# 6.29 O???shore drilling, Part I. A 2010 survey asked 827 randomly sampled registered voters in California "Do you support? Or do you oppose? Drilling for oil and natural gas off the Coast of California? Or do you not know enough to say?" Below is the distribution of responses, separated based on whether or not the respondent graduated from college.

#(a) What percent of college graduates and what percent of the non-college graduates in this sample do not know enough to have an opinion on drilling for oil and natural gas off the Coast of California? 

pc = 104/438
pn = 131/389

#College
pc
## [1] 0.2374429
#Non-College
pn
## [1] 0.3367609
#(b) Conduct a hypothesis test to determine if the data provide strong evidence that the proportion of college graduates who do not have an opinion on this issue is different than that of non-college graduates. 
#Hypothesis: Ho: pc = pn, Ha: pc != pn
Z = (0.237-0.337)/sqrt(0.254*0.716/438+0.284*0.716/389)
2*pnorm(Z,0,1)
## [1] 0.001093856
#Decision: reject the null as the p-vale is less than .05
#There appears to be a stastical difference in the proportion of college graduates that do not know enough about the topic.

#Chi Square Discussion
#One would not expect the probability to hold as we reject the null

library(data.table)
College.dt <- data.table(
 rowNames = c("Support","Oppose","Do not know"),
 Yes = c(154,180, 104),
 No = c(132,126,131)
)


chisq.test(x = College.dt$Yes, y= College.dt$No, correct = T )
## Warning in chisq.test(x = College.dt$Yes, y = College.dt$No, correct = T):
## Chi-squared approximation may be incorrect
## 
##  Pearson's Chi-squared test
## 
## data:  College.dt$Yes and College.dt$No
## X-squared = 6, df = 4, p-value = 0.1991
#The Chisq test shows that there is a p-value > .05