Section B.4 Two proportions
Subsection B.4.1 Problem statement
A 2010 survey asked 827 randomly sampled registered voters in California βDo you support? Or do you oppose? Drilling for oil and natural gas off the Coast of California? Or do you not know enough to say?β Conduct a hypothesis test to determine if the data provide strong evidence that the proportion of college graduates who do not have an opinion on this issue is different than that of non-college graduates. (Tweaked a bit from [7], Chapter 6.)
Subsection B.4.2 Competing hypotheses
-
Null hypothesis: There is no association between having an opinion on drilling and having a college degree for all registered California voters in 2010.
-
Alternative hypothesis: There is an association between having an opinion on drilling and having a college degree for all registered California voters in 2010.
-
\(\displaystyle H_0: \pi_{\text{college}} = \pi_{\text{no\_college}}\)
-
\(\displaystyle H_A: \pi_{\text{college}} - \pi_{\text{no\_college}} \ne 0\)
Significance level: \(\alpha = 0.05\text{.}\)
Subsection B.4.3 Exploring the sample data
offshore <- read_csv("https://moderndive.com/data/offshore.csv")
counts <- offshore |> tabyl(college_grad, response)
counts
college_grad no opinion opinion
no 131 258
yes 104 334
offshore <- offshore |>
mutate(response = fct_rev(response))
ggplot(offshore, aes(x = college_grad, fill = response)) +
geom_bar(position = "fill") +
labs(x = "College grad?", y = "Proportion with no opinion on drilling") +
coord_flip()
Subsection B.4.4 Simulation-based methods
d_hat <- offshore |>
specify(response ~ college_grad, success = "no opinion") |>
calculate(stat = "diff in props", order = c("yes", "no"))
d_hat
set.seed(2018)
null_distn_two_props <- offshore |>
specify(response ~ college_grad, success = "no opinion") |>
hypothesize(null = "independence") |>
generate(reps = 10000) |>
calculate(stat = "diff in props", order = c("yes", "no"))
null_distn_two_props |>
visualize() +
shade_p_value(obs_stat = d_hat, direction = "both")
pvalue <- null_distn_two_props |>
get_pvalue(obs_stat = d_hat, direction = "two_sided")
pvalue
The \(p\)-value is small and we reject the null hypothesis at the 5% level.
boot_distn_two_props <- offshore |>
specify(response ~ college_grad, success = "no opinion") |>
generate(reps = 10000) |>
calculate(stat = "diff in props", order = c("yes", "no"))
ci <- boot_distn_two_props |>
get_ci()
ci
boot_distn_two_props |>
visualize() +
shade_ci(endpoints = ci)
We see that 0 is not contained in this confidence interval. This matches with our hypothesis test results of rejecting the null hypothesis.
Subsection B.4.5 Theory-based methods
Check conditions.
Remember that in order to use the shortcut (formula-based, theoretical) approach, we need to check that some conditions are met.
-
Independent observations: Each case that was selected must be independent of all the other cases selected. This condition is met since cases were selected at random to observe.
-
Sample size: The number of pooled successes and pooled failures must be at least 10 for each group. The pooled success rate is approximately 0.28, and the expected counts are all greater than 10.
-
Independent selection of samples: The cases are not paired in any meaningful way. We have no reason to suspect that a college graduate selected would have any relationship to a non-college graduate selected.
Test statistic.
If conditions are met and \(H_0\) is true, we can standardize \(\hat{P}_{\text{college}} - \hat{P}_{\text{no\_college}}\) using the pooled standard error:
\begin{equation*}
Z = \frac{(\hat{P}_{\text{college}} - \hat{P}_{\text{no\_college}}) - 0}
{\sqrt{\dfrac{\hat{P}(1-\hat{P})}{n_1} + \dfrac{\hat{P}(1-\hat{P})}{n_2}}}
\sim N(0,1)
\end{equation*}
where \(\hat{P} = \dfrac{\text{total successes}}{\text{total cases}}\text{.}\)
Observed test statistic.
While one could compute this observed test statistic by "hand", the focus here is on the set-up of the problem and in understanding which formula for the test statistic applies.
z_hat <- offshore |>
specify(response ~ college_grad, success = "no opinion") |>
calculate(stat = "z", order = c("yes", "no"))
z_hat
The \(p\)-valueβthe probability of observing a \(Z\) value of -3.16 or more extreme in our null distributionβis 0.0016. This can also be calculated in R directly:
2 * pnorm(-3.16, lower.tail = TRUE)
State conclusion.
We have sufficient evidence to reject the null hypothesis. We do have evidence to suggest that there is a dependency between college graduation and position on offshore drilling for Californians.
Subsection B.4.6 Comparing results
Observing the bootstrap distribution and the null distribution that were created, it makes quite a bit of sense that the results are so similar for traditional and non-traditional methods in terms of the \(p\)-value and the confidence interval since these distributions look very similar to normal distributions. The conditions were not met since the number of pairs was small, but the sample data was not highly skewed. Using any of the methods whether they are traditional (formula-based) or non-traditional (computational-based) lead to similar results.
