MODULE 1210 QUESTIONS

Inference for Proportions

ADAPTIVE FLASHCARDS
Flashcard Study Mode
Study this module with spaced repetition. Wrong answers come back weighted heavier.

Inference for Proportions

From Means to Proportions

The previous module covered inference for a continuous mean. Now we handle proportions -- when the response variable is binary (yes/no, success/failure, heads/tails).

  • Population proportion: p -- the true fraction of the population with the characteristic
  • Sample proportion: p̂ = (number of successes) / n

The logic is the same as for means: use p̂ to estimate p, quantify uncertainty with a confidence interval, and test claims with a hypothesis test.

When to use proportion inference: When your response variable is categorical and binary. "What fraction of UW students prefer R over Python?" is a proportion question. "What is the average GPA of UW students?" is a mean question.

Sampling Distribution of p̂

By the Central Limit Theorem, for large n:

p̂ ≈ N( p, p(1-p)/n )
SE(p̂) = sqrt( p(1-p) / n )

Conditions for this to hold:

  • np >= 10 (at least 10 expected successes)
  • n(1-p) >= 10 (at least 10 expected failures)

Why these conditions? The normal approximation breaks down when the distribution is too skewed. If p = 0.01 and n = 50, you'd expect 0.5 successes -- the distribution can't look bell-shaped there.

Confidence Interval for p

p̂ ± z* × sqrt( p̂(1-p̂) / n )

Note: we use z (not t) because we're using the normal approximation and SE is fully determined by p̂.

R
1# 43 successes out of 100 trials
2prop.test(x = 43, n = 100)

Reading prop.test output: Our estimate is p̂ = 0.43, and we're 95% confident the true proportion is between 0.333 and 0.531. Since 0.5 is inside the interval, we don't have evidence to reject p = 0.5.

Hypothesis Test for p

To test a specific claim H₀: p = p₀:

z = (p̂ - p₀) / sqrt( p₀(1-p₀) / n )

Notice: we use p₀ (the null value) in the denominator, not p̂. Under H0, we assume p = p₀ is true.

R
1# Test if proportion equals 0.5
2prop.test(x = 43, n = 100, p = 0.5)
3
4# One-sided test: Ha: p < 0.5
5prop.test(x = 43, n = 100, p = 0.5, alternative = "less")

Sample Size Planning

Before collecting data, how large a sample do you need for your desired margin of error m?

Using p = 0.5 (the most conservative choice -- maximizes variance):

n = (z* / (2m))^2
R
1# 95% CI with margin of error <= 0.03
2z_star <- qnorm(0.975) # 1.96
3m <- 0.03
4n_needed <- (z_star / (2 * m))^2
5ceiling(n_needed) # round up

Why p = 0.5 is conservative: p(1-p) is maximized at p = 0.5, giving p(1-p) = 0.25. Using this gives you the largest sample size, ensuring your interval will be narrow enough no matter what p turns out to be.

Testing Proportions with prop.test()

Two-sided test:

R
1prop.test(x = 60, n = 90, p = 0.5)

One-sided test:

R
1prop.test(x = 60, n = 90, p = 0.5, alternative = "greater")

Output gives the 95% CI and p-value.

Simulation: Building a Sampling Distribution

To test a proportion using simulation:

R
1# Assuming H0: p = 0.6, generate sampling distribution
2n_sims <- 10000
3n <- 90
4p_null <- 0.6
5
6# Simulate B samples of size n, each with success probability p
7x_star <- rbinom(n_sims, size = n, prob = p_null)
8p_hat <- x_star / n
9
10# Our observed p-hat = 60/90 ≈ 0.667
11# P-value = proportion of simulations as extreme as 0.667
12obs_p_hat <- 60 / 90
13p_value <- mean(p_hat >= obs_p_hat | p_hat <= 1 - obs_p_hat)
14p_value

This gives you the empirical p-value from the simulation.

Conditions for Normal Approximation

For the normal approximation to p̂ to be valid:

np >= 10 AND n(1-p) >= 10

If either condition fails, use exact binomial methods or simulation instead.

Chimpanzee Example -- Full Analysis

Setup: Chimp A made prosocial choices (helping a partner) 60 out of 90 trials.

Hypotheses:

  • H₀: p = 0.5 (choosing randomly)
  • Hₐ: p > 0.5 (genuinely prosocial)

Check conditions: np0 = 90 x 0.5 = 45 ✓, n(1-p₀) = 45 ✓ (both >= 10)

R
1prop.test(x = 60, n = 90, p = 0.5, alternative = "greater")

Interpretation: p̂ = 0.667. p-value ≈ 0.0008 < 0.05 -> reject H0. Strong evidence that Chimp A makes prosocial choices at above-chance rates.

CI for a Proportion -- Step by Step

For x successes out of n trials:

1. p̂ = x/n

2. SE = sqrt(p̂(1-p̂)/n)

3. z* = 1.96 (for 95% confidence)

4. CI: p̂ +/- z* x SE

Example: x=60, n=90

R
1# Manual calculation
2p_hat <- 60/90 # 0.667
3SE <- sqrt(p_hat * (1 - p_hat) / 90) # 0.0497
4z_star <- 1.96
5lower <- p_hat - z_star * SE # 0.570
6upper <- p_hat + z_star * SE # 0.764
7
8# Or use R:
9prop.test(x = 60, n = 90)

95% CI: (0.570, 0.764)

Two-Sample Proportion Inference

When comparing proportions between two groups, we conduct inference on the difference p1 - p2.

Confidence Interval for Difference in Proportions

Point estimate:

p̂₁ - p̂₂

Standard Error (using individual proportions, NOT pooled):

SE = sqrt( p̂₁(1-p̂₁)/n₁ + p̂₂(1-p̂₂)/n₂ )

Confidence interval:

(p̂₁ - p̂₂) ± z* × SE

Example: Chimp A with vs without partner

  • With partner: 60 successes out of 90 trials -> p̂₁ = 0.667
  • Without partner: 16 successes out of 30 trials -> p̂₂ = 0.533
R
1# Manual calculation
2p_hat1 <- 60/90
3p_hat2 <- 16/30
4difference <- p_hat1 - p_hat2 # 0.134
5
6SE <- sqrt((p_hat1*(1-p_hat1)/90) + (p_hat2*(1-p_hat2)/30))
7z_star <- 1.96
8
9lower <- difference - z_star * SE
10upper <- difference + z_star * SE
11cat("95% CI for (p1 - p2):", lower, "to", upper)

95% CI: approximately (-0.051, 0.319)

Interpretation: The CI includes 0, so we have no strong evidence that the proportions differ significantly between the two conditions.

Hypothesis Test for Two Proportions

To test H₀: p1 = p2, we use a pooled proportion in the standard error:

Pooled proportion:

p-pool = (x1 + x2) / (n₁ + n2)

Standard Error (pooled for hypothesis test):

SE_pool = sqrt( p-pool(1-p-pool) × (1/n₁ + 1/n₂) )

Test statistic:

z = (p̂₁ - p̂₂) / SE_pool

Key difference: For the CI we use individual proportions in SE. For the hypothesis test we use the pooled proportion.

Example: Comparing chimp's prosocial choices with vs without partner

R
1# Two-proportion hypothesis test
2prop.test(x = c(60, 16), n = c(90, 30))

Manual calculation:

R
1p_hat1 <- 60/90
2p_hat2 <- 16/30
3p_pool <- (60 + 16) / (90 + 30) # 0.633
4
5SE_pool <- sqrt(p_pool * (1 - p_pool) * (1/90 + 1/30))
6z <- (p_hat1 - p_hat2) / SE_pool
7p_value <- 2 * (1 - pnorm(abs(z))) # two-sided

Interpretation: p-value = 0.246 > 0.05, so we fail to reject H0. There is no significant evidence that Chimp A's prosocial choice rates differ between the with-partner and without-partner conditions.

Key Point: Why Different SE for CI vs Test?

For confidence intervals: We use p̂₁ and p̂₂ (observed proportions) to reflect the uncertainty in each sample.

For hypothesis tests: We assume H0 is true (p1 = p2 = p-pool), so we use the pooled proportion in the SE.

Two-Proportion Inference Checklist

1. State hypotheses: H₀: p1 = p2 vs Hₐ: p1 != p2 (or > or <)

2. Check conditions: n₁ x p₀ >= 10, n₁ x (1-p₀) >= 10, and similarly for group 2

3. For CI: Use individual proportions in SE

4. For hypothesis test: Use pooled proportion in SE

5. Interpretation: If CI for (p1-p2) contains 0, no significant difference

Exam Checklist for Proportion Tests

1. State hypotheses: H₀: p = p₀ vs Hₐ: p != p₀ (or > or <)

2. Check conditions: np0 >= 10 AND n(1-p₀) >= 10

3. Compute test statistic: z = (p̂ - p₀) / sqrt(p₀(1-p₀)/n)

4. Get p-value: Use prop.test() or pnorm()

5. Conclude: Compare p-value to alpha, state conclusion in context