Skip to main content

Section A.3 The \(t\) distribution calculations

The syntax in R for the \(t\) distribution is analogous to the standard normal distribution. We use the function pt() instead of pnorm() and qt() instead of qnorm(). In addition, the \(t\) distribution requires one additional parameter, the degrees of freedom. For the sample mean problems, the degrees of freedom needed are exactly \(n - 1\text{,}\) the size of the samples minus one.
We construct a 95% confidence interval for the population mean, using the sample standard deviation to estimate the standard error and the \(t\) distribution to determine how wide the confidence interval should be.
We start by obtaining the sample statistics (assuming a dataset almonds_sample_100 with a variable weight):
almonds_sample_100 |>
  summarize(
    mean_weight = mean(weight),
    sd_weight = sd(weight),
    sample_size = n()
  )
# A tibble: 1 × 4
  replicate mean_weight sd_weight sample_size
      <int>       <dbl>     <dbl>       <int>
1         1        3.68     0.362         100
To obtain the number of standard deviations on the \(t\) distribution to account for 95% of the values, we proceed as we did in the normal case: the area in the middle is 0.95, so the area on the tails is \(1 - 0.95 = 0.05\text{.}\) Since the \(t\) distribution is also symmetric, the area on each tail is \(0.025\text{.}\) The number of standard deviations around the center is given by the value \(q\) such that the area under the \(t\) curve to the left of \(q\) is exactly \(0.975\text{.}\) Using R we get:
qt(0.975, df = 100 - 1)
[1] 1.984217
So, in order to account for 95% of the observations around the mean, we need to take into account all the values within 1.98 standard deviations from the mean. Compare this number with the 1.96 obtained for the standard normal; the difference is due to the fact that the \(t\) curve has thicker tails than the standard normal. We can now construct the 95% confidence interval:
xbar <- 3.682
se_xbar <- 0.362 / sqrt(100)
lower_bound <- xbar - 1.98 * se_xbar
upper_bound <- xbar + 1.98 * se_xbar
c(lower_bound, upper_bound)
[1] 3.610324 3.753676
We are 95% confident that the population mean weight of almonds is a number between 3.61 and 3.75 grams.