The t-distribution is used in place of the standard normal distribution for small sample sizes ($n<30$).
Let $Z \sim N(0,1)$ and $W \sim \chi^2(n)$ be independent random variables. The t-distribution is given by
$T = \frac{Z}{\sqrt{W/n}}$
As the degrees of freedom $n$ gets larger, the t-distribution approximates the normal distribution.
#expand Week 3 Lesson 3 DS5003
## Notation
$T \sim t(n)$
with $n$ [[degrees of freedom]].
## Probability density function
The pdf of the t-distribution can be derived, however it is almost never used in closed form and instead we lookup values in [[R]].
## Expectation
$E(X) = 0$
## Variance
$V(X) = \frac{n}{n - 2}$
## R
The t-distribution is `t` in [[R]].
```R
# Quantile function (to get confidence interval)
n <- 20
df <- n - 1
qt(0.975, df)
```