if (!require('DATA606')) install.packages('DATA606')
## Loading required package: DATA606
## 
## 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
if (!require('ggplot2')) install.packages('ggplot2')
## Loading required package: ggplot2

Graded: 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.

  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. The confidence interval is not concerned with the sample. It is concerned with 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.

True.

  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. Another method of describing the convidence interval.

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

False. Z goes down, as does our 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.

p=.48
n=1259
se=round(sqrt((p*(1-p))/n),3)
z=1.96
moe=round(z*se,2)
p-moe; p+moe
## [1] 0.45
## [1] 0.51
  1. Is 48% a sample statistic or a population parameter? Explain.

48% is a point estimate from the sample. we can use it for inference about 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.

Calculation above 45-51%.

  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.

Yes our distribution is nearly normal. Our observations seem to be indpendant, and have a large sample of both success and failiure rates and no strond skewness.

  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?

It is not. It is possible that 51% is the true proportion, but more of our confidence interval spans below 50%.

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?

p=.48
z=1.96
moe=.02
se=moe/z
n=round(p * (1-p) / se^2)
n
## [1] 2397
# Population survey should be of 2397

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

nCal = 11545
nOrg = 4691
pCal=.08
pOrg= .088

diffprop= pOrg - pCal
se=round(sqrt((pOrg*(1-pOrg))/nOrg + (pCal*(1-pCal))/nCal), 6)
z=1.96
moe=round(se * z, 6)
diffprop - moe
## [1] -0.001498
diffprop + moe
## [1] 0.017498

95% confidence of difference in proportions of insufficient sleep between Californians and Oregons are between -.149% and 1.75%

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.

t=426
woods=c(4, round(t * .048))
grassplot=c(16, round(t * .147))
forests=c(67, round(t * .396))
other=c(345, round(t * .409))
total=c(t, t)
df=data.frame(rbind(woods, grassplot, forests, other, total))
colnames(df)=c("observed", "expected")
df$z2=(df$observed-df$expected)^2 / df$expected
x2=round(sum(df$z2), 2)

knitr::kable(df,format = "pandoc",align = "l", caption = "Barking Deer")
Barking Deer
observed expected z2
woods 4 20 12.80000
grassplot 16 63 35.06349
forests 67 169 61.56213
other 345 174 168.05172
total 426 426 0.00000
  1. Write the hypotheses for testing if barking deer prefer to forage in certain habitats over others.

Null Hypothesis = \(H_O\): The deer foraging sites do not prefer certain habitats over others.

Alternative Hypothesis = \(H_A\): The deer foraging sites have a preference.

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

A Chi-square can be used.

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

The counts are independant. While we have an observed value of 4 woods, we have an expected value of 20.

  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.

Test Statistics is very high with 3 degree of freedom. P-Value is very low. So we can reject \(H_O\)

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.

Figure 6.48

Figure 6.48

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

We can use two way table

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

Null Hypothesis \(H_0\): Coffee Consumption has no effect on depression.

Alternative hypothesis \(H_A\): Coffee Consumption has some effect on depression.

  1. Calculate the overall proportion of women who do and do not suffer from depression.
pYes <- round(2607/50739, 3)
pNo <- round(48132/50739, 3)
pYes; pNo
## [1] 0.051
## [1] 0.949
  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.
test=pYes * 6617
test=round(test,0)
(373-test)^2 / test
## [1] 3.845697
  1. The test statistic is X^2 = 20.93. What is the p-value?
#Degree of Freedom=(Columns-1)* (Rows-1)
DoF=(5-1)*(2-1)
DoF
## [1] 4
pchisq(20.93,DoF,lower.tail = FALSE)
## [1] 0.0003269507

p-Value is 0.0003269507, which is very less than .001

  1. What is the conclusion of the hypothesis test?

p-Values is very low we reject \(H_O\)

  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.64 Do you agree with this statement? Explain your reasoning.

Agree with the author, as per the calculation of p-value being very low and rejection of null hypothesis, though it is statistically significant in real world sense there could be other factors which could dictate the outcome