Degrees of Freedom, t-distribution

When standard error is estimated from the data, the sampling distribution for the estimated mean follows the student \(t\) distribution with \(n-1\) degrees of freedom. (Every coefficient uses up a degree of freedom)

n <- length(sim_data)
estimate <- mean(sim_data)
se <- sd(sim_data)/sqrt(n)
estimate + qt(c(0.025, 0.975), n-1)*se
## [1] -2.885881 14.816747

Note that as the degrees of freedom approaches infinity, the t-distribution approaches the normal distribution. 30 is usually close enough to infinity.

estimate + qnorm(c(0.025, 0.975))*se
## [1] -2.777692 14.708558