library(ggplot2)
library('DATA606')          # Load the package
## 
## 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.
## 
## Attaching package: 'DATA606'
## The following object is masked from 'package:utils':
## 
##     demo
library(knitr)
#vignette(package='DATA606') # Lists vignettes in the DATA606 package
#vignette('os3')             # Loads a PDF of the OpenIntro Statistics book
#data(package='DATA606')     # Lists data available in the package
#getLabs()                   # Returns a list of the available labs
#viewLab('Lab0')             # Opens Lab0 in the default web browser
#startLab('Lab0')            # Starts Lab0 (copies to getwd()), opens the Rmd file
#shiny_demo()                # Lists available Shiny apps

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.

Answer: False. Confidence intervals are for the population.

  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.

Answer: True. Follows the definition of confidence interval.

  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%.

Answer: False, 95% of the sample’s confidence intervals would be for true proportion of the population.

  1. The margin of error at a 90% confidence level would be higher than 3%.

Answer: False, with a lower confidence interval the margin of error also lowers.

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.

Answer: It is a sample statistic because 48% of the 1,259 US residents and not the total population of US.

  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.

Answer:

n <- 1259
p <- .48
z <- 1.96
SE <- sqrt((p*(1-p))/n)
lower_limit <- p - (z * SE)
lower_limit
## [1] 0.4524028
upper_limit <- p + (z * SE)
upper_limit
## [1] 0.5075972

Interval is 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.

Answer: True. Both (1259 x .48) > 10 and (1259 x(1-.48)) > 10, the distribution is normal and the CI is correct.

  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?

Answer: Yes, With the confidence interval being between 45% and 51% it can be said that over 50% of the Americans think marijuana should be legal.

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 ?

Answer:

p <- 0.48
ME <- 0.02
z <- qnorm(0.975)
SE <- ME/z
n <- (p * (1-p)) / SE^2
n
## [1] 2397.07

Need to survey 2,398 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 di???erence between the proportions of Californians and Oregonians who are sleep deprived and interpret it in context of the data.

Answer:

ncalifornia <- 11545
noregon <- 4691
pcalifornia <- 0.08
poregon <- 0.088
pDiff <- poregon - pcalifornia
SE <- sqrt( ((pcalifornia * (1 - pcalifornia)) / ncalifornia) +  ((poregon * (1 - poregon)) / noregon))
me <- qnorm(0.975) * SE
lower_limit <- pDiff - me
lower_limit
## [1] -0.001497954
upper_limit <- pDiff + me
upper_limit
## [1] 0.01749795

With 0 included in this interval we can say that with a 95% confidence level that the proportions are not statistically different between California and Oregon.

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 Cultivated grassplot Deciduous forests Other Total 4 16 67 345 426

  1. Write the hypotheses for testing if barking deer prefer to forage in certain habitats over others.

Answer:

Ho is there is no difference in the proportion of deer that forage in certain habitats.

HA is there is a difference in the proportion of deer that forage in certain habitats.

  1. What type of test can we use to answer this research question?

Answer: Chi-square test

  1. Check if the assumptions and conditions required for this test are satisfied.

Answer:

Independent observations: True as 461 is less than 10% total population.

Sample size (at least 10): True.

  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.

Answer:

chisq.test(x=c(4,16,67,345),p=c(0.048,0.147,0.396,0.409))
## 
##  Chi-squared test for given probabilities
## 
## data:  c(4, 16, 67, 345)
## X-squared = 272.69, df = 3, p-value < 2.2e-16

The p value is (<0.05) so we can conclude barking deer forage in some habitats more than others.

6.48 Co???ee and Depression.:

Researchers conducted a study investigating the relationship between ca???einated co???ee 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 ca???einated co???ee 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 ca???einated co???ee consumption.

  1. What type of test is appropriate for evaluating if there is an association between co???ee intake and depression?

Answer: Chi squared test.

  1. Write the hypotheses for the test you identified in part (a).

Answer:

H0: There is no relationship between coffee consumption and clinical depression.

HA: There is a relationship between coffee consumption and clinical depression.

  1. Calculate the overall proportion of women who do and do not su???er from depression.

Answer:

depress <- 2607/50739
depress
## [1] 0.05138059
not_depress <-  48132/50739
not_depress
## [1] 0.9486194

The propotion of women who do suffer from depression is .05 and the proportion of women who do not suffer from depression is .95.

  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.

Answer:

n <- 373
expect <- depress *  6617
expect
## [1] 339.9854
expected_count <- ((n - expect)^2) / expect
expected_count
## [1] 3.205914

The expected count: 3.21.

  1. The test statistic is #2 = 20.93. What is the p-value?

Answer:

chisq <- 20.93
df <-  (5-1)*(2-1)
p <- 1-pchisq(chisq, df)
p
## [1] 0.0003269507

The p value is .00033

  1. What is the conclusion of the hypothesis test?

Answer: The p value is less than .05 so we can reject the null hypothesis that there is no association between coffee and 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.

Answer: Yes I agree, the study only establishes statistical significance. I would say its a weak relationship between coffee consumption and depression among women.