In the last module, we reviewed statistical inference for one sample.
In this module, we will focus on tests for two samples.
In this lecture: two-sample proportions (\pi_1-\pi_2)
R SetupMeadowbrook and Coldharbor, each with 60 officers who just went through recertification.| precinct | taser_recert | firearms_requal |
|---|---|---|
| Meadowbrook | Fail | Fail |
| Meadowbrook | Fail | Fail |
| Meadowbrook | Pass | Fail |
(\hat{p}_1 - \hat{p}_2) \pm z_{\alpha/2} \sqrt{\dfrac{\hat{p}_1(1-\hat{p}_1)}{n_1} + \dfrac{\hat{p}_2(1-\hat{p}_2)}{n_2}}
Two-Tailed
H_0: \ \pi_1-\pi_2=\pi_0
H_1: \ \pi_1-\pi_2 \ne \pi_0
Left-Tailed
H_0: \ \pi_1-\pi_2 \ge \pi_0
H_1: \ \pi_1-\pi_2 < \pi_0
Right-Tailed
H_0: \ \pi_1-\pi_2 \le \pi_0
H_1: \ \pi_1-\pi_2 > \pi_0
\pi_i is the population proportion for group i
\pi_0 is the hypothesized value of the difference in proportions (often 0, for “no change”).
z_0 = \frac{\left( \hat{p}_1 - \hat{p}_2 \right)- d_0}{\sqrt{\hat{p}\left(1-\hat{p}\right)\left( \frac{1}{n_1}+\frac{1}{n_2} \right)}}
z_0 = \frac{\left( \hat{p}_1 - \hat{p}_2 \right)- d_0}{\sqrt{\hat{p}\left(1-\hat{p}\right)\left( \frac{1}{n_1}+\frac{1}{n_2} \right)}}
\hat{p} = \frac{x_1+x_2}{n_1+n_2}
R)We will use the independent_proportions() function from library(ssstats) to perform statistical inference.
Generic syntax:
dataset_name |> independent_proportions(outcome = binary_variable,
grouping = grouping_variable,
event = "Name of Event",
p = hypothesized_value,
alternative = "two" | "less" | "greater",
alpha = specified_alpha)binary_variable that counts as a “success” — this defines what your proportions are proportions of.
0.
"two"
0.05.
Meadowbrook and Coldharbor just finished the same taser recertification course, same instructors, same exam. Deputy Chief Okonkwo wants to verify that Meadowbrook and Coldharbor recertification rates look the same.
We will use the zootopia dataset to answer the following question:
We’ll work with taser_recert and precinct.
Independent proportions
p̂[Coldharbor] = 0.65
p̂[Meadowbrook] = 0.7
Point estimate: p̂[Coldharbor] − p̂[Meadowbrook] = -0.05
95% CI for π[Coldharbor] − π[Meadowbrook]: (-0.2174, 0.1174)
Hypotheses:
H₀: π[Coldharbor] − π[Meadowbrook] = 0
H₁: π[Coldharbor] − π[Meadowbrook] ≠ 0
Test statistic: z = -0.58
p-value: 0.559
Conclusion: Fail to reject the null hypothesis (p = 0.559 ≥ α = 0.050)
Does the taser recertification pass rate differ between Meadowbrook and Coldharbor?
How do we translate this into hypotheses?
Hypotheses:
For the independent_proportion() function, we will set
p = 0alternative = "two".Independent proportions
p̂[Coldharbor] = 0.65
p̂[Meadowbrook] = 0.7
Point estimate: p̂[Coldharbor] − p̂[Meadowbrook] = -0.05
95% CI for π[Coldharbor] − π[Meadowbrook]: (-0.2174, 0.1174)
Hypotheses:
H₀: π[Coldharbor] − π[Meadowbrook] = 0
H₁: π[Coldharbor] − π[Meadowbrook] ≠ 0
Test statistic: z = -0.58
p-value: 0.559
Conclusion: Fail to reject the null hypothesis (p = 0.559 ≥ α = 0.050)
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
Coldharbor got a new firearms range last year… the one Meadowbrook’s been asking for forever. If it’s actually helping, Coldharbor’s requalification numbers should be better. Let’s see if the budget was worth it.
We will use the zootopia dataset to answer the following question:
We’ll work with firearms_requal and precinct.
Independent proportions
p̂[Coldharbor] = 0.8333
p̂[Meadowbrook] = 0.6667
Point estimate: p̂[Coldharbor] − p̂[Meadowbrook] = 0.1667
95% CI for π[Coldharbor] − π[Meadowbrook]: (0.0146, 0.3187)
Hypotheses:
H₀: π[Coldharbor] − π[Meadowbrook] = 0
H₁: π[Coldharbor] − π[Meadowbrook] ≠ 0
Test statistic: z = 2.11
p-value: 0.035
Conclusion: Reject the null hypothesis (p = 0.035 < α = 0.050)
Does Coldharbor have a higher firearms requalification pass rate than Meadowbrook?
How do we translate this into hypotheses?
Hypotheses:
For the independent_proportion() function, we will set
p = 0alternative = "greater".zootopia |> independent_proportions(outcome = firearms_requal,
grouping = precinct,
event = "Pass",
alternative = "greater")Independent proportions
p̂[Coldharbor] = 0.8333
p̂[Meadowbrook] = 0.6667
Point estimate: p̂[Coldharbor] − p̂[Meadowbrook] = 0.1667
95% CI for π[Coldharbor] − π[Meadowbrook]: (0.0146, 0.3187)
Hypotheses:
H₀: π[Coldharbor] − π[Meadowbrook] ≤ 0
H₁: π[Coldharbor] − π[Meadowbrook] > 0
Test statistic: z = 2.11
p-value: 0.018
Conclusion: Reject the null hypothesis (p = 0.018 < α = 0.050)
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
Independent (two-sample) proportion data comes from two separate, unrelated groups.
Next: comparing two variances.