# Estimating the Population Mean with the Sample Mean

I am trying to better understand how the sample mean can be used to estimate the population mean. Using the R language, suppose I have the following population:

library(dplyr)
set.seed(123)
pop = rnorm(100000,5,5)
i = 1
population = data.frame(i,pop)


The mean of this population is:

 mean(population$pop)  4.985157  I take random (small) samples from this population sample_1 <- population %>% sample_frac(0.01) mean(sample_1$pop)

4.875

sample_2 <- population %>% sample_frac(0.01)
mean(sample_2$pop) 4.569 sample_3 <- population %>% sample_frac(0.01) mean(sample_3$pop)

5.13


My Question: All these sample mean estimates, even though they are very small - are so close to the population mean! Is this how sampling works? 100 observations from a 100000 observation population is enough to get a good estimate of the mean?

Thanks!

• As long as the standard deviation $\sigma$ of the normal population from which the data were sampled, is not too large as sample of size $n=100$ should give a suitably narrow 95% confidence interval. The margin of error $1.96s/\sqrt{n}$ will be roughly $\sigma/5.$ Oct 13 at 23:08
• In simpler language, what you've observed is basically why random sampling is so useful! Practitioners are used to it but it's definitely a deep result that a well-constructed random sample of only a tiny fraction of a population can be enough for accurate estimation of a population parameter; in your case you're taking a simple random sample which is a sound sampling strategy. A famous example where this was not appreciated is the Literary Digest poll of 1936 where they had a huge sample size but were way off because it wasn't representative
– jld
Oct 13 at 23:54
• Note that in your example the underlying total population has a normal distribution. This makes these sample mean estimates work fairly well even with relatively small samples. If you have a different distribution possibly with heavy tails, estimating the mean from samples gets a lot more inaccurate. Oct 14 at 9:31
• It is shown in this answer from math.SE, that $E\!\left[(m_s-m_d)^2\right]=\frac1nv_d$, where $m_s$ is the sample mean, $m_d$ is the distribution mean, and $v_d$ is the distribution variance. This means that the expected value of $|m_s-m_d|$ is less than $\frac\sigma{\sqrt{n}}$, where $\sigma$ is the standard deviation of the distribution. Oct 14 at 15:35

Let $$X_{1},X_{2},\dots ,X_{n}$$ are $$n$$ random samples drawn from a population with overall mean $$\mu$$ and finite variance $$\sigma ^{2}$$ and if $$\bar {X}_{n}$$ is the sample mean, then

• We know sample mean (statistic) is an unbiased estimator of the population mean (parameter) i.e., $$E[\bar{X_n}]=\mu$$
• By SLLN we have $$\bar{X_n}\overset{a.s.}{\rightarrow}\mu$$ and WLLN we have $$\bar{X_n}\overset{P}{\rightarrow}\mu$$, when $$n \to \infty$$
• By CLT, $$\dfrac{\bar{X_n}-\mu}{\sigma/\sqrt{n}}\overset{D}{\rightarrow}N(0,1)$$, where a rule of thumb is sample size $$n \geq 30$$
• We can compute the $$(1-\alpha)\%$$ confidence interval for the population mean by $$\bar{X_n}\pm z_{\alpha/2}\frac{\sigma}{\sqrt{n}}$$

For example, with the following R code snippet we can construct a $$95\%$$ confidence interval for the population mean:

sigma <- 5
n <- length(sample_1$$pop) x_bar <- mean(sample_1$$pop)
# 95% CI
c(x_bar - qnorm(0.975)*sigma/sqrt(n), x_bar + qnorm(0.975)*sigma/sqrt(n))
#  4.804931 5.424726


The following animation shows how the sampling distribution changes when the sample size gets larger: The next animation shows how the confidence interval changes for different samples and if you repeat drawing random samples (with replacement) for a long time, there is $$(1-\alpha)\%$$ chance of the population mean falling inside the $$(1-\alpha)\%$$ confidence interval. • As can be seen from above, since the population is normally distributed, an observation has low probability to have value far away from the population mean (e.g., there are less than $$5\%$$ points with more than $$2$$ standard deviations away from mean), that's why even when the sample size is small, there is a very low probability that an observation in population far away from the population mean will be chosen in the sample, which keeps the sample mean close enough to population mean and the confidence interval constructed around the point estimate (sample mean) almost always contains the population mean. This will not be the case (in general), particularly for the population that has a distribution with fat tails.

The next animation shows how the length of the $$95\%$$ confidence interval decreases as we have larger sample size: • I fear this answer might be too technical to help the OP right now (though everything looks correct).
– Dave
Oct 13 at 22:34
• And the animation is nice. Oct 13 at 23:51

If you have a sample $$X_1, X_2, \dots, X_n$$ from a normal population in vector x, the procedure t.test in R will give you a 95% confidence interval $$(49.19, 50.33)$$ for the population mean $$\mu,$$ for a sample of size $$n = 20$$ from $$\mathsf{Norm}(\mu = 50, \sigma=7),$$ as shown below. (No hand computation is needed.)

set.seed(2021)
x = rnorm(20, 50, 7)
t.test(x)$conf.int  49.19194 56.32578 attr(,"conf.level")  0.95  This procedure also does a t test, but you can use $ notation to show just the confidence interval.

This confidence interval is of the form $$\bar X\pm t^* s/\sqrt{n},$$ where $$\bar X$$ is the sample mean, $$s$$ is the sample standard deviation, and $$t^*$$ cuts probability $$0.025$$ from the upper tail of Student's t distribution with $$n-1 = 19$$ degrees of freedom.

a = mean(x)           # sample mean
s = sd(x)             # sample standard deviation
t.q = qt(.975, 19)    # quantiles .025 and .975 of T(19)

a; s; qt(.975,19)
 52.75886
 7.621391
 2.093024
a + qt(c(.025,.975), 19)*s/sqrt(20)
 49.19194 56.32578


Notice that the appropriate quantiles of the (symmetrical) t distribution are $$\pm 2.09,$$ whereas the same quantiles of the standard normal distribution are $$\pm 1.96.$$ When $$n\ge 30,$$ the quantiles of $$\mathsf{T}(n-1)$$ for a 95% confidence interval are not far from $$\pm 1.96;$$ both quantiles round to $$2.0.$$ [But this 'rule of 30' does not work quite so well for confidence levels other than 95%. For a 90% CI the normal quantiles are $$\pm 1.645\approx \pm 1.6;$$ for $$n=30$$ the t quantiles are $$\pm 1.699 \approx \pm 1.7.]$$

qnorm(c(.025,.975))
 -1.959964  1.959964


If, for some reason, you wanted a 90% or a 99% confidence interval for $$\mu$$ in the above example, you could also get those by using t.test. Notice that the 99% confidence interval is the longest of the three CIs given here (90%, 95%, 99%).

t.test(x, conf.level = .90)$$conf.int  49.81208 55.70564 attr(,"conf.level")  0.9 t.test(x, conf.level = .99)$$conf.int
 47.88327 57.63445
attr(,"conf.level")
 0.99


Finally, supposing we did not know that the data x were sampled from a normal distribution with $$\mu = 50,$$ we wanted to test $$H_0: \mu = 50$$ against $$H_a: \mu \ne 50.$$ Here are complete results from t.test.

t.test(x, mu = 50)

One Sample t-test

data:  x
t = 1.6189, df = 19, p-value = 0.122
alternative hypothesis:
true mean is not equal to 50
95 percent confidence interval:
49.19194 56.32578
sample estimates:
mean of x
52.75886


The null hypothesis is not rejected at the 5% level of significance because the P-value $$0.122 > 0.05 = 5\%.$$ Accordingly, $$\mu_0 = 50$$ is contained in the 95% CI.