An R Introduction to Statistics

Interval Estimate of Population Mean with Known Variance

After we found a point estimate of the population mean, we would need a way to quantify its accuracy. Here, we discuss the case where the population variance σ2 is assumed known.

Let us denote the 100(1 α∕2) percentile of the standard normal distribution as zα∕2. For random sample of sufficiently large size, the end points of the interval estimate at (1 α) confidence level is given as follows:

¯x± zα∕2√--


Assume the population standard deviation σ of the student height in survey is 9.48. Find the margin of error and interval estimate at 95% confidence level.


We first filter out missing values in survey$Height with the na.omit function, and save it in height.response.

> library(MASS)                  # load the MASS package 
> height.response = na.omit(survey$Height)

Then we compute the standard error of the mean.

> n = length(height.response) 
> sigma = 9.48                   # population standard deviation 
> sem = sigma/sqrt(n); sem       # standard error of the mean 
[1] 0.65575

Since there are two tails of the normal distribution, the 95% confidence level would imply the 97.5th percentile of the normal distribution at the upper tail. Therefore, zα∕2 is given by qnorm(.975). We multiply it with the standard error of the mean sem and get the margin of error.

> E = qnorm(.975)sem; E         # margin of error 
[1] 1.2852

We then add it up with the sample mean, and find the confidence interval as told.

> xbar = mean(height.response)   # sample mean 
> xbar + c(E, E) 
[1] 171.10 173.67


Assuming the population standard deviation σ being 9.48, the margin of error for the student height survey at 95% confidence level is 1.2852 centimeters. The confidence interval is between 171.10 and 173.67 centimeters.

Alternative Solution

Instead of using the textbook formula, we can apply the z.test function in the TeachingDemos package. It is not a core R package, and must be installed and loaded into the workspace beforehand.

> library(TeachingDemos)         # load TeachingDemos package 
> z.test(height.response, sd=sigma) 
       One Sample ztest 
data:  height.response 
z = 262.88, n = 209.000, Std. Dev. = 9.480, 
Std. Dev. of the sample mean = 0.656, pvalue < 2.2e16 
alternative hypothesis: true mean is not equal to 0 
95 percent confidence interval: 
 171.10 173.67 
sample estimates: 
mean of height.response