3  Simple Random Sampling

Author
Published

October 24, 2026

Simple random sampling is the simplest probability sampling design, and the building block for all the designs in later chapters. A stratified sample is an SRS within each stratum; a cluster sample is an SRS of clusters. This chapter defines the design, derives its estimators and their standard errors, shows how to build confidence intervals and choose the sample size, and checks the theory by simulation. The material corresponds to Sections 2.3–2.6 and 2.8 of Lohr and Sections 4.1–4.5 of Scheaffer et al.

3.1 SRS and SRSWR

There are two versions of simple random sampling.

A simple random sample with replacement (SRSWR) of size \(n\) from a population of \(N\) units can be thought of as \(n\) independent draws of one unit, each unit having probability \(1/N\) on every draw. The same unit can be drawn more than once.

A simple random sample without replacement (SRS) of size \(n\) is selected so that every possible subset of \(n\) distinct units in the population has the same probability of being the sample. There are \(\binom{N}{n}\) such subsets, so \[ P(\mathcal S) = \frac{1}{\binom{N}{n}} = \frac{n!\,(N-n)!}{N!} \] for every subset \(\mathcal S\) of size \(n\). Unless stated otherwise, “SRS” in this book means sampling without replacement. In practice an SRS is drawn with computer-generated random numbers; in R,

Code
sample(1:N, size = n)

returns the labels of \(n\) distinct units chosen in this way.

Figure 3.1 illustrates an SRS of \(n = 60\) from a synthetic population of \(N = 1000\) units. The design uses no information about the units other than their labels, so the sampled units (red) are scattered at random over the population, and their values cover its whole range.

Figure 3.1: A simple random sample of \(n = 60\) (red) from a synthetic population of \(N = 1000\) units, listed in an arbitrary order. The dashed line is the population mean.

3.1.1 Inclusion probabilities

To study which units end up in the sample, define the sample-membership indicator \[ Z_i = \begin{cases} 1 & \text{if unit } i \text{ is in the sample,} \\ 0 & \text{otherwise.} \end{cases} \] The probability \(\pi_i = P(Z_i = 1)\) is the inclusion probability of unit \(i\). If unit \(i\) is in the sample, the other \(n-1\) sampled units must come from the remaining \(N-1\) units, so \[ \pi_i = P(Z_i=1) = \frac{\text{number of samples including unit } i}{\text{number of possible samples}} = \frac{\binom{N-1}{n-1}}{\binom{N}{n}} = \frac{n}{N}. \] Every unit has the same chance \(n/N\) of being in the sample. The indicators \(Z_1, \ldots, Z_N\) are the only random quantities in design-based inference; we use them in Section 3.6 to prove the properties of the estimators.

3.2 Estimators for Simple Random Sampling

Write \(y_i\) for the value of unit \(i\) in the population \(U = \{1, \ldots, N\}\), and \[ \bar{y}_U = \frac{1}{N}\sum_{i=1}^N y_i, \qquad t = \sum_{i=1}^N y_i = N\bar{y}_U, \qquad S^2 = \frac{1}{N-1}\sum_{i=1}^N (y_i - \bar{y}_U)^2 \] for the population mean, total and variance. These are fixed, unknown numbers.

3.2.1 Estimating the population mean

The natural estimator of \(\bar y_U\) is the sample mean, and the natural estimator of \(S^2\) is the sample variance: \[ \bar y = \frac1n \sum_{i \in \mathcal S} y_i = \frac1n \sum_{i=1}^N Z_i y_i, \qquad s^2 = \frac{1}{n-1}\sum_{i\in\mathcal S} (y_i - \bar y)^2 . \] The sample mean is unbiased for \(\bar y_U\), and its variance is \[ V(\bar{y}) = \left(1 - \frac{n}{N}\right)\frac{S^2}{n} \] (both are proved in Section 3.6). This is the familiar \(S^2/n\) of independent sampling, multiplied by the factor \(1 - n/N\), the finite population correction (fpc). Sampling without replacement removes units from the pool, so the sample covers more of the population than independent draws would, and the variance is smaller. When the sampling fraction \(n/N\) is small, the fpc is close to \(1\) and can be ignored. When \(n = N\), the sample is a census and \(V(\bar y) = 0\).

Since \(s^2\) is unbiased for \(S^2\) (also proved in Section 3.6), replacing \(S^2\) by \(s^2\) gives an unbiased estimator of the variance. Its square root is the standard error: \[ \boxed{ \hat{V}(\bar{y}) = \left(1 - \frac{n}{N}\right)\frac{s^2}{n}, \qquad \mathrm{SE}(\bar y) = \sqrt{\Big(1-\frac nN\Big)\frac{s^2}{n}} .} \]

3.2.2 Estimating the population total

Since \(t = N\bar y_U\), the total is estimated by scaling up the sample mean: \[ \boxed{ \hat{t} = N\bar{y}, \qquad \hat{V}(\hat{t}) = N^2\left(1 - \frac{n}{N}\right)\frac{s^2}{n}, \qquad \mathrm{SE}(\hat{t}) = N\,\mathrm{SE}(\bar{y}).} \]

Sampling weights. The estimated total can also be written with sampling weights. The sampling weight of a unit is the reciprocal of its inclusion probability, \(w_i = 1/\pi_i = N/n\), and \[ \hat t = \sum_{i\in\mathcal S} w_i y_i = \sum_{i\in\mathcal S} \frac{N}{n} y_i . \] Each sampled unit “represents” \(N/n\) units of the population: itself and \(N/n - 1\) unsampled ones. In an SRS all weights are equal; in later chapters (stratified, cluster and unequal-probability sampling) they are not, but the weighted-sum form of \(\hat t\) carries over.

3.2.3 Coefficient of variation

The standard error is in the units of \(y\). A scale-free measure of precision is the coefficient of variation (CV), defined when \(\bar y_U \ne 0\): \[ \mathrm{CV}(\bar y) = \frac{\sqrt{V(\bar y)}}{E(\bar y)} = \sqrt{1-\frac nN}\ \frac{S}{\sqrt n\, \bar y_{U}}, \qquad \widehat{\mathrm{CV}}(\bar y) = \frac{\mathrm{SE}(\bar y)}{\bar y} . \] Because \(\hat t = N\bar y\), the factor \(N\) cancels and \(\mathrm{CV}(\hat t) = \mathrm{CV}(\bar y)\). A CV of 0.05 means the standard error is 5% of the estimate, whatever the units of measurement.

3.2.4 Estimating a proportion

Estimating a proportion is a special case of estimating a mean. Define \(y_i=1\) if unit \(i\) has the characteristic of interest and \(y_i=0\) otherwise. Then the population proportion and the sample proportion are \[ p = \frac{1}{N}\sum_{i=1}^N y_i = \bar y_{U}, \qquad \hat p = \frac1n\sum_{i\in\mathcal S} y_i = \bar y , \] so \(\hat p\) is unbiased for \(p\). For a 0/1 variable \(y_i^2 = y_i\), and the variances simplify: \[ S^2 = \frac{N}{N-1}\,p(1-p), \qquad s^2 = \frac{n}{n-1}\,\hat p(1-\hat p). \] Substituting into the general formulas, \[ V(\hat p) = \Big(\frac{N-n}{N-1}\Big)\frac{p(1-p)}{n}, \qquad \boxed{\hat V(\hat p) = \Big(1-\frac nN\Big)\frac{\hat p (1-\hat p)}{n-1}.} \] The number of units with the characteristic, \(Np\), is estimated by \(N\hat p\) with standard error \(N\,\mathrm{SE}(\hat p)\).

3.3 Example: The Census of Agriculture

The U.S. government conducts a Census of Agriculture every five years. It collects data on all farms (any place producing $1000 or more of agricultural products) in the 50 states, for each of the \(N=3078\) counties and county-equivalents. The file agpop.csv contains the 1982, 1987 and 1992 farm data for the whole population. An SRS of \(n=300\) counties was selected with computer-generated random numbers and saved as agsrs.csv. We use it to estimate the mean and total of acres92, the number of acres devoted to farms in 1992, and the proportion of counties with fewer than 200,000 acres in farms.

Throughout the agriculture examples in this book, county acreages are expressed in thousands of acres. The raw figures run into the millions, and every mean, variance and total reads far more easily on that scale. The helper acres_in_thousands() performs the conversion as the data are read.

3.3.1 Step-by-step calculation

We first compute the estimates directly from the formulas of Section 3.2.

Code
## read survey data
agsrs <- read.csv ("data/agsrs.csv")
## work in thousands of acres, the unit used for every agriculture example here
agsrs[c("acres92", "acres87", "acres82")] <- agsrs[c("acres92", "acres87", "acres82")] / 1000
head(agsrs)
Code
## extract the variable of interest
sdata <- agsrs$acres92
N <- 3078

## do calculation
n <- length (sdata)
ybar <- mean (sdata)
s <- sd (sdata)
se.ybar <- sqrt((1 - n / N)) * s / sqrt(n)
mem <- qt (0.975, df = n - 1) * se.ybar

## return estimate vector for pop mean
c (Est. = ybar, S.E. = se.ybar, ci.low = ybar - mem, ci.upp = ybar + mem)
     Est.      S.E.    ci.low    ci.upp 
297.89705  18.89843 260.70626 335.08784 
Code
## return estimate vector for pop total
c (Est. = ybar, S.E. = se.ybar, ci.low = ybar - mem, ci.upp = ybar + mem) * N
      Est.       S.E.     ci.low     ci.upp 
 916927.11   58169.38  802453.86 1031400.36 

In thousands of acres, the sample gives \(\bar y = 297.897\) and \(s = 344.55\), so \[ \mathrm{SE}(\bar y) = \sqrt{\Big(1-\frac{300}{3078}\Big)\frac{344.55^2}{300}} = 18.898, \] \[ \hat t = N\bar y = 3078(297.897) = 916,927, \qquad \mathrm{SE}(\hat t) = 3078(18.898) = 58,169 . \] The average county has about 298 thousand acres in farms, and the U.S. total is estimated at about 917 million acres. The estimated coefficient of variation is \[ \widehat{\mathrm{CV}}(\hat t) = \widehat{\mathrm{CV}}(\bar y) = \frac{\mathrm{SE}(\bar y)}{\bar y} = \frac{18.898}{297.897} = 0.0634, \] so the standard error is about 6.3% of the estimate.

The data are highly skewed (Figure 3.2): most counties have fewer than 500 thousand acres in farms, but some have more than 1.5 million. For such data the mean is pulled up by the long right tail, and we should also report the median, which is 196.7 thousand acres here, well below the mean.

Code
hist(sdata, breaks = 30, col = "lightblue", border = "white",
     xlab = "acres92 (thousands of acres)", main = "")
abline(v = c(ybar, median(sdata)), col = c("firebrick", "darkgreen"), lwd = 2, lty = c(1, 2))
legend("topright", bty = "n", lwd = 2, lty = c(1, 2), col = c("firebrick", "darkgreen"),
       legend = c("mean", "median"))
Figure 3.2: Farm acreage in 1992 (thousands of acres) for the SRS of 300 counties. The distribution is strongly skewed to the right.

A proportion. Let \(y_i = 1\) if county \(i\) has fewer than 200 thousand acres in farms. In the sample, 153 of the 300 counties do, so \(\hat p = 153/300 = 0.51\) and \[ \mathrm{SE}(\hat p) = \sqrt{\Big(1-\frac{300}{3078}\Big)\frac{(0.51)(0.49)}{299}} = 0.0275 . \]

3.3.2 A function for repeated use

The same calculation is needed again and again, so we wrap it in a function. To avoid repeating code in every chapter, all estimating functions (and their gt table formatting helpers) live in a single shared file, samplingestimate.r, sourced at the start of this chapter. The SRS function is srs_est().

The full source of samplingestimate.r is listed in Appendix C.

Code
agsrs <- acres_in_thousands (read.csv ("data/agsrs.csv"))

Estimating the mean of acres92. The function’s $table shows the row-level working values (the first 6 rows and the Sum), and $estimate holds the point estimate, SE and CI, formatted with format_est_gt().

Code
res_mean <- srs_est(agsrs[,"acres92"], N = 3078, estimate = "mean")
res_mean$table
SRS Mean Estimation: Working Table
\(n = 300\)
\(i\) \(y_i\) \(\hat y_i\) \(e_i\) \((y_i-\hat y_i)^2\)1
1 175.21 297.90 −122.69 15,052.36
2 138.13 297.90 −159.76 25,523.91
3 56.10 297.90 −241.80 58,464.84
4 199.12 297.90 −98.78 9,757.50
5 89.23 297.90 −208.67 43,542.77
6 96.19 297.90 −201.70 40,684.12
... ... ... ... ...
Sum 89,369.11 297.90 0.00 35,496,086.45
1 \(\hat y_i = \bar y\) for every unit under the SRS model; \(s_y^2 = \sum_i (y_i-\hat y_i)^2/(n-1) = 1.19 \times 10^{5}\).
\(\bar y = \dfrac{\sum_i y_i}{n} = \dfrac{89,369.11}{300} = 297.90\)
\(\mathrm{SE}(\bar y) = \sqrt{1-\dfrac{n}{N}}\,\dfrac{s_y}{\sqrt n} = \sqrt{1-\dfrac{300}{3078}}\,\dfrac{344.55}{\sqrt{300}} = 18.90\)
Code
res_mean$estimate |> format_est_gt("mean")
\(\bar{y}\) \(\mathrm{SE}(\bar{y})\) 95% CI Lower 95% CI Upper
297.90 18.90 260.71 335.09

Estimating the total of acres92. Setting estimate = "total" makes the function scale the mean and confidence interval by \(N = 3078\).

Code
res_total <- srs_est(agsrs[,"acres92"], N = 3078, estimate = "total", show.details = FALSE)
res_total$estimate |> format_est_gt("total")
\(\hat{t}\) \(\mathrm{SE}(\hat{t})\) 95% CI Lower 95% CI Upper
916,927.11 58,169.38 802,453.86 1,031,400.36

Estimating the proportion of counties with fewer than 200K acres. We create the 0/1 indicator and estimate its mean.

Code
acres92.is.fewer.200k <- as.numeric (agsrs[,"acres92"] < 200)   # 200 thousand acres
head(acres92.is.fewer.200k)
[1] 1 1 1 1 1 1
Code
res_prop <- srs_est(acres92.is.fewer.200k, N = 3078, estimate = "mean", show.details = FALSE)
res_prop$estimate |> format_est_gt("mean")
\(\bar{y}\) \(\mathrm{SE}(\bar{y})\) 95% CI Lower 95% CI Upper
0.51 0.03 0.46 0.56

Estimating the number of such counties.

Code
res_prop_total <- srs_est(acres92.is.fewer.200k, N = 3078, estimate = "total", show.details = FALSE)
res_prop_total$estimate |> format_est_gt("total")
\(\hat{t}\) \(\mathrm{SE}(\hat{t})\) 95% CI Lower 95% CI Upper
1,569.78 84.54 1,403.42 1,736.14

3.3.3 Comparing with the true values

Because the census file agpop.csv contains the whole population, we can check how close the SRS estimates came to the true values. (In a real survey these are, of course, unknown.)

Code
agpop <- acres_in_thousands (read.csv ("data/agpop.csv"))
#true mean (thousands of acres)
mean (agpop[, "acres92"], na.rm = T)
[1] 308.5824
Code
# true total (thousands of acres)
sum (agpop[, "acres92"], na.rm = T)
[1] 943953.6
Code
# true proportion of counties with less than 200K acres for farming
mean (agpop[, "acres92"] < 200, na.rm = T)
[1] 0.5145472
Code
# true number of counties with less than 200K acres for farming
sum (agpop[, "acres92"] < 200, na.rm = T)
[1] 1574

All the true values lie inside the 95% confidence intervals computed above.

3.4 Confidence Intervals

A confidence interval (CI) indicates the accuracy of an estimate. A 95% CI is often explained heuristically: if we took samples from the population over and over again, and constructed a CI by our procedure for each possible sample, we would expect 95% of the resulting intervals to include the true value of the population quantity. In design-based inference this is literally what the probability refers to: the population is fixed and the randomness is over the \(\binom{N}{n}\) possible samples.

3.4.1 Normality of the sample mean

In an SRS without replacement the observations are not independent, so the ordinary central limit theorem does not apply directly. A finite-population version is due to Hájek (1960): if certain technical conditions hold and \(n\), \(N\) and \(N-n\) are all “sufficiently large”, then the sampling distribution of \[ \frac{\bar y - \bar y_{U}}{\sqrt{\big(1-\tfrac nN\big)}\, \tfrac{S}{\sqrt n}} \] is approximately standard normal. Replacing \(S\) by \(s\) gives the standard error, and approximate \(100(1-\alpha)\%\) CIs for the mean, total and proportion are \[ \bar y \pm t_{\alpha/2,\, n-1} \, \mathrm{SE}(\bar y), \qquad \hat t \pm t_{\alpha/2,\, n-1} \, \mathrm{SE}(\hat t), \qquad \hat p \pm t_{\alpha/2,\, n-1} \, \mathrm{SE}(\hat p). \] The \(t\) quantile is customary; for the sample sizes used in surveys it is very close to the normal quantile \(z_{\alpha/2}\).

Example (continued). For the agriculture sample, \(t_{0.025,\,299} = 1.968\), and the 95% CIs are \[ \text{mean: } 297.9 \pm 1.968(18.9) = [260.7,\ 335.1] \text{ thousand acres}, \] \[ \text{total: } [802,454,\ 1,031,400] \text{ thousand acres}, \] \[ \text{proportion: } 0.51 \pm 1.968(0.0275) = [0.456,\ 0.564], \] matching the output of srs_est() in Section 3.3.

3.4.2 How large must \(n\) be for normality?

The normal approximation needs a larger sample when the population is skewed, as acreage is. Sugden, Smith and Jones (2000) extend Cochran’s rule and recommend the minimum sample size \[ n_{\min} = 28 + 25\left(\frac{\sum_{i=1}^N (y_i-\bar y_{U})^3}{N S^3}\right)^{\!2}, \] where the quantity in parentheses is the skewness of the population. The more skewed the population, the larger the sample required.

Code
g1 <- (sum((sdata - ybar)^3) / n) / s^3   # sample skewness
n_min <- 28 + 25 * g1^2
c(skewness = g1, n_min = n_min)
  skewness      n_min 
  2.567866 192.848373 

For the agriculture data we substitute the sample quantities: \(s = 344.55\) and \(\sum_{i\in\mathcal S}(y_i-\bar y)^3/n = 1.0504 \times 10^{8}\) (in thousands of acres), giving a skewness of 2.57 and \[ n_{\min} = 28 + 25(2.568)^2 \approx 193 . \] Our sample of \(n=300\) exceeds \(n_{\min}\), so it appears large enough for the sampling distribution of \(\bar y\) to be approximately normal. The simulation in Section 3.7 confirms this.

3.5 Choosing the Sample Size

Before a survey is carried out we must decide how large the sample should be. The answer depends on how precise the estimate must be.

3.5.1 Specifying the tolerable error

The desired precision is often expressed in absolute terms, \[ P(|\bar y - \bar y_{U}| \le e) = 1-\alpha , \] where \(e\) is the margin of error. For many surveys of people that measure a proportion, \(e=0.03\) and \(\alpha=0.05\). Alternatively, precision can be specified in relative terms, which controls the CV: \[ P\left(\left|\frac{\bar y - \bar y_{U}}{\bar y_{U}}\right| \le r\right) = 1-\alpha, \qquad\text{that is,}\qquad e = r \, \bar y_{U} . \] For example, if \(\bar y_{U} \approx 180\) thousand and \(r=0.1\), then \(e=18\) thousand.

3.5.2 Solving for \(n\)

Using the normal approximation, the margin of error is \(z_{\alpha/2}\,\mathrm{SD}(\bar y)\), so we need \(n\) with \[ e = z_{\alpha/2}\sqrt{\Big(1-\frac nN\Big)\frac{S^2}{n}} . \] Solving in two steps is convenient. First find the sample size \(n_0\) we would need for an infinite population (no fpc): \[ n_0 = \left(\frac{z_{\alpha/2}\, S}{e}\right)^{\!2}. \] Then adjust for the finite population: \[ \boxed{n = \frac{n_0}{1+n_0/N} = \frac{z_{\alpha/2}^2 S^2}{e^2 + z_{\alpha/2}^2 S^2/N}.} \] When \(N\) is large relative to \(n_0\), \(n \approx n_0\); the population size matters only when \(n_0\) is a substantial fraction of \(N\). The formula needs a value for \(S\), which is unknown. It can come from a pilot sample, a previous survey of a similar population, or a guess. For a proportion, \(S^2 \approx p(1-p) \le 1/4\), so using \(p = 1/2\) gives a conservative (largest) sample size.

Code
srs_size <- function(S, e, N = Inf, alpha = 0.05) {
  n0 <- (qnorm(1 - alpha / 2) * S / e)^2
  c(n0 = n0, n = n0 / (1 + n0 / N))
}

Example: margin of error 0.03 for a proportion. We want to estimate the proportion of the \(N=1251\) recipes in a cookbook that do not involve animal products, with a 95% CI of margin of error 0.03. Using the conservative \(p = 1/2\), \[ n_0 = \frac{(1.96)^2 (\tfrac12)(1-\tfrac12)}{(0.03)^2} \approx 1067 . \] Since \(n_0\) is large relative to \(N=1251\), the fpc adjustment matters: \[ n = \frac{n_0}{1+n_0/N} = \frac{1067}{1+1067/1251} \approx 576 . \] If \(N\) were very large we would use \(n\approx n_0 = 1067\).

Code
srs_size(S = 0.5, e = 0.03, N = 1251)
       n0         n 
1067.0719  575.8695 

Example: the agriculture survey. A pilot sample of 30 counties was taken (one county was missing acres92). The sample SD of the remaining 29 observations was 519.085 thousand acres. With a desired margin of error of 60 thousand acres, \[ n_0 = (1.96)^2\,\frac{519.085^2}{60^2} \approx 288, \qquad n = \frac{288}{1+288/3078} \approx 263 . \] The investigators took a sample of 300, in case the pilot’s estimate of the SD was too low.

Code
srs_size(S = 519.085, e = 60, N = 3078)
      n0        n 
287.5217 262.9583 

3.6 Randomization Theory for SRS

We now prove the properties of \(\bar y\) and \(s^2\) used above. In the randomization theory (design-based) approach, the values \(y_1, \ldots, y_N\) are fixed but unknown numbers. The only random variables are the indicators \(Z_1, \ldots, Z_N\) that record which units are in the sample: \[ \bar y = \sum_{i\in\mathcal S} \frac{y_i}{n} = \sum_{i=1}^N Z_i \frac{y_i}{n} . \] All the randomness in \(\bar y\) comes from \(Z_1,\ldots,Z_N\).

3.6.1 Moments of \(Z_i\)

Each \(Z_i\) is a Bernoulli random variable with \(P(Z_i=1) = \pi_i = n/N\) (Section 3.1). Since \(Z_i^2 = Z_i\), \[ E[Z_i] = E[Z_i^2] = \frac nN, \qquad V(Z_i) = \frac nN - \Big(\frac nN\Big)^2 = \frac nN\Big(1-\frac nN\Big). \] The \(Z_i\) are not independent, because the sample size is fixed: if unit \(i\) is in the sample, there is one less place for the other units. For \(i\ne j\), given that unit \(i\) is sampled, the remaining \(n-1\) units are an SRS from the other \(N-1\), so \[ E[Z_iZ_j] = P(Z_j=1\mid Z_i=1)\,P(Z_i=1) = \frac{n-1}{N-1}\cdot\frac nN , \] \[ \mathrm{Cov}(Z_i,Z_j) = E[Z_iZ_j]-E[Z_i]E[Z_j] = \frac nN\Big(\frac{n-1}{N-1} - \frac nN\Big) = -\frac{1}{N-1}\Big(1-\frac nN\Big)\frac nN . \] This negative covariance is the source of the finite population correction.

3.6.2 Unbiasedness of \(\bar y\)

By linearity of expectation, \[ E[\bar y] = \sum_{i=1}^N E[Z_i]\frac{y_i}{n} = \sum_{i=1}^N \frac{n}{N}\cdot\frac{y_i}{n} = \frac1N \sum_{i=1}^N y_i = \bar y_{U}. \] So \(\bar y\) is an unbiased estimator of \(\bar y_{U}\), and \(\hat t = N\bar y\) is unbiased for \(t\).

3.6.3 Variance of \(\bar y\)

Expanding the variance of a sum, \[ \begin{aligned} V(\bar y) &= \frac{1}{n^2}\left[\sum_{i=1}^N y_i^2\, V(Z_i) + \sum_{i=1}^N\sum_{j\ne i} y_i y_j\,\mathrm{Cov}(Z_i,Z_j)\right] \\ &= \frac{1}{n^2}\,\frac nN\Big(1-\frac nN\Big)\left[\sum_{i=1}^N y_i^2 - \frac{1}{N-1}\sum_{i=1}^N\sum_{j\ne i} y_i y_j\right]. \end{aligned} \] Using \(\sum_i\sum_{j\ne i} y_iy_j = \big(\sum_i y_i\big)^2 - \sum_i y_i^2\), the term in brackets is \[ \frac{N\sum_{i} y_i^2 - \big(\sum_{i} y_i\big)^2}{N-1} = \frac{N\sum_i (y_i - \bar y_U)^2}{N-1} = N S^2 . \] Therefore \[ V(\bar y) = \frac{1}{n^2}\,\frac nN\Big(1-\frac nN\Big) N S^2 = \Big(1-\frac nN\Big)\frac{S^2}{n}. \] Without the negative covariances, the result would be \(\frac{N-1}{N}\cdot\frac{S^2}{n}\) (the SRSWR variance). The covariance terms produce the factor \(1 - n/N\).

3.6.4 Unbiasedness of \(s^2\)

Adding and subtracting \(\bar y_U\) inside the sum of squares gives the identity \[ \sum_{i\in\mathcal S}(y_i-\bar y)^2 = \sum_{i\in\mathcal S}(y_i-\bar y_{U})^2 - n(\bar y - \bar y_U)^2 . \] Take expectations. For the first term, \(E\big[\sum_{i=1}^N Z_i(y_i-\bar y_U)^2\big] = \frac nN (N-1)S^2\); for the second, \(E[n(\bar y - \bar y_U)^2] = nV(\bar y) = (1-\frac nN)S^2\). Hence \[ E\left[\sum_{i\in\mathcal S}(y_i-\bar y)^2\right] = \frac{n(N-1)}{N}S^2 - \frac{N-n}{N}S^2 = (n-1)S^2 , \] and therefore \(E[s^2] = S^2\). It follows that \(\hat V(\bar y) = (1-\frac nN)\frac{s^2}{n}\) is unbiased for \(V(\bar y)\). (The standard error, its square root, is slightly biased, as a square root always is, but this is ignored in practice.)

3.7 A Simulation Demonstration of SRS Inference

The theory says that \(\bar y\) is unbiased, that its standard deviation is \(\sqrt{1-n/N}\,S/\sqrt n\), that it is approximately normal for \(n = 300\), and that the 95% CIs cover \(\bar y_U\) about 95% of the time. Because agpop.csv contains the whole population, we can check all four claims by drawing many samples from it.

Code
# read population data, with acreages in thousands of acres
agpop <- acres_in_thousands (read.csv ("data/agpop.csv"))
# remove those counties with na
agpop <- subset( agpop, !is.na (acres92))

3.7.1 True values

We fix the sample size and compute the true population mean and the true standard deviation of \(\bar y\) from the population \(S\): \[ \mathrm{SD}(\bar{y}) = \sqrt{1 - \frac{n}{N}} \left(\frac{S}{\sqrt{n}}\right). \]

Code
# sample size
n <- 300
# population size
N <- nrow (agpop); N
[1] 3059
Code
# true value of population mean
ybarU <- mean (agpop[,"acres92"]); ybarU
[1] 308.5824
Code
# true value of deviation of sample mean
true.se.ybar <- sqrt (1- n/N) * sd (agpop[,"acres92"]) / sqrt (n); true.se.ybar
[1] 23.32029

3.7.2 One SRS

A single random sample of \(n=300\), analyzed with srs_est(), is one instance of survey inference:

Code
# srs sampling
srs <- sample (1:N,n)
head(agpop [srs, ])
Code
# get data of variable "acres92"
sdata <- agpop [srs, "acres92"]
# analysis
res_one <- srs_est(sdata, N, estimate = "mean", show.details = FALSE)
res_one$estimate |> format_est_gt("mean")
\(\bar{y}\) \(\mathrm{SE}(\bar{y})\) 95% CI Lower 95% CI Upper
302.63 18.38 266.46 338.79

3.7.3 Repeating SRS 5000 times

We now draw 5000 independent samples and store the estimates from each. (We use show.details = FALSE and keep only $estimate, so the loop skips building 5000 working tables.)

Code
nres <- 5000 # number of repeated sampling
simulation.results <- matrix (0, nres, 4) # matrix recording repeated results
colnames(simulation.results) <- c( "Est.",   "S.E.",   "ci.low", "ci.upp")

for (i in 1:nres)
{
    srs <- sample (N, n)
   sdata <- agpop [srs, "acres92"]
   simulation.results [i,] <- srs_est (sdata, N, estimate = "mean", show.details = FALSE)$estimate
}

head(simulation.results)
         Est.     S.E.   ci.low   ci.upp
[1,] 266.4408 19.12183 228.8104 304.0712
[2,] 350.9636 34.73818 282.6013 419.3259
[3,] 311.9485 20.59931 271.4105 352.4865
[4,] 307.8111 23.35216 261.8557 353.7665
[5,] 338.9564 27.27598 285.2792 392.6336
[6,] 278.5276 24.80710 229.7090 327.3463
Code
# look at the distribution of sample mean
par (mfrow= c(2,2))
dens_pop <- density (agpop$acres92, from = 0)
hist (agpop$acres92, breaks = 50, freq = FALSE, col = "lightblue", border = "white",
      ylim = c(0, max (dens_pop$y)),
      main = "Population of acres92", xlab = "acres92")
lines (dens_pop, col = "blue", lwd = 2)
hist (simulation.results[,1], breaks = 40, freq = FALSE, col = "lightblue", border = "white",
      main = "Sample means of acres92", xlab = "sample mean")
lines (density (simulation.results[,1]), col = "blue", lwd = 2)
curve (dnorm (x, mean = ybarU, sd = true.se.ybar), add = TRUE, col = "red", lwd = 2, lty = 2)
abline (v = ybarU, col = "red")
legend ("topright", bty = "n", lwd = 2, lty = c(1, 2), col = c("blue", "red"), cex = 0.8,
        legend = c("kernel density", "normal (theory)"))
qqnorm (simulation.results[,1], main="QQ plot of Sample Mean"); qqline(simulation.results[,1])
boxplot (simulation.results[,1], main = "Boxplot of Sample Mean")
abline (h = ybarU, col = "red")

mean (simulation.results[,1])
[1] 308.9626
Code
ybarU
[1] 308.5824
Code
sd (simulation.results [,1])
[1] 23.26756
Code
true.se.ybar
[1] 23.32029
Figure 3.3: Population distribution and sampling distribution of the SRS sample mean over 5000 repeated samples (n = 300)

The blue curves are kernel density estimates. The population density (top left) is strongly skewed to the right, with a long tail of very large counties. The kernel density of the 5000 sample means (top right) is nearly symmetric and almost coincides with the normal density \(N\big(\bar y_U,\ \mathrm{SD}(\bar y)^2\big)\) predicted by the theory (red dashed curve); the QQ plot (bottom left) is close to a straight line, with only a slight bend in the upper tail left over from the skewness. So the sampling distribution of \(\bar y\) is close to normal, as Hájek’s theorem and the \(n_{\min}\) check of Section 3.4 suggest. The average of the 5000 estimates, 308.96, is close to \(\bar y_U = 308.58\) (unbiasedness), and their standard deviation, 23.27, is close to the theoretical value 23.32.

3.7.4 Empirical coverage rate of CIs

Finally we check whether the 95% CIs cover the true mean about 95% of the time.

Code
library(plotrix)

# Convert to data frame (if it was a matrix) and use mutate to evaluate coverage
simulation.results <- as.data.frame(simulation.results) |>
  mutate(
    `Covered?` = as.numeric(ci.low < ybarU & ybarU < ci.upp)
  )

head(simulation.results)
Code
par(mfrow=c(1,1))
plotCI(
  x = 1:100,
  y = simulation.results$Est.[1:100],
  li = simulation.results$ci.low[1:100],
  ui = simulation.results$ci.upp[1:100],
  col = 2 - simulation.results$`Covered?`[1:100]
)
abline(h = ybarU, col = "blue")

# Empirical coverage rate
mean(simulation.results$`Covered?`)
[1] 0.9372
Figure 3.4: First 100 simulated 95% confidence intervals for the SRS sample mean, with coverage failures highlighted

The empirical coverage rate is 0.937, close to the nominal 0.95. (With a skewed population the coverage of the \(t\) interval tends to fall slightly short of nominal.) The intervals that miss (in red) are exactly the “5% of samples” in the heuristic interpretation of Section 3.4.

3.8 Shinylive App for Illustrating SRS Theory

The simulation for this section runs as a standalone app: Simple random sampling. It draws samples one at a time and builds up the sampling distribution and the coverage rate interactively, for any sample size and confidence level. It opens in a new tab, together with its documentation and the full list of apps.