Chapter 6 - Inference for Categorical Data

6.6 2010 Healthcare Law. 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.

  1. 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.
# False. We know for 100% fact that this sample has a 46% approval rate. We know that the US population approval rate with 95% confidence intervals is between 43% and 49%.
  1. 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.
# True. This is the definition of the confidence interval. (The American population, not the sample size.)
  1. 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. This is also the definition of the confidence interval.
  1. The margin of error at a 90% confidence level would be higher than 3%.
# Margin of error = Z * Standard of Error. If this is a 90% confidence interval, the Z would correspond to: 1.65. Therefore, the margin of error would be lower, thus this statement is false.

6.12 Legalization of marijuana, Part I. 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.

  1. Is 48% a sample statistic or a population parameter? Explain.
# This is a sample statistic as this number, 48%, was derived from a sample of 1259 US residents, and NOT from the US population.
  1. 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.
# 95% Confidence Interval translates into an alpha of 0.05. On the Z table, z = 1.96
z <- 1.96
p <- .48 # We are making the presumption that the global proportion is 0.48, from the sample statistic
n <- 1259 # The number in this sample
me <- z * sqrt(p*(1-p)/n)
paste("Margin of Error: ", round(me*100,2), "%")
## [1] "Margin of Error:  2.76 %"
ci.l <- (p - me) * 100
ci.u <- (p + me) * 100
paste("The 95% confidence interval ranges from ", round(ci.l,2), "% to", round(ci.u,2), "%.")
## [1] "The 95% confidence interval ranges from  45.24 % to 50.76 %."
# This means that we are 95% confident that the approval rate in the US population for the legal use of marijuana ranges from 45.24% to 50.76%.
  1. 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.
# Given that there are over >1200 residents, this is a fairly large sample size. So yes, while having a normal model would allow us to perform a 95% confidence interval, some skew or even large skews would be negated by the fact that we have such a large sample. In addition, given how large the samples are, we appear to have a large sample of both successes and failures.
  1. A news piece on this survey’s findings states, “Majority of Americans think marijuana should be legalized.” Based on your confidence interval, is this news piece’s statement justified?
# This statement is false. The 95% confidence interval falls between 45.24% to 50.76%, which most of it is < 50%. Therefore, this statement is incorrect.

6.20 Legalize Marijuana, Part II. 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 ?

# Here, they are looking for margin of error = 2% = .02
# Margin of Error = Z * Standard of Error
# Because they are looking for a 95% confidence interval, z = 1.96
MJ.p <- .48
SE <- .02/1.96

# Standard of Error = sqrt(p * (1-p) / n)
# Will need to rearrange to look for n
MJ.n <- (MJ.p * (1-MJ.p))/(SE^2)
paste("Americans needed for survey for Margin of Error of a 95% confidence interval to 2% is: ", MJ.n)
## [1] "Americans needed for survey for Margin of Error of a 95% confidence interval to 2% is:  2397.1584"
# Given the answer is 2397.16, will need to round up to 2398 Americans.

6.28 Sleep deprivation, CA vs. OR, Part I. According to a report on sleep deprivation by the Centers for Disease Control and Prevention, the proportion of California residents who reported insufficient 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.

CA.n <- 11545
CA.p <- 0.08
OR.n <- 4691
OR.p <- 0.088
St.z <- 1.96 # For 95% Confidence Interval
St.se.ca <- sqrt((CA.p)*(1-CA.p)/CA.n) 
St.ME.ca <- St.z * St.se.ca # Margin of Error at 95% confidence interval
St.se.or <- sqrt((OR.p)*(1-OR.p)/OR.n)
St.ME.or <- St.z * St.se.or # Margin of Error at 95% confidence interval
paste("The margin of error for California in this data: ", round(St.ME.ca * 100, 2), "%.")
## [1] "The margin of error for California in this data:  0.49 %."
paste("The margin of error for Oregon in this data: ", round(St.ME.or * 100, 2), "%.")
## [1] "The margin of error for Oregon in this data:  0.81 %."
# Now to calculate the confidence interval
CA.lower <- CA.p - St.ME.ca
CA.upper <- CA.p + St.ME.ca
OR.lower <- OR.p - St.ME.or
OR.upper <- OR.p + St.ME.or
paste("California 95% Confidence Interval: ", round(CA.lower * 100, 2), "% to", round(CA.upper * 100, 2), "%.")
## [1] "California 95% Confidence Interval:  7.51 % to 8.49 %."
paste("Oregon 95% Confidence Interval: ", round(OR.lower * 100, 2), "% to", round(OR.upper * 100, 2), "%.")
## [1] "Oregon 95% Confidence Interval:  7.99 % to 9.61 %."
# Given that these two states' confidence intervals overlap, it appears that we cannot reject the null hypothesis. However, let's take a closer look at the differences in proportions.
# Again, null hypothesis is the proportion of California residents with insufficient sleep - the proportion of Oregon residents with insufficient sleep == 0.
# The alternate hypothesis is: null hypothesis is the proportion of California residents with insufficient sleep - the proportion of Oregon residents with insufficient sleep != 0.

St.se <- sqrt((CA.p)*(1-CA.p)/CA.n + (OR.p)*(1-OR.p)/OR.n) # Calculating a new SE for the differences
State.MoE <- St.z * St.se

# Will develop the 95% confidence interval
Difference <- OR.p - CA.p
Difference.lower <- Difference - State.MoE
Difference.upper <- Difference + State.MoE
paste("The 95% confidence interval for the difference in proportion of Oregon and California residents for sleep deprivation ranges from ", round(Difference.lower, 4), " to ", round(Difference.upper,4), ".")
## [1] "The 95% confidence interval for the difference in proportion of Oregon and California residents for sleep deprivation ranges from  -0.0015  to  0.0175 ."
# Given that the 95% confidence includes 0, we cannot sufficiently reject the null hypothesis.

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.

  1. Write the hypotheses for testing if barking deer prefer to forage in certain habitats over others.
# The null hypothesis is: the barking deer have no preference to certain habitats and that they have equal preference among them all.
# The alternative hypothesis is: The barking deer does indeed have a preference to certain habitats
  1. What type of test can we use to answer this research question?
# We can use a Chi square test.
  1. Check if the assumptions and conditions required for this test are satisfied.
# Looking at the data, we assume that the deer are not influencing each other and that they are independent. There appears to be 4 observed cases in the woods section, but if we calculate out the expected amount of cases for woods, .048 * 426 = 20.448, which is greater or equal to 5, thus satisfying part 2 of the conditions. 
  1. Do these data provide convincing evidence that barking deer prefer to forage in certain habitats over others? Conduct an appropriate hypothesis test to answer this research question.
# Will use the chi square test
deer.chi <- (4-20.448)^2/20.448 + (16-62.622)^2/62.622 + (61-168.696)^2/168.696 +(345-174.234)^2/174.234
paste("Chi Squared for Deer: ", deer.chi)
## [1] "Chi Squared for Deer:  284.06094954246"
# Degrees of freedom: (4-1) = 3
# Will look on the table.
# p value is <=less than 0.005.
# Therefore, we reject the null hypothesis.

6.48 Coffee and Depression. Researchers conducted a study investigating the relationship between ca↵einated 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.

  1. What type of test is appropriate for evaluating if there is an association between coffee intake and depression?
# An appropriate test would be a two table chi squared test.
  1. Write the hypotheses for the test you identified in part (a).
# Null hypothesis: The proportion of clinically depressed women are the same no matter the amount of coffee they drink.
# Alternative hypothesis: The proportion of clinically depressed women are different among varying amounts of coffee that has been consumed.
  1. Calculate the overall proportion of women who do and do not suffer from depression.
Depressed <- 2607/50739
paste("The proportion of women who suffer from depression: ", round(Depressed, 4))
## [1] "The proportion of women who suffer from depression:  0.0514"
Not.Depressed <- 48132/50739
paste("The proportion of women who do not suffer from depression: ", round(Not.Depressed, 4))
## [1] "The proportion of women who do not suffer from depression:  0.9486"
  1. 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.
cup1week.depressed <- Depressed * 12215 
cup1week.notd <- Not.Depressed * 12215 

cup2.6.week.depressed <- Depressed * 6617 
cup2.6.week.notd <- Not.Depressed * 6617 

cup1.day.depressed <- Depressed * 17234
cup1.day.notd <- Not.Depressed * 17234

cup2.3.day.depressed <- Depressed * 12290
cup2.3.day.notd <- Not.Depressed * 12290

cup4.day.depressed <- Depressed * 2383
cup4.day.notd <- Not.Depressed * 2383

#------------------------------------
# Expected values
paste("Expected Value: 2 to 6 cups/week & depressed: ", cup2.6.week.depressed)
## [1] "Expected Value: 2 to 6 cups/week & depressed:  339.985395849347"
paste("Calculation for the test statistic: ", (373-cup2.6.week.depressed)^2/cup2.6.week.depressed)
## [1] "Calculation for the test statistic:  3.20591443200495"
  1. The test statistic is 2 = 20.93. What is the p-value?
# Must calculate for the degrees of freedom, which is (columns - 1) * (rows - 1)
degree.freedom <- (5-1) * (2-1)
paste("Degree of Freedom: ", degree.freedom)
## [1] "Degree of Freedom:  4"
# Look on the table with 4 degree of freedom with a chi squared result of 20.93.
paste("According to the table, a chi squared value of 20.93 with 4 degrees of freedom has a p value less than 0.005, thus rejecting the null hypothesis.")
## [1] "According to the table, a chi squared value of 20.93 with 4 degrees of freedom has a p value less than 0.005, thus rejecting the null hypothesis."
  1. What is the conclusion of the hypothesis test?
# We reject the null hypothesis and state that there is a statistical significant difference among different groups of coffee drinkers and clinical depression.
  1. 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.
# I agree that it was too early to make this recommendation. All the study states is that there is a statistical difference. It does not necessarily imply that there is a clinical significant difference, which is what many physicians, psychologist, psychiatrists are interested in. This was not an experiment but simply a prospective observation study. Because there is a correlation does not necessitate a causation. Plus, there are so many confounding factors to consider.