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.
Answer: False. Confidence intervals are for the population.
Answer: True. Follows the definition of confidence interval.
Answer: False, 95% of the sample’s confidence intervals would be for true proportion of the population.
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.
Answer: It is a sample statistic because 48% of the 1,259 US residents and not the total population of US.
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%
Answer: True. Both (1259 x .48) > 10 and (1259 x(1-.48)) > 10, the distribution is normal and the CI is correct.
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
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.
Answer: Chi-square test
Answer:
Independent observations: True as 461 is less than 10% total population.
Sample size (at least 10): True.
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.
Answer: Chi squared test.
Answer:
H0: There is no relationship between coffee consumption and clinical depression.
HA: There is a relationship between coffee consumption and clinical 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.
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.
Answer:
chisq <- 20.93
df <- (5-1)*(2-1)
p <- 1-pchisq(chisq, df)
p
## [1] 0.0003269507
The p value is .00033
Answer: The p value is less than .05 so we can reject the null hypothesis that there is no association between coffee and depression.
Answer: Yes I agree, the study only establishes statistical significance. I would say its a weak relationship between coffee consumption and depression among women.