In the last module, we discussed describing data.
In this module, we are discussing statistical inference on one sample.
Mean / median
Proportion
Variance / standard deviation
In this lecture, we are focusing on one-sample proportions.
R Setup| resident_name | department | district | academy_status | academy_exam_score | sleep_hours | hustle_earnings | district_temp_f |
|---|---|---|---|---|---|---|---|
| Sable Jones | Desk | Rainforest District | Fail | 65 | 5.5 | 14.72 | 72.2 |
| Kevin Frostwhisker | Patrol | Downtown | Fail | 69 | 7.4 | 45.66 | 66.2 |
| Jasper Duskrunner | Patrol | Sahara Square | Pass | 79 | 8.7 | 30.91 | 89.8 |
\hat{p} \pm z_{\alpha/2} \sqrt{\frac{\hat{p}(1-\hat{p})}{n}}
\hat{p} is the sample proportion (the point estimate)
z_{\alpha/2} comes from the standard normal distribution (the critical value)
\hat{p}(1-\hat{p}) is the variance of the Bernoulli distribution and n is the sample size (\sqrt{\hat{p}(1-\hat{p})/n} is the standard error of the mean)
Two-Tailed
H_0: \pi = \pi_0
H_1: \pi \ne \pi_0
Left-Tailed
H_0: \pi \ge \pi_0
H_1: \pi < \pi_0
Right-Tailed
H_0: \pi \le \pi_0
H_1: \pi > \pi_0
\pi is the population proportion,
\pi_0 is the hypothesized value of \pi.
z_0 = \frac{\hat{p} - \pi_0}{\sqrt{\frac{\pi_0(1-\pi_0)}{n}}}
where
\hat{p} is the sample proportion
\pi_0 is the hypothesized value of \pi
n is the sample size
R)one_proportion() function from library(ssstats) to perform statistical inference.where
outcome is the variable name of the outcome variable
event is the name or number of the event of interest
p is the hypothesized value of the population proportion (default = 0.05)
alternative is the alternative hypothesis (default = “two”)
alpha is the significance level (default = 0.05)
ZPD’s official staffing policy states that 50% of officers are assigned to Patrol, with the rest working Desk duty. As Zootopia’s data analyst, you believe that Patrol seems to make up a lot more than 50% of the department these days. We will use the zootopia dataset to answer:
First, we need to describe the data.
Then, we will perform a hypothesis test to answer the question.
Error in `one_proportion()`:
! argument "event" is missing, with no default
department variable.One-sample proportion
p̂ = 0.6 (18/30)
95% CI for π: (0.4247, 0.7753)
Hypotheses:
H₀: π = 0.5
H₁: π ≠ 0.5
Test statistic: z = 1.1
p-value: 0.273
Conclusion: Fail to reject the null hypothesis (p = 0.273 ≥ α = 0.050)
Then, we will perform a hypothesis test to answer the question.
How do we translate this into hypotheses?
For the one_proportion() function, we will set
p = 0.5alternative = "greater".zootopia |> one_proportion(outcome = department,
event = "Patrol",
p = 0.5,
alternative = "greater",
alpha = 0.05)One-sample proportion
p̂ = 0.6 (18/30)
95% CI for π: (0.4247, 0.7753)
Hypotheses:
H₀: π ≤ 0.5
H₁: π > 0.5
Test statistic: z = 1.1
p-value: 0.137
Conclusion: Fail to reject the null hypothesis (p = 0.137 ≥ α = 0.050)
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
Zootopia’s Housing Authority claims that 40% of officers live in Downtown. As data analyst, you believe Downtown might actually make up a smaller proportion of the roster than the Authority’s number suggests. We will use the zootopia dataset to answer:
First, we need to describe the data.
Then, we will perform a hypothesis test to answer the question.
district,| district | n (pct) |
|---|---|
| Downtown | 8 (26.7%) |
| Rainforest District | 7 (23.3%) |
| Sahara Square | 9 (30.0%) |
| Tundratown | 6 (20.0%) |
Downtown.One-sample proportion
p̂ = 0.2667 (8/30)
95% CI for π: (0.1084, 0.4249)
Hypotheses:
H₀: π = 0.5
H₁: π ≠ 0.5
Test statistic: z = -2.56
p-value: 0.011
Conclusion: Reject the null hypothesis (p = 0.011 < α = 0.050)
Then, we will perform a hypothesis test to answer the question.
How do we translate this into hypotheses?
For the one_proportion() function, we will set
p = 0.4alternative = "less".zootopia |> one_proportion(outcome = district,
event = "Downtown",
p = 0.4,
alternative = "less",
alpha = 0.05)One-sample proportion
p̂ = 0.2667 (8/30)
95% CI for π: (0.1084, 0.4249)
Hypotheses:
H₀: π ≥ 0.4
H₁: π < 0.4
Test statistic: z = -1.49
p-value: 0.068
Conclusion: Fail to reject the null hypothesis (p = 0.068 ≥ α = 0.050)
Hypotheses
Test Statistic and p-Value
Rejection Region
Conclusion and Interpretation
In this lecture, we discussed statistical inference on one proportion.
Fun fact: proportions are just a mean!
In the next lecture, we will examine statistical inference on one variance or standard deviation.