STAT 516 Lec 01 (accessible)

Inference on the mean and variance of a Normal population

Author

Karl Gregory

Published

August 26, 2026

Setup

Throughout let X1,,XnindN(μ,σ2).

In this lecture we review how to:

  1. Estimate μ and σ2.
  2. Build confidence intervals for μ and σ2.
  3. Test hypotheses concerning μ and σ2.
  4. Choose the sample size.

We call X1,,Xn a random sample.

Golden ratio example:

A class of n=27 students measured B/A on themselves:

gr <- c(1.66, 1.61, 1.62, 1.69, 1.58, 1.43, 1.66, 
        1.69, 1.58, 1.20, 1.52, 1.60, 1.55, 1.67, 
        1.77, 1.50, 1.64, 1.54, 1.40, 1.36, 1.50, 
        1.40, 1.35, 1.48, 1.64, 1.91, 1.70)

What is the true mean of B/A? Could it be the golden ratio?!?


Check if B/A measurements come from a Normal distribution.

qqnorm(scale(gr))
abline(0,1)

Estimation

Based on X1,,Xn, define the sample statistics

  • X¯n=1ni=1nXi
  • Sn2=1n1i=1n(XiX¯n)2

Then X¯n and Sn2 are unbiased estimators of μ and σ2, respectively.

Golden ratio example (cont):

We have X¯n= mean(gr) = 1.565 and Sn2= var(gr) = 0.0219.

hist(gr)

Important sampling distribution results

Provided X1,,XnindN(μ,σ2), we have

  • X¯nμσ/nN(0,1)
  • (n1)Sn2σ2χn12
  • X¯nμSn/ntn1

Discuss: Anatomy of chi-square and t random variables

  • Z1,,ZmindN(0,1)Z12++Zm2χm2.
  • ZNormal(0,1)Wχm2ZW/mtm.

Relate these to the results on the previous slide.

Simulation illustrating sampling distribution results:

sims <- 1000
mu <- 1
sigma <- 1/2
n <- 8
Tn <- numeric(sims)
Wn <- numeric(sims)
for(s in 1:sims){
  
  X <- rnorm(n,mu,sigma)
  sn <- sd(X)
  xbar <- mean(X)
  Tn[s] <- sqrt(n)*(xbar - mu) / sn
  Wn[s] <- (n-1)*sn^2 / sigma^2
  
}

hist(Tn,freq = FALSE,breaks = 50)
x <- seq(-4,4,length = 500)
lines(dt(x,n-1)~x)


hist(Wn,freq = FALSE,breaks = 50)
x <- seq(0,max(Wn),length = 500)
lines(dchisq(x,n-1)~x)

Confidence intervals for the mean and variance

The sampling distribution results give (1α)100% CIs as

  • X¯n±tn1,α/2Snn for μ.
  • ((n1)Sn2χn1,α/22,(n1)Sn2χn1,1α/22) for σ2.

Exercise: Derive the above.

Golden ratio example (cont):

Build 95% CIs for population mean and variance of B/A values:

alpha <- 0.05
n <- length(gr)

lomu <- mean(gr) - qt(1-alpha/2,n-1) * sd(gr)/sqrt(n)
upmu <- mean(gr) + qt(1-alpha/2,n-1) * sd(gr)/sqrt(n)

losgs <- (n-1) * var(gr) / qchisq(1-alpha/2,n-1)
upsgs <- (n-1) * var(gr) / qchisq(alpha/2,n-1)

The 95% CI for μ is (1.506,1.623). For σ2 it is (0.014,0.041).

Testing hypotheses about the mean

Consider testing hypotheses about μ of the form H0μμ0 or H0μ=μ0 or H0μμ0H1μ<μ0H1μμ0H1μ>μ0. Reject or fail to reject H0 based on the value of the test statistic Tstat=X¯nμ0Sn/n. Rejection rules for the above at significance level α are Tstat<tn1,α or |Tstat|>tn1,α/2 or Tstat>tn1,α.

The corresponding p-values are, with Ttn1, the probabilities P(T<Tstat) or 2×P(T>|Tstat|) or P(T>Tstat).

Golden ratio example (cont):

Test H0: μ=1.618 vs H1: μ1.618 at α=0.05 based on data.

alpha <- 0.05
Tstat <- (mean(gr) - 1.618) / (sd(gr) / sqrt(n))
abs(Tstat) > qt(1-alpha/2,n-1)
[1] FALSE

Fail to reject H0 since Tstat = -1.866 is smaller in absolute value than tn1,α/2 = 2.056.

pval <- 2*(1 - pt(abs(Tstat),n-1))

Equivalently, the p-value, which is 0.073, is greater than α=0.05.

The t.test() function in R

The function t.test() tests H0: μ=0 vs H1: μ0 by default.

t.test(gr)

    One Sample t-test

data:  gr
t = 54.902, df = 26, p-value < 2.2e-16
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
 1.506228 1.623401
sample estimates:
mean of x 
 1.564815 

The t.test() function in R

Now test H0: μ=1.618 versus H1: μ1.618, ask for 99% CI.

t.test(gr, mu = 1.618, conf.level = 0.99)

    One Sample t-test

data:  gr
t = -1.866, df = 26, p-value = 0.07336
alternative hypothesis: true mean is not equal to 1.618
99 percent confidence interval:
 1.485616 1.644013
sample estimates:
mean of x 
 1.564815 

The t.test() function in R

Now test H0: μ1.618 versus H1: μ>1.618.

t.test(gr, mu = 1.618, alternative = "greater")

    One Sample t-test

data:  gr
t = -1.866, df = 26, p-value = 0.9633
alternative hypothesis: true mean is greater than 1.618
95 percent confidence interval:
 1.516202      Inf
sample estimates:
mean of x 
 1.564815 

Testing hypotheses about the variance

Consider testing hypotheses about σ2 of the form H0σ2σ02 or H0σ2σ02H1σ2<σ02H1σ2>σ02 Reject or fail to reject H0 based on the value of the test statistic Wstat=(n1)Sn2σ02. Rejection rules for the above at significance level α are Wstat<χn1,1α2 or Wstat>χn1,α2

The corresponding p-values are, with Wχn12, the probabilities P(W<Wstat) or P(W>Wstat).

Golden ratio example (cont):

Test H0: σ20.03 vs H1: σ2<0.03 at α=0.05 based on data.

alpha <- 0.05
Wstat <- (n-1)*var(gr) / 0.03
Wstat < qchisq(alpha,n-1)
[1] FALSE

FTR H0 since Wstat = 19.009 is not less than χn1,1α2 = 15.379.

pval <- pchisq(Wstat,n-1)

Equivalently, the p-value, which is 0.164, is greater than α=0.05.

Pallet weights example

The weights in lbs of several wooden pallets were recorded.

wt <- c(41,34,40,44,33,42,52,38,32,31,31,35,
        39,44,42,42,35,33,40,48,51,32,41,35,
        38,48,37,35,42,41,40,47,40,46,33,38,
        51,39,40)

Pallet weights example continued

  • Check if we can assume normally distributed pallet weights.
  • Build a 95% CI for the mean pallet weight assuming σ=5.
  • Build a 95% CI for the mean pallet weight assuming σ is unknown.
  • Test at α=0.05 whether the mean pallet weight is equal to 48 lbs.
  • Test at α=0.05 whether the mean pallet weight is less than 40 lbs.

Sample size calculations

We can choose a sample size based on the desired:

  1. Width of a confidence interval.
  2. Power of a test to reject H0 when it is false.

Sample size required to achieve desired CI width

A CI for μ takes the form X¯n±M, where

  • M=zα/2σn if σ is known
  • M=tn1,α/2Snn if σ is unknown

For ease, use the “σ-known” version.

If one wants MM, find smallest n such that zα/2σnM.

So take n=(zα/2σM)2, where rounds up.

Must put in a guess for σ.

Golden ratio example (cont):

Find n required to make the 95% CI for μ no wider than 0.08.

alpha <- 0.05
M <- 0.08/2
sigma_guess <- sd(gr)
nr <- ceiling((qnorm(1-alpha/2) * sigma_guess / M)^2)
nr
[1] 53

Sample size required to achieve desired power

The power of a test is the probability with which it rejects H0.

For tests of H0 concerning the mean μ we write the power as γ(μ)=P(Reject H0 when true mean is μ)=Pμ(Reject H0).

So the power depends on the true value of μ, i.e. is a function of μ.


Exercise: Derive the power functions for the tests of H0μμ0 and H0μ=μ0 and H0μμ0H1μ<μ0H1μμ0H1μ>μ0 with the rejection rules Zstat<zα and |Zstat|>zα/2 and Zstat>zα, respectively, where Zstat=X¯nμ0σ/n (σ-known case).

Plot of power curves for right-, left-, and two-sided tests

Set μ0=1.618, n=27, and α=0.05 and use σ=0.148.

alpha <- 0.05
mu0 <- 1.618
sigma <- sd(gr)
n <- length(gr)
mu <- seq(mu0-4*sigma/sqrt(n),mu0+4*sigma/sqrt(n),length=500)
za <- qnorm(1-alpha)
za2 <- qnorm(1-alpha/2)
d <- sqrt(n) * (mu - mu0) / sigma
rp <- 1 - pnorm(za - d)
lp <- pnorm(-za - d)
rp2 <- 1 - pnorm(za2 - d)
lp2 <- pnorm(-za2 - d)
tsp <- lp2 + rp2

plot(rp ~ mu, type = "l", ylab = "power", xlab = "mu")
lines(lp ~ mu, lty =2)
lines(tsp ~ mu, lty = 3)

Power curve for right-sided test at various sample sizes

Test H0: μ1.618 vs H1: μ>1.618. Use α=0.05 and σ=0.148.

alpha <- 0.05
mu0 <- 1.618
sigma <- sd(gr)
n <- length(gr)
mu <- seq(mu0-1*sigma/sqrt(n),mu0+4*sigma/sqrt(n),length=500)
za <- qnorm(1-alpha)

# various sample sizes
nn <- c(10,20,30,40,50,60)
rp <- matrix(NA,500,length(nn))
for(j in 1:length(nn)){
  d <- sqrt(nn[j]) * (mu - mu0) / sigma
  rp[,j] <- 1 - pnorm(za - d)
}

plot(NA,xlim = range(mu), ylim = c(0,1), ylab = "power", xlab = "mu")
for(j in 1:length(nn)) lines(rp[,j] ~ mu, lty = j)
legend(x = min(mu), y = 1,legend = paste("n =",nn),lty = 1:length(nn),bty = "n")


Sample size based on desired power

To find the smallest sample size guaranteeing a desired power:

  1. Fix an alternative value μ and a desired power γ.
  2. Set up the equation γ(μ)=γ and solve for n (then round up).

For our tests concerning μ when σ is known, we obtain:

  • In the one-sided case n=σ2(zα+zβμμ0)2.
  • In the two-sided case n=σ2(zα/2+zβμμ0)2.

In the above β=1γ.


Exercise: Derive the sample size formula for the test of H0μμ0 vs H1μ>μ0 when σ is known.

Golden ratio example (cont):

Suppose the true mean of B/A in the population is 1.65.

Give the sample size n required to reject H0: μ1.618 vs H1: μ>1.618 with power 0.80. Use Sn = 0.148 as a guess of σ.

alpha <- 0.05
gm <- 0.80
sigma <- sd(gr)
mu <- 1.65
mu0 <- 1.618
za <- qnorm(1 - alpha)
zb <- qnorm(gm)
nr <- ceiling(sigma^2 * (za + zb)^2 / (mu - mu0)^2)
nr
[1] 133