Sampling distributions — exam-style exercises with the Virtual Campus, a laptop battery and two printers (and the degrees of freedom I put the wrong way round)

In the class mock of the EC2 I got a two-variances question and lost it entirely over a detail. It asked for a and b such that P(a≤S12/S22≤b)=0.90 P(a \le S_1^2/S_2^2 \le b) = 0.90 , with 13 data on top and 9 below. I was completely sure and wrote qf(0.05, 8, 12) and qf(0.95, 8, 12). Out came a very reasonable and very wrong interval: I had swapped the degrees of freedom. The first is the top sample’s, m−1=12 m – 1 = 12 , and the second the bottom one’s. I lost the whole question. That mistake, with its output, is fragment 3 of “What’s wrong here?”.

These are the exam-style exercises for sampling distributions: three chained exercises, each with its own context, mixing paper (proofs and calculations) and R, with marks for each part as in the EC2, plus a bonus. Before doing them it helps to have the topic’s proofs and R practice at hand.

How to use this article

  1. Do the exercises with the exam in mind. In ME1’s EC2 you have 4 hours for 50 marks, with RStudio and the data open. These three exercises add up to 40 marks plus a 2.5 bonus: give them about 3 hours.
  2. Paper for what is proved, R for what is computed. Calculations to 2 decimals, as the exam asks. Keep whatever you do in R in a script: at the end of the exam you have to upload the .R file with the code for each exercise.
  3. Before each quantile, decide the distribution and its degrees. Normal, t, chi-square or F? n n or n−1 n – 1 ? Which sample goes on top?
  4. Mark yourself with the criteria. Each solution comes with “How it is marked”, a split of the marks. It is a guide, mine: not the official marking scheme.
  5. Finish with the cheat sheet and “For your script”. The cheat sheet only has results (that is what you can bring, handwritten: two sheets, both sides, in the EC2) and “For your script” is the topic’s code ready for your .R file.

Exercise 1: the Virtual Campus first thing in the morning (10 marks)

The time a course page of the Virtual Campus takes to load at 8:00, in seconds, follows a normal with mean 2.4 and standard deviation 0.5. You load the page 16 times on different days (an SRS of size 16).

  1. (2 marks) Give the distribution of the sample mean Xˉ \bar X and compute P(Xˉ>2.6) P(\bar X > 2.6) .
  2. (3 marks) Find a value q such that P(∑i=116(Xi−2.40.5)2≤q)=0.95 P\left(\sum_{i=1}^{16} \left(\frac{X_i – 2.4}{0.5}\right)^2 \le q\right) = 0.95 . Justify the distribution you use.
  3. (3 marks) Find two values a and b, leaving the same probability in each tail, such that P(a≤S2≤b)=0.90 P(a \le S^2 \le b) = 0.90 .
  4. (2 marks) Compute P(S2>0.4) P(S^2 > 0.4) .

Exercise 2: the laptop battery in the exam (15 marks)

Your laptop’s manufacturer says the battery lasts 6 hours on average with brightness at 100 %. Before the EC2, ten classmates with the same model measure how long it lasts, first with brightness at 100 % and on another day with brightness at 50 %. Assume the durations are normal.

bright100 <- c(5.23, 5.72, 4.49, 4.61, 6.64, 4.95, 6.76, 6.20, 5.66, 4.90)   # hours
bright50  <- c(5.49, 6.15, 4.50, 5.07, 6.79, 5.50, 7.23, 7.06, 6.00, 5.22)   # the same 10 laptops
  1. (3 marks) With the 100 % data, compute in R the sample mean and standard deviation, the statistic tobs=n(xˉ−6)/s t_{obs} = \sqrt n (\bar x – 6)/s and P(T≤tobs) P(T \le t_{obs}) if the manufacturer is right. Do the data support the manufacturer’s claim?
  2. (3 marks) Prove that, if X1,…,Xn X_1, \dots, X_n is an SRS from an N(μ,σ) N(\mu, \sigma) , n(Xˉ−μ)/S∼t(n−1) \sqrt n (\bar X – \mu)/S \sim t(n-1) . Justify each piece and its independence.
  3. (3 marks) The two measurements of each laptop are not independent. Call Di D_i the difference (brightness 50 % minus brightness 100 %) and justify that n(Dˉ−μD)/SD∼t(n−1) \sqrt n (\bar D – \mu_D)/S_D \sim t(n-1) . Compute its value if μD=0 \mu_D = 0 and P(T≥tobs) P(T \ge t_{obs}) .
  4. (3 marks) Prove that if T∼t(k) T \sim t(k) , then T2∼F(1,k) T^2 \sim F(1, k) , and check in R, with the tobs t_{obs} from part 1, that P(T2>tobs2)=2P(T>∣tobs∣) P(T^2 > t_{obs}^2) = 2P(T > |t_{obs}|) .
  5. (3 marks) Simulate 10,000 samples of 10 laptops from an N(6,0.8) N(6, 0.8) , compute the statistic from part 1 in each and compare its 97.5 % quantile with qt(0.975, 9) and qnorm(0.975). Draw the histogram with the t(9) t(9) density on top.

Exercise 3: two printers in the library (15 marks)

The library has an old printer (A) and a new one (B). The time per page, in seconds, is normal for both. The two samples are independent: 13 jobs on A and 9 on B.

  1. (3 marks) The technician says A’s variance is double B’s: σA2=2σB2 \sigma_A^2 = 2\sigma_B^2 . Give the distribution of SA2/σA2SB2/σB2 \frac{S_A^2/\sigma_A^2}{S_B^2/\sigma_B^2} and find a and b, with the same probability in each tail, such that P(a≤SA2/SB2≤b)=0.90 P(a \le S_A^2/S_B^2 \le b) = 0.90 .
  2. (3 marks) Prove that if X∼F(m,n) X \sim F(m, n) , then 1/X∼F(n,m) 1/X \sim F(n, m) , and from there that qα(m,n)=1/q1−α(n,m) q_{\alpha}(m, n) = 1/q_{1-\alpha}(n, m) . Check in R that the a from part 1 can be computed without the left tail.

After a service, the technician says both printers now have the same standard deviation. These are the times measured afterwards:

A <- c(7.7, 10.1, 7.2, 8.7, 10.5, 7.9, 8.1, 7.9, 8.3, 8.8, 10.0, 7.7, 7.4)   # 13 jobs
B <- c(7.5, 6.5, 7.5, 7.0, 5.3, 8.0, 7.4, 8.7, 8.7)                         # 9 jobs
  1. (3 marks) With σA=σB=σ \sigma_A = \sigma_B = \sigma , prove that (XˉA−XˉB)−(μA−μB)Sp1/m+1/n∼t(m+n−2) \frac{(\bar X_A – \bar X_B) – (\mu_A – \mu_B)}{S_p\sqrt{1/m + 1/n}} \sim t(m + n – 2) , with Sp2 S_p^2 the pooled variance.
  2. (3 marks) With the data, compute Sp S_p and the statistic from part 3 if μA=μB \mu_A = \mu_B , and the probability P(∣T∣≥∣tobs∣) P(|T| \ge |t_{obs}|) . Do the two printers look equally fast?
  3. (3 marks) Is the data ratio sA2/sB2 s_A^2/s_B^2 compatible with σA=σB \sigma_A = \sigma_B ? Answer with the central 90 % interval of the relevant F and with pf.

Bonus (2.5 marks)

Let T=Z/Y/k∼t(k) T = Z/\sqrt{Y/k} \sim t(k) , with k>2 k > 2 . Using that Z and Y are independent, prove that Var⁡(T)=kk−2 \operatorname{Var}(T) = \dfrac{k}{k-2} . (Hint: compute E(1/Y) E(1/Y) for a χ2(k) \chi^2(k) with the gamma integral.)

Solutions

Exercise 1

Part 1. The population is normal, so the mean is exactly normal: Xˉ∼N(2.4, 0.5/16)=N(2.4, 0.125) \bar X \sim N(2.4,\ 0.5/\sqrt{16}) = N(2.4,\ 0.125) .

1 - pnorm(2.6, 2.4, 0.5 / sqrt(16))    # P(mean > 2.6)

Output:

[1] 0.05479929

5.48 % of the time the mean of 16 loads exceeds 2.6 seconds.

Part 2. Each (Xi−2.4)/0.5∼N(0,1) (X_i – 2.4)/0.5 \sim N(0, 1) , its square is a χ2(1) \chi^2(1) and the 16 are independent: the sum is a χ2(16) \chi^2(16) (μ and σ known: 16 degrees, not 15). q is its 95 % quantile:

qchisq(0.95, 16)

Output:

[1] 26.29623

q=26.30 q = 26.30 .

Why 16 degrees and not 15. Before looking up the quantile, look at what is inside the brackets: Xi−2.4 X_i – 2.4 , with the population mean, not with Xˉ \bar X . Since μ and σ are given in the statement, nothing is estimated and no degree is lost: 16 squares of standard normals, 16 degrees. The obvious path, “it looks like S2 S^2 , so n−1 n – 1 “, gives qchisq(0.95, 15) = 25.00.

Check you’ve got it: what if the sum used the sample mean instead of 2.4?

Then it really is 15 degrees: the sum is 15S2/0.25 15S^2/0.25 , the χ2(15) \chi^2(15) of part 3. When you use Xˉ \bar X , the 16 deviations add up to zero and one of them is fixed by the others. You would get q=25.00 q = 25.00 .

Part 3. With n−1=15 n – 1 = 15 and σ2=0.25 \sigma^2 = 0.25 , U=15S2/0.25∼χ2(15) U = 15S^2/0.25 \sim \chi^2(15) :

P(a≤S2≤b)=P(15a0.25≤U≤15b0.25)=0.90 P(a \le S^2 \le b) = P\left(\frac{15a}{0.25} \le U \le \frac{15b}{0.25}\right) = 0.90

With 5 % in each tail, 15a/0.25=q0.05 15a/0.25 = q_{0.05} and 15b/0.25=q0.95 15b/0.25 = q_{0.95} of the χ2(15) \chi^2(15) . Solve by going back:

a <- 0.25 * qchisq(0.05, 15) / 15
b <- 0.25 * qchisq(0.95, 15) / 15
round(c(a = a, b = b), 2)

Output:

   a    b 
0.12 0.42 

P(0.12≤S2≤0.42)=0.90 P(0.12 \le S^2 \le 0.42) = 0.90 . Notice the interval is not symmetric about σ2=0.25 \sigma^2 = 0.25 : the chi-square is skewed.

How to set up part 3. All you know about S2 S^2 is that 15S2/0.25 15S^2/0.25 is a χ2(15) \chi^2(15) . So the path is to translate the event about S2 S^2 into one about U (multiply all three sides by 15/0.25 15/0.25 , which is positive, so the inequalities don’t flip), find the quantiles there and undo the change. An interval “0.25 plus or minus something” doesn’t work: the chi-square is not symmetric.

Using the quantiles 0.025 and 0.975 out of habit. With 90 % in the middle there is 5 % in each tail: 0.05 and 0.95. With the others you get (0.10, 0.46) (0.10,\ 0.46) , the 95 % interval.

Part 4.

P(S2>0.4)=P(U>15⋅0.40.25)=P(U>24) P(S^2 > 0.4) = P\left(U > \frac{15 \cdot 0.4}{0.25}\right) = P(U > 24)
1 - pchisq(15 * 0.4 / 0.25, 15)

Output:

[1] 0.06509349

6.5 %, consistent with part 3: 0.4 is a little below b = 0.42, which leaves 5 % above.

How it is marked. Part 1: the normal with σ/n \sigma/\sqrt n (1), the probability (1). Part 2: justifying χ2(16) \chi^2(16) (2), the quantile (1); with 15 degrees, −1. Part 3: moving to the χ2(15) \chi^2(15) (1), the two quantiles (1), solving for a and b (1). Part 4: the change and the result (2).

Exercise 2

Part 1.

bright100 <- c(5.23, 5.72, 4.49, 4.61, 6.64, 4.95, 6.76, 6.20, 5.66, 4.90)
n <- length(bright100)
t_obs <- sqrt(n) * (mean(bright100) - 6) / sd(bright100)
round(c(mean = mean(bright100), s = sd(bright100), t_obs = t_obs), 2)
pt(t_obs, n - 1)              # P(T <= t_obs) if mu = 6

Output:

 mean     s t_obs 
 5.52  0.82 -1.88 
[1] 0.04676651

The mean is 5.52 hours and the sample standard deviation 0.82. Since σ is estimated by s, the statistic is a t(9) t(9) : P(T≤−1.88)=0.047 P(T \le -1.88) = 0.047 . If the manufacturer were right, a mean this low would come up less than 5 % of the time: the data do not really support the 6 hours.

Part 2. The three pieces (proof 7 of the topic):

  • Z=n(Xˉ−μ)/σ∼N(0,1) Z = \sqrt n (\bar X – \mu)/\sigma \sim N(0, 1) , because Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) (mean of independent normals).
  • Y=(n−1)S2/σ2∼χ2(n−1) Y = (n-1)S^2/\sigma^2 \sim \chi^2(n-1) (decomposition of the sum of squares and the mgf).
  • Z depends only on Xˉ \bar X and Y only on S2 S^2 ; in a normal sample Xˉ \bar X and S2 S^2 are independent, so Z and Y are too.

By the definition of the t:

ZY/(n−1)=n(Xˉ−μ)/σS2/σ2=n Xˉ−μS∼t(n−1) \frac{Z}{\sqrt{Y/(n-1)}} = \frac{\sqrt n (\bar X – \mu)/\sigma}{\sqrt{S^2/\sigma^2}} = \sqrt n\,\frac{\bar X – \mu}{S} \sim t(n-1)

Part 3. Each Di=X50,i−X100,i D_i = X_{50,i} – X_{100,i} is a difference of two normals from the same laptop, so it is normal; the Ds of different laptops are independent. So D1,…,Dn D_1, \dots, D_n is an SRS from an N(μD,σD) N(\mu_D, \sigma_D) and, by part 2 applied to the Ds, n(Dˉ−μD)/SD∼t(n−1) \sqrt n(\bar D – \mu_D)/S_D \sim t(n-1) .

bright50 <- c(5.49, 6.15, 4.50, 5.07, 6.79, 5.50, 7.23, 7.06, 6.00, 5.22)
d <- bright50 - bright100
t_d <- sqrt(n) * mean(d) / sd(d)          # mu_D = 0
round(c(mean_d = mean(d), s_d = sd(d), t_d = t_d), 3)
1 - pt(t_d, n - 1)                         # P(T >= t_d)

Output:

mean_d    s_d    t_d 
 0.385  0.232  5.242 
[1] 0.0002666158

Turning brightness down gives on average 0.385 hours more (about 23 minutes), with a standard deviation of the differences of only 0.232. t=5.24 t = 5.24 and P(T≥5.24)=0.0003 P(T \ge 5.24) = 0.0003 : if brightness had no effect, this would almost never happen. With paired data, the variation between laptops cancels out when you subtract, and that is why the difference shows so clearly.

Why subtract instead of comparing two samples. The obvious path is the two-sample t for independent samples. But these are the same ten laptops: one with a worn battery lasts little at both brightness levels. That variation between laptops (standard deviations of 0.82 and 0.91) would end up in the denominator and hide the effect of brightness. Subtracting within each laptop removes it, and only the variation of the differences is left, 0.23.

Check you’ve got it: what would you get treating the two columns as independent samples?

With the two-sample t and 18 degrees, t=1.00 t = 1.00 and P(T≥1.00)=0.17 P(T \ge 1.00) = 0.17 : you would see nothing. And it wouldn’t even be valid, because that t needs independent samples and these are not.

Part 4. T=Z/Y/k T = Z/\sqrt{Y/k} , so T2=Z2/1Y/k T^2 = \frac{Z^2/1}{Y/k} . Z2∼χ2(1) Z^2 \sim \chi^2(1) (square of a standard normal) and it is independent of Y: it is a ratio of chi-squares over their degrees, T2∼F(1,k) T^2 \sim F(1, k) . And since T2>c2  ⟺  ∣T∣>c T^2 > c^2 \iff |T| > c , and the t is symmetric:

round(c(with_F = 1 - pf(t_obs^2, 1, n - 1), with_t = 2 * (1 - pt(abs(t_obs), n - 1))), 4)

Output:

with_F with_t 
0.0935 0.0935 

Both give 0.0935: the F with 1 degree on top is the t with its two tails together.

Part 5.

set.seed(2026)
t_sim <- replicate(10000, { x <- rnorm(10, 6, 0.8); sqrt(10) * (mean(x) - 6) / sd(x) })
round(c(q975 = unname(quantile(t_sim, 0.975)), t9 = qt(0.975, 9), normal = qnorm(0.975)), 3)
hist(t_sim, freq = FALSE, breaks = 50, main = "", xlab = "t")
curve(dt(x, 9), add = TRUE, lwd = 2, col = "red")

Output:

  q975     t9 normal 
 2.300  2.262  1.960 
The statistic with S from 10 laptopsDensity-scale histogram of 10,000 values of the statistic root 10 times the mean minus 6 over S, simulated with normal laptops of mean 6 and standard deviation 0.8, between −5 and 5. On top, the t with 9 degrees in coral, which fits, and the standard normal in dashed grey, higher in the center and with less tail. Lines at plus and minus 2.262, the t quantiles that leave 2.5 % in each tail.0.00.10.20.30.4−5−4−3−2−1012345tdensity±2.262 = qt(0.975, 9)more tail than the normal10,000 statisticst(9)N(0, 1)
What hist and curve of part 5 draw: the histogram goes with t(9), not with the normal.

The 97.5 % quantile of the 10,000 simulated statistics sits next to the t(9) t(9) one and far from the normal’s 1.96. In the picture, the histogram follows t(9) in the tails too: there are more values beyond ±3 than a normal would allow.

Why sd(x) inside replicate. The whole part depends on one line: the statistic is computed with the standard deviation of each simulated sample, not with the population’s 0.8. It is that s, changing from sample to sample, that fattens the tails. If you put 0.8, each value is an exact standard normal: with the same seed, the 97.5 % quantile comes out at 2.01, right next to the normal’s 1.96 and far from the 2.26 of t(9) t(9) .

How it is marked. Part 1: mean and s (1), the statistic with s (1), the probability with pt and 9 degrees and the conclusion (1). Part 2: the normal (1), the chi-square (1), independence and the ratio (1). Part 3: justifying that the Ds are a normal SRS (1.5), the calculation (1.5). Part 4: the proof (2), the check (1). Part 5: simulation with the sample inside (1), quantiles (1), histogram with freq = FALSE and the curve (1).

Exercise 3

Part 1. By proof 8, SA2/σA2SB2/σB2∼F(12,8) \frac{S_A^2/\sigma_A^2}{S_B^2/\sigma_B^2} \sim F(12, 8) . With σA2=2σB2 \sigma_A^2 = 2\sigma_B^2 , that is SA22SB2=V∼F(12,8) \frac{S_A^2}{2S_B^2} = V \sim F(12, 8) , so

P(a≤SA2/SB2≤b)=P(a2≤V≤b2)=0.90 P(a \le S_A^2/S_B^2 \le b) = P\left(\frac a2 \le V \le \frac b2\right) = 0.90

with a/2=q0.05 a/2 = q_{0.05} and b/2=q0.95 b/2 = q_{0.95} of the F(12,8) F(12, 8) :

a <- 2 * qf(0.05, 12, 8); b <- 2 * qf(0.95, 12, 8)
round(c(a = a, b = b), 3)

Output:

    a     b 
0.702 6.568 

P(0.702≤SA2/SB2≤6.568)=0.90 P(0.702 \le S_A^2/S_B^2 \le 6.568) = 0.90 .

How to set up part 1. The statement doesn’t give you any variance, only the relation between them. That’s fine: in the ratio from proof 8 the σs only appear as σA2/σB2 \sigma_A^2/\sigma_B^2 , so knowing it equals 2 is enough. What you can’t do is look up a and b directly in the F(12,8) F(12, 8) , as if the variances were equal: you would get (0.351, 3.284) (0.351,\ 3.284) , which are exactly the quantiles of part 5, where the technician does say they are equal. The factor 2 is the only thing that tells the two parts apart.

Part 2. If X=U/mV/n X = \frac{U/m}{V/n} , with U∼χ2(m) U \sim \chi^2(m) and V∼χ2(n) V \sim \chi^2(n) independent, then 1/X=V/nU/m∼F(n,m) 1/X = \frac{V/n}{U/m} \sim F(n, m) . For the quantiles:

α=P(X≤qα(m,n))=P(1X≥1qα(m,n))  ⇒  1qα(m,n)=q1−α(n,m) \alpha = P(X \le q_\alpha(m,n)) = P\left(\frac1X \ge \frac{1}{q_\alpha(m,n)}\right) \;\Rightarrow\; \frac{1}{q_\alpha(m,n)} = q_{1-\alpha}(n, m)
round(c(a_direct = 2 * qf(0.05, 12, 8), a_no_left_tail = 2 / qf(0.95, 8, 12)), 3)

Output:

      a_direct a_no_left_tail 
         0.702          0.702 

Both give 0.702: qf(0.05, 12, 8) is the same as 1 / qf(0.95, 8, 12) (degrees swapped and tail swapped).

Part 3. It is proof 9: XˉA−XˉB∼N(μA−μB,σ1/m+1/n) \bar X_A – \bar X_B \sim N\left(\mu_A – \mu_B, \sigma\sqrt{1/m + 1/n}\right) , which standardised is an N(0, 1); (m−1)SA2+(n−1)SB2σ2=(m+n−2)Sp2σ2∼χ2(12+8)=χ2(20) \frac{(m-1)S_A^2 + (n-1)S_B^2}{\sigma^2} = \frac{(m+n-2)S_p^2}{\sigma^2} \sim \chi^2(12 + 8) = \chi^2(20) by the sum of independent chi-squares; the two are independent (one depends on the means and the other on the variances). The ratio of the normal over the root of the chi-square over 20 gives the expression in the question, in which σ cancels: t(m+n−2)=t(20) t(m + n – 2) = t(20) .

Part 4.

A <- c(7.7, 10.1, 7.2, 8.7, 10.5, 7.9, 8.1, 7.9, 8.3, 8.8, 10.0, 7.7, 7.4)
B <- c(7.5, 6.5, 7.5, 7.0, 5.3, 8.0, 7.4, 8.7, 8.7)
m <- length(A); n <- length(B)
sp <- sqrt(((m - 1) * var(A) + (n - 1) * var(B)) / (m + n - 2))
t_obs <- (mean(A) - mean(B)) / (sp * sqrt(1 / m + 1 / n))
round(c(mean_A = mean(A), mean_B = mean(B), sp = sp, t_obs = t_obs), 3)
2 * (1 - pt(abs(t_obs), m + n - 2))       # P(|T| >= |t_obs|)

Output:

mean_A mean_B     sp  t_obs 
 8.485  7.400  1.076  2.324 
[1] 0.03080616

The old one takes 8.48 s per page on average and the new one 7.40. With sp=1.08 s_p = 1.08 , t=2.32 t = 2.32 and P(∣T∣≥2.32)=0.031 P(|T| \ge 2.32) = 0.031 : if they were equally fast, a difference like this would come up 3 % of the time. The new one does look faster.

Why two tails and 20 degrees. The question is whether they are equally fast, without saying which one you suspect is slower: so you add both tails (with one you would get 0.015, half). There are 12+8=20 12 + 8 = 20 degrees because each sample loses one when estimating its mean. And mind the order: the pooled t is only valid if the two σs are equal, which is exactly what part 5 checks.

Part 5. With σA=σB \sigma_A = \sigma_B , SA2/SB2∼F(12,8) S_A^2/S_B^2 \sim F(12, 8) :

f_obs <- var(A) / var(B)
round(c(f_obs = f_obs, q05 = qf(0.05, 12, 8), q95 = qf(0.95, 12, 8), p = pf(f_obs, 12, 8)), 3)

Output:

f_obs   q05   q95     p 
1.024 0.351 3.284 0.497 

The ratio is 1.024 and the central 90 % of the F(12,8) F(12, 8) goes from 0.351 to 3.284: it is inside, and well centred (it leaves 49.7 % below). The data are compatible with equal σs, which is what part 4 needed.

Check you’ve got it: does the conclusion change if you put B in the numerator?

No. The ratio becomes sB2/sA2=0.98 s_B^2/s_A^2 = 0.98 and the F to use is F(8,12) F(8, 12) , with the degrees swapped too. Its central 90 % goes from 0.30 to 2.85, so 0.98 is still inside, and pf gives 0.503. What you can’t do is change only one of the two things: the ratio or the degrees.

How it is marked. Part 1: the F with (12, 8) and the factor 2 (1.5), a and b (1.5). Part 2: the reciprocal (1.5), the quantile rule and the check (1.5). Part 3: normal (1), chi-square with 20 degrees (1), independence and ratio (1). Part 4: sp s_p (1), the statistic (1), the two-tailed probability with 20 degrees (1). Part 5: the quantiles (1.5), the conclusion (1.5).

Bonus

By the independence of Z and Y, E(T2)=E(Z2⋅kY)=E(Z2) k E(1/Y)=k E(1/Y) E(T^2) = E\left(Z^2 \cdot \frac{k}{Y}\right) = E(Z^2)\, k\, E(1/Y) = k\,E(1/Y) , because E(Z2)=1 E(Z^2) = 1 . For Y∼χ2(k)=gamma(k/2,1/2) Y \sim \chi^2(k) = \text{gamma}(k/2, 1/2) :

E(1Y)=∫0∞1y(1/2)k/2Γ(k/2)yk/2−1e−y/2 dy=(1/2)k/2Γ(k/2)⋅Γ(k/2−1)(1/2)k/2−1=12⋅Γ(k/2−1)Γ(k/2) E\left(\frac1Y\right) = \int_0^\infty \frac1y \frac{(1/2)^{k/2}}{\Gamma(k/2)} y^{k/2-1} e^{-y/2}\,dy = \frac{(1/2)^{k/2}}{\Gamma(k/2)} \cdot \frac{\Gamma(k/2 – 1)}{(1/2)^{k/2-1}} = \frac12\cdot\frac{\Gamma(k/2-1)}{\Gamma(k/2)}

The integral is that of a gamma with shape k/2−1 k/2 – 1 (which is why k>2 k > 2 is needed). Since Γ(k/2)=(k/2−1)Γ(k/2−1) \Gamma(k/2) = (k/2 – 1)\Gamma(k/2 – 1) :

E(1Y)=12(k/2−1)=1k−2,Var⁡(T)=E(T2)−02=kk−2 E\left(\frac1Y\right) = \frac{1}{2(k/2 – 1)} = \frac{1}{k-2}, \qquad \operatorname{Var}(T) = E(T^2) – 0^2 = \frac{k}{k-2}
k <- 9
c(E_1_over_Y = integrate(function(y) dchisq(y, k) / y, 0, Inf)$value, formula = 1 / (k - 2))
c(var_t = integrate(function(x) x^2 * dt(x, k), -Inf, Inf)$value, formula = k / (k - 2))

Output:

E_1_over_Y    formula 
 0.1428571  0.1428571 
   var_t  formula 
1.285714 1.285714 

With 9 degrees, E(1/Y)=1/7 E(1/Y) = 1/7 and the variance of t(9) t(9) is 9/7=1.29 9/7 = 1.29 , more than the normal’s: those are the heavy tails.

Why go through E(1/Y) E(1/Y) . The obvious path, integrating t2 t^2 times the density of the t, is a long calculation. The independence of Z and Y avoids it: the expectation of the product splits, you already know E(Z2)=1 E(Z^2) = 1 , and all that’s left is the integral of 1/y 1/y times a gamma density. That integral only converges if k>2 k > 2 : with 1 or 2 degrees, the t has no finite variance.

What’s wrong here?

Three fragments with one mistake each. Before reading the explanation, try to find it.

Fragment 1. With the 10 laptops from exercise 2 (xˉ=5.516 \bar x = 5.516 , s=0.816 s = 0.816 ), the value that leaves 2.5 % in each tail of the statistic:

qnorm(0.975)

Output:

[1] 1.959964

The standard deviation comes from the sample, so the statistic is a t(9) t(9) , not a normal. The right value is qt(0.975, 9) = 2.262. With 1.96, everything you build on top (a bound, an interval) will be too narrow.

Ask where σ comes from. If it is a number in the question (“standard deviation 0.5”), normal. If you compute it with sd(), t with n−1 n – 1 .

Fragment 2. The value b such that P(S2>b)=0.05 P(S^2 > b) = 0.05 for 10 laptops, if σ=0.8 \sigma = 0.8 :

b <- 0.8^2 * qchisq(0.95, 10) / 9
round(b, 3)

Output:

[1] 1.302

With 10 data, 9S2/σ2∼χ2(9) 9S^2/\sigma^2 \sim \chi^2(9) : the quantile is the χ2(9) \chi^2(9) ‘s, not the χ2(10) \chi^2(10) ‘s. The odd thing is that the 9 in the denominator is right, so the mistake doesn’t jump out. The right one: 0.8^2 * qchisq(0.95, 9) / 9 = 1.203, not 1.302.

The 95 % quantile with 9 and with 10 degreesChi-square densities with 9 degrees in green and 10 in dashed red, between 0 and 30. The 5 % tail of the 9-degree one is shaded right of 16.92, the right quantile; the red line at 18.31 is the 95 % quantile of the 10-degree one, the wrong one, further right.0.000.050.10051015202530xf(x)right: 16.92wrong: 18.315 % of χ²(9)χ²(9): 10 data − 1χ²(10)
With one degree too many, the quantile moves right and b comes out too large.

In the picture, the two chi-squares: the 95 % quantile of χ2(10) \chi^2(10) sits to the right of the χ2(9) \chi^2(9) ‘s, and that is why b comes out too large.

Fragment 3. The one from my mock: a and b such that P(a≤S12/S22≤b)=0.90 P(a \le S_1^2/S_2^2 \le b) = 0.90 with 13 data on top, 9 below and equal σs:

round(c(a = qf(0.05, 8, 12), b = qf(0.95, 8, 12)), 3)

Output:

    a     b 
0.305 2.849 

The degrees go in the order of the ratio: on top 13−1=12 13 – 1 = 12 , below 9−1=8 9 – 1 = 8 . The right ones are qf(0.05, 12, 8) = 0.351 and qf(0.95, 12, 8) = 3.284. With the degrees swapped, b comes out 2.85 instead of 3.28: the interval falls short at the top and a ratio of 3 would be taken as unusual when it isn’t.

Swapping the F’s degrees “because it doesn’t matter”. It only doesn’t matter if you also invert the ratio and switch tails: q0.95(8,12)=1/q0.05(12,8) q_{0.95}(8, 12) = 1/q_{0.05}(12, 8) .

Practice quiz

Before moving on to the next topic, check you have got it. This quiz is here to consolidate what this article explains: the ME1 exam is not a multiple-choice test (you solve problems by hand and with R), so no mark here counts. There are 10 questions on sampling distributions: key ideas, typical mistakes and many «what does this R code print?», with the outputs from really running it. In the short answers, a decimal point or a decimal comma both work. Answer without running anything, press Check and read the explanation for each option; you can repeat it as many times as you like.

Question 1Single choice

With 10 laptops, the mean and the standard deviation come from the sample (sd()). Which quantile leaves 2.5 % in each tail of the mean’s statistic?

  1. qt(0.975, 9), which is 2.262
  2. qnorm(0.975), which is 1.96
  3. qt(0.975, 10)
  4. qchisq(0.975, 9)
Solution

Answer: qt(0.975, 9), which is 2.262

Ask yourself where σ comes from: if it is a number in the problem, normal; if you compute it with sd(), t with n − 1.

Question 2Short answer

10 laptops, normal population with σ = 0.8. What value b satisfies P(S² > b) = 0.05? (3 decimals.)

round(0.8^2 * qchisq(0.95, 9) / 9, 3)
Solution

Answer: 1.203

9S²/σ² ~ χ²(9), so b = σ² · q_0.95(χ²(9)) / 9 = 0.64 · 16.92 / 9 = 1.203. With χ²(10) you would get 1.302: snippet 2’s degrees-of-freedom mistake.

Question 3Single choice

13 values in sample 1 and 9 in sample 2, equal σ. What distribution does S₁²/S₂² have?

  1. F(12, 8)
  2. F(8, 12)
  3. F(13, 9)
  4. t(20)
Solution

Answer: F(12, 8)

Swapping the degrees «because it doesn’t matter» only works if you also invert the ratio and change tail: q_0.95(8, 12) = 1/q_0.05(12, 8).

Question 4Short answer

What does it print? (3 decimals.)

round(qf(0.95, 12, 8), 3)
Solution

Answer: 3.284

It is the mock exam’s b with the degrees the right way round: F(12, 8) leaves 5 % above 3.284.

Question 5Short answer

Population with σ = 2 and a sample of n = 16. What is the standard deviation of the sample mean?

2 / sqrt(16)
Solution

Answer: 0.5

Var(mean) = σ²/n, so its standard deviation is σ/√n = 2/4 = 0.5.

Question 6Match

Normal population. Match each statistic with its distribution:

Sample mean, σ known
(n − 1)S²/σ²
√n(mean − μ)/S
(S₁²/σ₁²)/(S₂²/σ₂²)

Definitions:

  • N(μ, σ/√n)
  • F(m − 1, n − 1)
  • t(n − 1)
  • N(0, σ²)
  • χ²(n − 1)
Solution
  • Sample mean, σ known → N(μ, σ/√n)
  • (n − 1)S²/σ² → χ²(n − 1)
  • √n(mean − μ)/S → t(n − 1)
  • (S₁²/σ₁²)/(S₂²/σ₂²) → F(m − 1, n − 1)

It is the cheat sheet’s «The essentials in 30 seconds». Also, in a normal population the mean and S² are independent.

Question 7True or false

True or false?

  1. E(S²) = σ² (that is why S² divides by n − 1).
  2. A simple random sample is n independent, identically distributed variables.
  3. With more data, the sample mean has more variance.
  4. Student’s t looks more and more like N(0, 1) as the degrees of freedom grow.
Solution
  • T — E(S²) = σ² (that is why S² divides by n − 1).
  • T — A simple random sample is n independent, identically distributed variables.
  • F — With more data, the sample mean has more variance.
  • T — Student’s t looks more and more like N(0, 1) as the degrees of freedom grow.

Var(mean) = σ²/n goes down as n grows. And the t has heavier tails than the normal, which thin out with more degrees.

Question 8Single choice

You have computed a χ²(9) quantile for the variance. What is left to give b for S²?

  1. Solving back to the original statistic: b = σ² · quantile / (n − 1)
  2. Nothing: the quantile is already b
  3. Taking its square root
  4. Dividing by n
Solution

Answer: Solving back to the original statistic: b = σ² · quantile / (n − 1)

P(9S²/0.64 > q) = 0.05 ⇔ P(S² > 0.64 · q / 9) = 0.05.

Question 9Short answer

What does it print? (3 decimals.)

round(qt(0.975, 9), 3)
Solution

Answer: 2.262

With 9 degrees of freedom, the t leaves 2.5 % above 2.262: more than 1.96, because estimating σ adds uncertainty.

Question 10Single choice

For the mean, when do you use the normal and when the t?

  1. Normal if σ is given in the problem; t with n − 1 if σ is estimated from the data
  2. Normal with large n and t with small n, always
  3. t if the population is normal; normal otherwise
  4. Always the t, which is safer
Solution

Answer: Normal if σ is given in the problem; t with n − 1 if σ is estimated from the data

The first question of «Before you hand in»: is σ from the problem or from the data?

Try it in the R playground

Open the R playground on the site (or RStudio) and paste this script. It checks three answers from the exercises by simulation:

set.seed(2026)
m <- 10000
# Exercise 1, part 3: P(0.12 <= S^2 <= 0.42) with 16 loads N(2.4, 0.5)
s2 <- replicate(m, var(rnorm(16, 2.4, 0.5)))
mean(s2 >= 0.25 * qchisq(0.05, 15) / 15 & s2 <= 0.25 * qchisq(0.95, 15) / 15)   # close to 0.90
# Exercise 3, part 1: S_A^2 / S_B^2 with sigma_A^2 = 2 sigma_B^2
r <- replicate(m, var(rnorm(13, 0, sqrt(2))) / var(rnorm(9, 0, 1)))
mean(r >= 2 * qf(0.05, 12, 8) & r <= 2 * qf(0.95, 12, 8))                     # close to 0.90
# Fragment 2: the right b and the wrong one
v <- replicate(m, var(rnorm(10, 6, 0.8)))
c(right = mean(v > 0.8^2 * qchisq(0.95, 9) / 9), wrong = mean(v > 0.8^2 * qchisq(0.95, 10) / 9))

Things to look at:

  1. That both interval proportions come out close to 0.90.
  2. That the right b leaves about 5 % of the variances above it and the wrong one quite a bit less.
  3. Replace sqrt(2) with 1 in exercise 3: with equal σs, the interval computed for double the variance no longer hits 90 %.

Cheat sheet: sampling distributions

The essentials in 30 seconds. SRS = iid. E(Xˉ)=μ E(\bar X) = \mu , Var⁡(Xˉ)=σ2/n \operatorname{Var}(\bar X) = \sigma^2/n , E(S2)=σ2 E(S^2) = \sigma^2 . Normal population: Xˉ∼N(μ,σ/n) \bar X \sim N(\mu, \sigma/\sqrt n) ; (n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1) , independent of Xˉ \bar X ; n(Xˉ−μ)/S∼t(n−1) \sqrt n(\bar X – \mu)/S \sim t(n-1) ; S12/σ12S22/σ22∼F(m−1,n−1) \frac{S_1^2/\sigma_1^2}{S_2^2/\sigma_2^2} \sim F(m-1, n-1) .

I want…ResultIn R
P(Xˉ≤x) P(\bar X \le x) , σ knownN(μ,σ/n) N(\mu, \sigma/\sqrt n) pnorm(x, mu, sigma / sqrt(n))
Quantile of ∑((Xi−μ)/σ)2 \sum ((X_i – \mu)/\sigma)^2 χ2(n) \chi^2(n) qchisq(p, n)
P(S2>c) P(S^2 > c) (n−1)S2/σ2∼χ2(n−1) (n-1)S^2/\sigma^2 \sim \chi^2(n-1) 1 - pchisq((n - 1) * c / sigma^2, n - 1)
b with P(S2>b)=α P(S^2 > b) = \alpha solvesigma^2 * qchisq(1 - alpha, n - 1) / (n - 1)
a, b with P(a≤S2≤b)=1−α P(a \le S^2 \le b) = 1 – \alpha equal tailssigma^2 * qchisq(c(alpha/2, 1 - alpha/2), n - 1) / (n - 1)
P(T≤t) P(T \le t) with St(n−1) t(n-1) pt(t, n - 1)
Two-tailed t valueq1−α/2 q_{1-\alpha/2} qt(1 - alpha/2, n - 1)
Ratio of variancesF(m−1,n−1) F(m-1, n-1) qf(p, m - 1, n - 1), pf(x, m - 1, n - 1)
a, b for S12/S22 S_1^2/S_2^2 with σ12=rσ22 \sigma_1^2 = r\sigma_2^2 S12/(rS22)∼F S_1^2/(rS_2^2) \sim F r * qf(c(alpha/2, 1 - alpha/2), m - 1, n - 1)
Two means, common σt(m+n−2) t(m+n-2) with Sp S_p sp <- sqrt(((m-1)*var(x) + (n-1)*var(y)) / (m+n-2))
Pairedt(n−1) t(n-1) with the differencesd <- x - y; sqrt(n) * mean(d) / sd(d)

Properties of the families:

DistributionMeanVarianceOther
χ2(k) \chi^2(k) k2kgamma(k/2, 1/2); mgf (1−2t)−k/2 (1-2t)^{-k/2} ; they add up
t(k) t(k) 0 (k > 1)k/(k−2) k/(k-2) (k > 2)symmetric; t(1) Cauchy; t(k)2∼F(1,k) t(k)^2 \sim F(1, k)
F(m,n) F(m, n) n/(n−2) n/(n-2) (n > 2)—1/F∼F(n,m) 1/F \sim F(n, m) ; qα(m,n)=1/q1−α(n,m) q_\alpha(m,n) = 1/q_{1-\alpha}(n,m)

Symptom / likely cause:

SymptomLikely cause
The b for S2 S^2 comes out too largeqchisq(…, n) instead of n - 1
The b for S2 S^2 comes out smaller than σ² for a right tailYou didn’t go back multiplying by σ2/(n−1) \sigma^2/(n-1)
An F interval falls short at the topDegrees of freedom swapped
“Too small” probabilities for the mean with few datapnorm with s instead of pt
The curve doesn’t fit the simulated histogramDegrees of freedom; or freq = FALSE is missing

Before you hand in, ask yourself:

  1. Does σ come from the question (normal, chi-square with n) or from the data (t, chi-square with n − 1)?
  2. How many degrees of freedom does each distribution have, and why?
  3. In an F, which sample goes on top?
  4. Have I solved by going back to the original statistic (S2 S^2 , not the chi-square)?
ME1 exam coming up?The script for every topic, the printable cheat sheet and the pack for each exam, for free.See the pack

For your script

The topic’s code, commented, for your exam .R file. Your own functions and the code for the solved exercises, without the questions:

# ===== Topic 8: sampling distributions (chi^2, t, F) =====
# --- Sample mean (sigma known) ---
p_mean <- function(x, mu, sigma, n, tail = "left")          # P(mean <= x) or P(mean > x)
  if (tail == "left") pnorm(x, mu, sigma / sqrt(n)) else 1 - pnorm(x, mu, sigma / sqrt(n))
# --- Sample variance: (n - 1) S^2 / sigma^2 ~ chi^2(n - 1) ---
p_s2_above <- function(c, sigma, n) 1 - pchisq((n - 1) * c / sigma^2, n - 1)   # P(S^2 > c)
b_s2 <- function(alpha, sigma, n) sigma^2 * qchisq(1 - alpha, n - 1) / (n - 1)  # P(S^2 > b) = alpha
ab_s2 <- function(conf, sigma, n) {                          # P(a <= S^2 <= b) = conf, equal tails
  al <- 1 - conf
  sigma^2 * qchisq(c(a = al / 2, b = 1 - al / 2), n - 1) / (n - 1)
}
# --- Sum of squares with mu and sigma known: chi^2(n) ---
q_sum_squares <- function(p, n) qchisq(p, n)
# --- One-sample t (sigma estimated) ---
t_one <- function(x, mu0) sqrt(length(x)) * (mean(x) - mu0) / sd(x)   # ~ t(n - 1)
t_paired <- function(x, y, mu_d = 0) t_one(x - y, mu_d)               # the differences
# --- Two samples: F and pooled-variance t ---
ab_ratio <- function(conf, m, n, r = 1) {                    # P(a <= S1^2/S2^2 <= b), sigma1^2 = r sigma2^2
  al <- 1 - conf
  r * qf(c(a = al / 2, b = 1 - al / 2), m - 1, n - 1)       # m = size of the TOP sample
}
sp <- function(x, y) sqrt(((length(x) - 1) * var(x) + (length(y) - 1) * var(y)) / (length(x) + length(y) - 2))
t_two <- function(x, y, dif0 = 0)                            # ~ t(m + n - 2) if equal sigmas
  ((mean(x) - mean(y)) - dif0) / (sp(x, y) * sqrt(1 / length(x) + 1 / length(y)))
p_two_tailed_t <- function(t, df) 2 * (1 - pt(abs(t), df)) # P(|T| >= |t|)
# --- Check a distribution by simulation (the sample is made INSIDE) ---
check_dist <- function(statistic, m = 10000, density, ...) {
  v <- replicate(m, statistic())
  hist(v, freq = FALSE, breaks = 50, main = "")
  curve(density(x, ...), add = TRUE, col = "red", lwd = 2)
  invisible(v)
}
# example: check_dist(function() 14 * var(rnorm(15, 40, 6)) / 36, density = dchisq, df = 14)
# --- Solved exercises ---
# Virtual Campus: N(2.4, 0.5), 16 loads
p_mean(2.6, 2.4, 0.5, 16, "right")                # 0.05
q_sum_squares(0.95, 16)                           # 26.30
round(ab_s2(0.90, 0.5, 16), 2); p_s2_above(0.4, 0.5, 16)   # 0.12, 0.42 and 0.07
# Battery: one-sample t and paired
bright100 <- c(5.23, 5.72, 4.49, 4.61, 6.64, 4.95, 6.76, 6.20, 5.66, 4.90)
bright50  <- c(5.49, 6.15, 4.50, 5.07, 6.79, 5.50, 7.23, 7.06, 6.00, 5.22)
pt(t_one(bright100, 6), 9)                        # 0.047
1 - pt(t_paired(bright50, bright100), 9)          # 0.0003
# Printers: F with sigma_A^2 = 2 sigma_B^2 and two-sample t
round(ab_ratio(0.90, 13, 9, r = 2), 3)            # 0.702 and 6.568
A <- c(7.7, 10.1, 7.2, 8.7, 10.5, 7.9, 8.1, 7.9, 8.3, 8.8, 10.0, 7.7, 7.4)
B <- c(7.5, 6.5, 7.5, 7.0, 5.3, 8.0, 7.4, 8.7, 8.7)
p_two_tailed_t(t_two(A, B), 13 + 9 - 2)           # 0.031
pf(var(A) / var(B), 12, 8)                         # 0.497

The numbers in the comments are the solutions’: if you get something else when you paste it, check the data.

What next?

With sampling distributions you close the block on the normal and the limit theorems. The next ME1 topic is point estimation: how to get a good value for an unknown parameter from a sample, with the method of moments and maximum likelihood. There Xˉ \bar X and S2 S^2 stop being just statistics and become estimators, and what you saw today (their mean, their variance and their distribution) is exactly what you need to decide whether they are good. And in confidence intervals you will use qchisq, qt and qf exactly as here.

If you want to review first, you have the theory, the proofs and the practice for this topic, and the limit theorems, where the normal of the mean comes from when the population is not normal.

Keep goingAll Statistics articles

Did this article help you? Here is how you can support SergioLearns →

Ready for the exam?ME1 EC2 mock exam — 4 hours with R beside you, from the normal to confidence intervals, four versions and a mark out of 50 (and why exercise 1 is worth double)