##
## Welcome to CUNY DATA606 Statistics and Probability for Data Analytics
## This package is designed to support this course. The text book used
## is OpenIntro Statistics, 3rd Edition. You can read this by typing
## vignette('os3') or visit www.OpenIntro.org.
##
## The getLabs() function will return a list of the labs available.
##
## The demo(package='DATA606') will list the demos that are available.
Practice: 6.6, 6.12, 6.20, 6.28, 6.44, 6.48
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.
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. CI applies to population, not sample.
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. We are 95% confident that the true population mean lies between 43% and 49% for Americans who support this decision.
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. Repeated random samples should capture the true population mean 95% of the time.
The margin of error at a 90% confidence level would be higher than 3%.
False. A lower confidence level would lower the margin of error.
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.
Is 48% a sample statistic or a population parameter? Explain.
Sample statistic. 48% represents the percentage of respondents that said marijuana should be made legal.
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.
n <- 1259
p <- 0.48
ci <- 0.95
se <- ((p * (1 - p)) / n) ^ 0.5
t <- qt(ci + (1 - ci)/2, n - 1)
me <- t * se
ci <- c(p - me, p + me)
ci## [1] 0.4523767 0.5076233
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.
The normal model appears to be a good approximation for this data because the observations meet the conditions for a random sample: The observations seem to be independent and the sample size it not more than 10% of the population.
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?
No. The lower and upper limit of the CI are 45% and 51% respectively. This would not represent the majority of Americans.
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 ?
2398 Americans would need to be surveyed.
moe <- .02
p <- .48
se <- moe/1.96
n <- (p * (1-p))/(se^2)
ceiling(n)## [1] 2398
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.
c <- .95
z <- 1.96
# CA variables
pCA <- .08
nCA <- 11545
# OR variables
pOR <- .088
nOR <- 4691
p.diff <- pOR - pCA
# Standard Error and Margin of Error Calculations
se <- sqrt( ((pCA * (1 - pCA)) / nCA) + ((pOR * (1 - pOR)) / nOR))
me <- z * se
# CI
ci <- c(p.diff - me, p.diff + me)
ci## [1] -0.001498128 0.017498128
We are 95% confident that the true population mean is between -0.14% and 1.75% for differences in the proportions of Californians and Oregonians who are sleep deprived. The CI interval range captures 0, which suggests that there is not a significant difference between sleep deprivation amongst CA and OR residences.
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.
a. Write the hypotheses for testing if barking deer prefer to forage in certain habitats over others.
H0: The barking deer do not prefer to forage in certain habitats over others.
HA: The barking deer prefer to forage in certain habitats over others.
What type of test can we use to answer this research question?
We can use a chi-square goodness-of-fit test to test if the distribution of a set of variables correlates with one another.
Check if the assumptions and conditions required for this test are satisfied.
The conditions for sample size, distribution, and independence are met.
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.
# variables
n <- 426
k <- 4
df <- k - 1
## observed frequencies
wO <- 4
gO <- 16
fO <- 61
oO <- 345
o <- c(wO, gO, fO, oO)
## expected frequencies
wE <- n * .048
gE <- n * .147
fE <- n * .396
oE <- n * (1 - sum(c(.048, .147, .396)))
e <- c(wE, gE, fE, oE)
# Chi2 test loop: x^2 = sigma (O-E)^2/E
chi2 <- 0
for(i in 1:length(o))
{
chi2 <- chi2 + ((o[i] - e[i])^2 / e[i])
}
chi2## [1] 284.0609
6.48 coffee and Depression. 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.
What type of test is appropriate for evaluating if there is an association between coffee intake and depression?
We can use a chi-square goodness-of-fit test to test the association between coffee intake and depression.
Write the hypotheses for the test you identified in part a.
H0: Caffeinated coffee consumption does not affect the risk of depression in women. HA: Caffeinated coffee consumption affects the risk of depression in women.
Calculate the overall proportion of women who do and do not suffer from depression.
# proportion with depression
yes <- 2607/50739
# proportion without depression
no <- 1 - yes
data.frame(yes, no)## yes no
## 1 0.05138059 0.9486194
# expected count
exp <- yes * 6617
exp ## [1] 339.9854
# cell contribution calculation
cell <- (373 - exp)^2 / exp
cell## [1] 3.205914
k <- 5
df <- k - 1
p <- pchisq(20.93, df=df, lower.tail=FALSE)
p## [1] 0.0003269507
What is the conclusion of the hypothesis test?
We reject the null hypothesis because p-value (0.0003269507) is less than 0.05. We can conclude that there is an association between coffee intake and depression.
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, further tests should be conducted to confirm that there are no other hidden variables that could affect these results.