One Proportion • Margin of Error•Two Proportions • Sample Sizes
Welcome to the home stretch! We aren't learning fundamentally "new" math theories anymore. Instead, we are executing what we know (Hypothesis Tests & CIs) for different scenarios using RStudio as our primary tool.
This phase of the course directly ties into your Final Project! The tools you learn here(prop.test, chisq.test, linear models) are the exact techniques you will use in RStudio to extract meaning from your chosen datasets.
Focus heavily on interpreting outputs and checking assumptions.
Consider a population where each member either has or does not have a specified attribute (e.g., "voted", "defective").
$x = \text{successes}$, $n= \text{sample size}$
Change the number of "successes" ($x$) out of$n=25$.
As part of an independent quality control audit, a regional consumer advocacy group receives multiple formal complaints regarding the 'Ultra-Glow'smart LED system. The packaging advertises that their custom filaments endure a baseline operational lifespan averaging 15,000 hours. Suspecting deceptive marketing practices, the audit team secures a random sample of $n=50$ retail units, runs them under standard laboratory conditions to failure, and analyzes the data to determine if they should file a false advertising claim against the manufacturer for delivering a fundamentally inferior product.
Following a contentious municipal debate regarding the reallocation of public infrastructure funding, historically established polls from a prior cycle indicated that exactly 48% of registered district voters supported the overarching tax overhaul.Given a recent influx of contradictory socio-economic editorials and massive neighborhood campaigning, an independent civic databank is commissioned to randomly sample 1,200 active municipal residents. Their primary directive is to definitively ascertain whether the community's fundamental stance on the proposal has systematically shifted in any direction since the benchmark was established.
A global biotechnology firm has recently rushed a proprietary antiviral compound through phase II clinical trials, issuing a press release that establishes a baseline efficacy benchmark of an exact 90% clearance rate across standard viral loads. Suspicious of the in-house testing methodology, a coalition of competing university virologists randomly synthesize the identical compound and administer it to a double-blind sample of severe symptomatic profiles. The university team is attempting to establish statistically significant clinical proof that the corporation's highly touted baseline clearance rate is a drastic underestimation of the drug's true therapeutic dominance.
How large a sample do we need to estimate a population proportion within a chosen margin of error $E$?
If we have no prior idea what $p$ might be, we assume the worst-case scenario ($p = 0.5$) to ensure the sample is large enough:
Always round UP to the nearest whole number.
If we have a prior estimate $\hat{p}_g$ (e.g., from a past study):
Always round UP to the nearest whole number.
Compute the observed test statistic $z_0$:
(Notice it is just [Observed - Null] / SE!)
Use the normal table to find P-value/CV, then conclude.
The Scenario: A popular streaming service wants to evaluate mobile app usage. The marketing team publishes a bold claim stating that more than 55% of all current subscribers primarily use the mobile app to watch content. To investigate this internally, a data analyst takes a random sample of 850 active subscribers and finds that precisely 510 of them use the mobile app. At the $\alpha = 0.05$ significance level, does the data support the marketing team's claim?
$2.93 > 1.645$ (CV) $\rightarrow$ Reject $H_0$
There is sufficient evidence to support the claim.
Change the number of "Successes" out of 50 trials.
Under $H_0: p_1 = p_2$, we assume both come from the same true proportion. So we just combine all the categorical dots into one big bucket!
For independent samples we take from each population (sizes $n_1$ and$n_2$):
Because $H_0$ states $p_1 = p_2$, we pool the samples to estimate the common proportion:
Test Statistic:
To estimate the difference $(p_1 - p_2)$ with confidence level $1-\alpha$:
R handles proportion tests easily using `prop.test()` and estimating confidence intervals at the same time.
# --- ONE POPULATION PROPORTION ---
# x: number of successes, n: sample size, p: null proportion
# correct = FALSE turns off continuity correction (matches textbook z-test)
prop.test(x = 42, n = 100, p = 0.50, alternative = "greater", conf.level = 0.95, correct = FALSE)
# --- TWO POPULATION PROPORTIONS ---
# Supply successes as a vector: c(x1, x2)
# Supply sample sizes as a vector: c(n1, n2)
successes <- c(45, 30)
trials <- c(100, 80)
# Two-tailed test comparing p1 and p2
prop.test(x = successes, n = trials, alternative = "two.sided", conf.level = 0.95, correct = FALSE)10 Minute Challenge:
A poll asked whether states should be allowed to conduct random drug tests on elected officials. Of 16,195 respondents, 65% said "yes".
a. Determine the margin of error for a 99% confidence interval.
b. Without doing any calculations, indicate whether the margin of error is larger or smaller for a 90% confidence interval. Explain your answer.
Part (a):
$n = 16,195 \quad \hat{p} = 0.65$
For 99% confidence, $z_{\alpha/2} = 2.576$
$E = z_{\alpha/2} \cdot \sqrt{\frac{\hat{p}(1-\hat{p})}{n}} = 2.576 \cdot\sqrt{\frac{0.65(0.35)}{16195}} \approx \mathbf{0.0097}$ (or $0.97\%$)
Part (b):
The margin of error for a 90% confidence interval would be smaller. To have a lower level of overall confidence, you do not need as wide of an interval to capture the true population proportion. (Mathematically, $z_{\alpha/2}$ for 90% is only $1.645$, which shrinks the margin compared to multiplying by $2.576$).
10 Minute Challenge:
For a margin of error of 0.04, a 95% confidence level, and an educated guess of 0.4 for the sample proportion,obtain a sample size that will ensure a margin of error of at most the one specified.
$E = 0.04 \quad \hat{p}_g = 0.4 \quad z_{\alpha/2} = 1.96$ (for 95%)
$n = \hat{p}_g(1-\hat{p}_g) \left(\frac{z_{\alpha/2}}{E}\right)^2 = 0.4(0.6)\left(\frac{1.96}{0.04}\right)^2$
$n = 0.24 \cdot (49)^2 = 0.24 \cdot 2401 = 576.24$
Always round up! $n = \mathbf{577}$
10 Minute Challenge:
Perform a hypothesis test for $x=35$, $n=50$, $H_0: p=0.6$, $H_a: p < 0.6$, and $\alpha=0.05$.
a. Determine the sample proportion.
b. Decide if the one-proportion z-test is appropriate.
c. If appropriate, determine the test statistic, critical value(s), and conclusion.
Part (a): $\hat{p} = \frac{x}{n} = \frac{35}{50} = \mathbf{0.70}$
Part (b): We must verify the assumptions ($np_0 \ge 5$ and $n(1-p_0) \ge 5$).
$50(0.6) = 30 \ge 5$ and $50(0.4) = 20 \ge 5$. It is **appropriate**.
Part (c): The test statistic is calculated as $z = \frac{0.70 -0.60}{\sqrt{0.60 \cdot 0.40 / 50}} = \mathbf{1.44}$.
Wait! Look carefully: The alternative hypothesis claimed $p < 0.6$. The sample proportion$0.70$ directly contradicts the claim immediately. The left-tailed P-value is very large($0.925$).
$0.925 \not\leq 0.05 \rightarrow \mathbf{\text{Do Not Reject } H_0}$.
10 Minute Challenge:
For independent samples $x_1=21$, $n_1=40$ and $x_2=25$, $n_2=30$ with $\alpha=0.10$:
a. Determine sample proportions $\hat{p}_1, \hat{p}_2,$ and pooled proportion$\hat{p}_p$.
b. Decide if two-proportions z-procedures are appropriate.
Part (a):
$\hat{p}_1 = \frac{x_1}{n_1} = \frac{21}{40} = \mathbf{0.525}$
$\hat{p}_2 = \frac{x_2}{n_2} = \frac{25}{30} \approx \mathbf{0.833}$
Pooled: $\hat{p}_p = \frac{x_1 + x_2}{n_1 + n_2} = \frac{21+25}{40+30} = \frac{46}{70}\approx \mathbf{0.657}$
Part (b):
Check if all successes and failures are $\ge 5$:
$x_1=21$, $n_1-x_1=19$; $x_2=25$, $n_2-x_2=5$.
They are all exactly 5 or greater, so it is appropriate to use the z-procedures.
10 Minute Challenge:
Using the identical dataset mapping to the previous question ($x_1=21$, $n_1=40$, $x_2=25$, $n_2=30$,$\alpha=0.10$):
c. Conduct a left-tailed hypothesis test (find the test statistic, critical value, and conclusion).
d. Find an 80% confidence interval for $p_1 - p_2$.
Part (c):
$z_0 = \frac{\hat{p}_1 - \hat{p}_2}{\sqrt{\hat{p}_p(1-\hat{p}_p)}\sqrt{1/n_1 + 1/n_2}} =\frac{0.525 - 0.833}{\sqrt{0.657(0.343)}\sqrt{\frac{1}{40} + \frac{1}{30}}} \approx\mathbf{-2.69}$
Critical Value for $\alpha=0.10$ left-tailed is $z = \mathbf{-1.28}$.
$-2.69 \le -1.28$, so we $\mathbf{Reject H_0}$.
Part (d):
$CI = (\hat{p}_1 - \hat{p}_2) \pm z_{\alpha/2} \cdot\sqrt{\frac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \frac{\hat{p}_2(1-\hat{p}_2)}{n_2}}$
Wait, $z_{\alpha/2}$ for 80% CI is $1.28$.
$E = 1.28 \cdot \sqrt{\frac{0.525(0.475)}{40} + \frac{0.833(0.167)}{30}} = 1.28 \cdot\sqrt{0.00623 + 0.00463} = 1.28 \cdot 0.1042 = \mathbf{0.133}$
$CI: -0.308 \pm 0.133 \rightarrow (\mathbf{-0.441, -0.175})$