Chapter 6 - Inference for Categorical Data
Practice: 6.5, 6.11, 6.27, 6.43, 6.47
Graded: 6.6, 6.12, 6.20, 6.28, 6.44, 6.48
On June 28, 2012 the U.S. Supreme Court upheld the much debated 2010 healthcare law, declaring it constitutional. A Gallup poll released the day after this decision indicates that 46% of 1,012 Americans agree with this decision. At a 95% confidence level, this sample has a 3% margin of error. Based on this information, determine if the following statements are true or false, and explain your reasoning.
(a) We are 95% confident that between 43% and 49% of Americans in this sample support the decision of the U.S. Supreme Court on the 2010 healthcare law.
Technically, yes, we’re at least 95% confident that between 43% and 49% of Americans in this sample support the decision. We know (100% confidence) that 46% of the sample supports it.
(b) We are 95% confident that between 43% and 49% of Americans support the decision of the U.S. Supreme Court on the 2010 healthcare law.
This is more like it. Yes, the confidence interval from the sample allows us to infer at a 95% confidence level that the true level of support in the population lies between 43% and 49%.
(c) If we considered many random samples of 1,012 Americans, and we calculated the sample proportions of those who support the decision of the U.S. Supreme Court, 95% of those sample proportions will be between 43% and 49%.
True. The sample proportion should fall in the confidence level 95% of the time.
(d) The margin of error at a 90% confidence level would be higher than 3%.
False. A lower confidence level means the range given by the margin of error will be smaller, as you’re willing to tolerate a higher chance of missing the true population proportion. Looking at the math, the z score used to calculate the margin of error will be lower at 90% than 95%, producing a smaller MoE.
The 2010 General Social Survey asked 1,259 US residents: “Do you think the use of marijuana should be made legal, or not?” 48% of the respondents said it should be made legal.
(a) Is 48% a sample statistic or a population parameter? Explain.
Sample statistic - it’s a point estimate of the population parameter. The population parameter would be the actual percentage of the entire US population that supports marijuana legalization.
(b) Construct a 95% confidence interval for the proportion of US residents who think marijuana should be made legal, and interpret it in the context of the data.
#calculate relatively manually for now - will use the inference function later
#two-tailed so use. 975 for z score
z_6.12 <- qnorm(.975)
n_6.12 <- 1259
p_6.12 <- .48
#margin of error
me_6.12 <- z_6.12 * sqrt((p_6.12*(1-p_6.12))/n_6.12)
#state confidencde interval
lt_6.12 = p_6.12 - me_6.12
ut_6.12 = p_6.12 + me_6.12
paste("95% confidence interval for marijuana legalization support is from",round(lt_6.12,4), "to",round(ut_6.12,4), ".")
## [1] "95% confidence interval for marijuana legalization support is from 0.4524 to 0.5076 ."
(c) A critic points out that this 95% confidence interval is only accurate if the statistic follows a normal distribution, or if the normal model is a good approximation. Is this true for these data? Explain.
Yes, it appears so. There are two conditions for confirming that a sampling distribution of a population proportion estimate is nearly normal.
1. The sampling observations are independent - it seems so. 2. Passes the success-failure conditions, meaning there are at least 10 successes and 10 failures. As our sample of > 1200 is nearly evenly split, the sample fits this criteria.
(d) A news piece on this survey’s ???ndings states, “Majority of Americans think marijuana should be legalized.” Based on your con???dence interval, is this news piece’s statement justi???ed?
No, it’s not justified based on this sample. While the upper end of the confidence interval slightly exceeds 50%, the vast majority of it is under 50%. At a 95% confidence level, we actually cannot say whether or not a majority supports or opposses such legislation, though at a lower confidence level the entire interval would likely be under 50%.
As discussed in Exercise 6.12, the 2010 General Social Survey reported a sample where about 48% of US residents thought marijuana should be made legal. If we wanted to limit the margin of error of a 95% confidence interval to 2%, about how many Americans would we need to survey?
Solve necessary sample size for <= 2% margin of error at 95% confidence level with known p of .48
#me = z-score * sqrt((p(1-p))/n)
#two tailed, so use .975
Z_6.20 = qnorm(.975)
p_6.20 = .48
p_6.20_num = p_6.20 * (1 - p_6.20)
#looking for me <= .1
me_6.20 = .02
#square both sides
((Z_6.20)^2 * (p_6.20_num))/me_6.20^2
## [1] 2397.07
Round up to 2398 to get the sample size needed for the guidelines.
According to a report on sleep deprivation by the Centers for Disease Control and Prevention, the proportion of California residents who reported insucient rest or sleep during each of the preceding 30 days is 8.0%, while this proportion is 8.8% for Oregon residents. These data are based on simple random samples of 11,545 California and 4,691 Oregon residents. Calculate a 95% confidence interval for the difference between the proportions of Californians and Oregonians who are sleep deprived and interpret it in context of the data.
Samples appear to be independent and pass success-failure condition.
Standard error of difference between two proportions:
SE(p1-p2) = sqrt(((p1(1-p1))/n1) + ((p2(1-p2))/n2)) CI = point est of diff +/- z * SE
Z = qnorm(.975)
#1 = Cali
p1 = .080
#2 = OR
p2 = .088
n1 = 11545
n2 = 4691
SE = sqrt(((p1*(1-p1))/n1) + ((p2*(1-p2))/n2))
CI_L = abs(p1-p2) - (Z * SE)
CI_U = abs(p1-p2) + (Z * SE)
paste("95% confidence interval for the difference in sleep deprivation rates is from",round(CI_L,4), "to",round(CI_U,4), ". Note that this is from the perspective of California. If we started with Oregon, the CI would be -.0175 to .0015.")
## [1] "95% confidence interval for the difference in sleep deprivation rates is from -0.0015 to 0.0175 . Note that this is from the perspective of California. If we started with Oregon, the CI would be -.0175 to .0015."
##6.44 Barking deer.
Microhabitat factors associated with forage and bed sites of barking deer in Hainan Island, China were examined from 2001 to 2002. In this region woods make up 4.8% of the land, cultivated grass plot makes up 14.7% and deciduous forests makes up 39.6%. Of the 426 sites where the deer forage, 4 were categorized as woods, 16 as cultivated grassplot, and 61 as deciduous forests. The table below summarizes these data.
woods_o <- 4
woods_e <- 426 * .048
grass_o <- 16
grass_e <- 426 * .147
forests_o <- 61
forests_e <- 426 * .396
other_o <- (426 - 4 - 16 - 61)
other_e <- 426 * (1-(.048 + .147 + .396))
#chi-square test
chisq_6.44 <- (woods_o-woods_e)^2/woods_e + (grass_o-grass_e)^2/grass_e + (forests_o-forests_e)^2/forests_e + (other_o-other_e)^2/other_e
dfree_6.44 <- 4-1
p_6.44 <- 1-pchisq(chisq_6.44,df=dfree_6.44)
p_6.44
## [1] 0
As we might expect given the actual woods value, we reject the null hypothesis that deer do not have preferences in foraging sites.
Researchers conducted a study investigating the relationship between caffeinated coffee consumption and risk of depression in women. They collected data on 50,739 women free of depression symptoms at the start of the study in the year 1996, and these women were followed through 2006. The researchers used questionnaires to collect data on caffeinated coffee consumption, asked each individual about physician-diagnosed depression, and also asked about the use of antidepressants. The table below shows the distribution of incidences of depression by amount of caffeinated coffee consumption.
(a) What type of test is appropriate for evaluating if there is an association between coffee intake and depression?
Chi-square.
(b) Write the hypotheses for the test you identi???ed in part (a).
HO: There is no difference in the amount of depression among different levels of coffee consumption. HA: Depression differs among different levels of caffeinated coffee consumption.
(c) Calculate the overall proportion of women who do and do not suffer from depression.
#depression
dep <- 2607/50739
#no depression
no_dep <- 48132/50739
paste("The overall proportion of women who suffer from depression is", round(dep,4))
## [1] "The overall proportion of women who suffer from depression is 0.0514"
paste("The overall proportion of women who do not suffer from depression is", round(no_dep,4))
## [1] "The overall proportion of women who do not suffer from depression is 0.9486"
(d) Identify the expected count for the highlighted cell, and calculate the contribution of this cell to the test statistic, i.e. (Observed-Expected)^2/Expected.
#highlighted cell is 2-6 cups/week with clinical depression
exp_dep_2_6 <- 6617 * dep
paste("Expected count for subjects who drink 2-6 cups per week with clinical depression is",round(exp_dep_2_6,0))
## [1] "Expected count for subjects who drink 2-6 cups per week with clinical depression is 340"
#contribution of this cell to test statistic
actual_dep_2_6 <- 373
cont_dep_2_6 <- (actual_dep_2_6 - exp_dep_2_6)^2/exp_dep_2_6
paste("The 2-6 cups per week with clinical depression cell contributes",round(cont_dep_2_6,2),"to the test statistic.")
## [1] "The 2-6 cups per week with clinical depression cell contributes 3.21 to the test statistic."
(e) The test statistic is X^2 = 20.93. What is the p-value?
(5-1) columns x (2-1) rows means 4 df.
p_6.48 <- pchisq(20.93, 4, lower.tail = FALSE)
paste("P-value is",round(p_6.48,5),"so we reject the null hypthoesis that there's no relationship between caffeine consumption and depression.")
## [1] "P-value is 0.00033 so we reject the null hypthoesis that there's no relationship between caffeine consumption and depression."
(f) What is the conclusion of the hypothesis test?
See above.
(g) One of the authors of this study was quoted on the NYTimes as saying it was “too early to recommend that women load up on extra coffee” based on just this study. Do you agree with this statement? Explain your reasoning.
Yes, I agree. Correlation, causation, all that. A 10-year questionnaire study is intriguing, but we’d prefer a more experimental study.