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
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.
False. The confidence interval is not concerned with the sample. It is concerned with the population.
True.
True. Another method of describing the convidence interval.
False. Z goes down, as does our margin of error.
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
48% is a point estimate from the sample. we can use it for inference about population.
Calculation above 45-51%.
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.
It is not. It is possible that 51% is the true proportion, but more of our confidence interval spans below 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?
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
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%
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")
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 |
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.
A Chi-square can be used.
The counts are independant. While we have an observed value of 4 woods, we have an expected value of 20.
Test Statistics is very high with 3 degree of freedom. P-Value is very low. So we can reject \(H_O\)
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
We can use two way table
Null Hypothesis \(H_0\): Coffee Consumption has no effect on depression.
Alternative hypothesis \(H_A\): Coffee Consumption has some effect on depression.
pYes <- round(2607/50739, 3)
pNo <- round(48132/50739, 3)
pYes; pNo
## [1] 0.051
## [1] 0.949
test=pYes * 6617
test=round(test,0)
(373-test)^2 / test
## [1] 3.845697
#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
p-Values is very low we reject \(H_O\)
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