You Try Answers: Sampling

POSC 8410

Author

Will Horne

Published

October 26, 2026

library(tidyverse)
# In your own class folder this path is just "Data/anes.csv"
anes <- read_csv("../Slides/Data/anes.csv", show_col_types = FALSE)

You Try

A note before starting: this exercise involves random draws, so your numbers will differ from mine. That is the point of the exercise. I use set.seed(8410) so that this document gives the same numbers every time it is rendered. If you run the same seed and the same code in the same order, you will match me exactly.

1. Using the anes, treat ft_science as a population, built the way we built pop. Compute the true mean. Then draw one sample of 40 and compare.

In class we built pop by dropping missing values and pulling out the single column as a vector. Same idea here:

set.seed(8410)
pop_s <- anes |> filter(!is.na(ft_science)) |> pull(ft_science)

length(pop_s)          # N, the population size
[1] 7367
mean(pop_s)            # mu, the true mean
[1] 79.31383
one_s <- sample(pop_s, 40)
mean(one_s)            # x-bar from one sample of 40
[1] 80.375

Our population has 7,367 people and a true mean of 79.31. My one sample of 40 gave 80.38, missing by 1.1 points. Yours will miss by a different amount. Remember the distinction from class: \(\mu\) is a fixed parameter, and \(\bar{x}\) is a statistic that changes with every sample.

2. Use replicate, as we did for sdist, to draw 2,000 samples of 40. What is the mean of those sample means? What is their standard deviation?

replicate(2000, ...) runs the code inside it 2,000 times and collects the results. Each run draws 40 people and keeps their mean:

d40 <- replicate(2000, mean(sample(pop_s, 40)))

c(mean_of_means = mean(d40),
  sd_of_means   = sd(d40))
mean_of_means   sd_of_means 
    79.308612      3.179139 

d40 is a simulated sampling distribution: 2,000 values of \(\bar{X}\).

  • The mean of the sample means is 79.309, against a true mean of 79.314. Individual samples miss in both directions, but center on the truth. This is what it means for \(\bar{X}\) to be unbiased, \(E[\bar{X}] = \mu\). (The two are not exactly equal because 2,000 replications is a lot, but unbiasedness is a property that holds with an infinite number of draws.)
  • The standard deviation of the sample means is 3.18. This is the standard error: how far a typical sample mean lands from the truth.

3. Check it against \(\sigma/\sqrt{n}\). Then repeat with \(n = 160\). Did the standard error halve?

\(\sigma\) is the population standard deviation, which we can compute here because we have the whole population:

d160 <- replicate(2000, mean(sample(pop_s, 160)))

tibble(n            = c(40, 160),
       simulated_SE = c(sd(d40), sd(d160)),
       formula_SE   = sd(pop_s) / sqrt(n))
# A tibble: 2 × 3
      n simulated_SE formula_SE
  <dbl>        <dbl>      <dbl>
1    40         3.18       3.19
2   160         1.58       1.59
sd(d160) / sd(d40)     # ratio of the two simulated SEs
[1] 0.4977057

The simulation and the formula agree closely at both sample sizes. They differ only by simulation noise, since each simulated SE is itself estimated from 2,000 draws.

And yes, the standard error halved (the ratio is 0.50, essentially one half). Going from 40 to 160 multiplies \(n\) by 4, which multiplies \(\sqrt{n}\) by 2, which divides \(\sigma/\sqrt{n}\) by 2. This is the same result we derived earlier for the survey of 400 versus 1,600.

The lesson is that precision is expensive. Cutting your uncertainty in half costs four times the data, and cutting it to a tenth costs a hundred times the data.

Two technical notes:

  • sd() divides by \(N - 1\), while the true population SD divides by \(N\). With \(N\) = 7,367, the difference is far too small to matter.
  • sample() draws without replacement, so the exact formula includes the finite population correction from class. With \(n = 160\) out of 7,367, that correction is 0.978, essentially 1.

4. A pollster surveys 50,000 people through a website banner ad. Which of today’s problems does the large \(n\) solve, and which does it not?

The large \(n\) solves one problem:

  • Sampling variability. For a proportion near 50%, the standard error is \(\sqrt{0.5 \times 0.5 / 50{,}000}\), about 0.22 percentage points. The estimate will be extremely precise.

It does nothing about the others, all of which are bias:

  • Coverage. The people who could possibly see the ad are visitors to that website, not the population. If the site’s audience is younger, more partisan, or more online than the public, so is the sample, however large it gets.
  • Self-selection (nonresponse). Of the people who see the banner, the ones who click are not a cross-section. People with strong opinions, or free time, are more likely to respond. This is the Literary Digest problem.
  • Measurement. Question wording, social desirability, and the fact that people overreport behavior like voting are all unaffected by \(n\).