##9.2.5

n<-339
ar<-69
p<-ar/n;p
## [1] 0.2035398
'P Wilson- adjusted'
## [1] "P Wilson- adjusted"
p_adj<-(ar+2)/(n+4);p_adj
## [1] 0.2069971
'Assumptions'
## [1] "Assumptions"
n*p_adj
## [1] 70.17201
n*(1-p_adj)
## [1] 268.828
SE_adj<-sqrt(((p_adj*(1-p_adj))/(n+4)))

CI<-c((p_adj-1.96*SE_adj),(p_adj+1.96*SE_adj)); CI
## [1] 0.1641197 0.2498745
  1. 95% CI (0.1641,0.2499)
  2. We are 95% confident that in a population of babies that recieve the whooping cough vacination somwhere between 16.41 to 24.99% of vacinated babies will experience adverse reactions. c)Using the CI from A, we can be confident that AR’s will be under 25%.
  3. Since it a 2 sided t-test (alpha level =0.05) was run at 95% confidence, would we say that about 97.5% confident that AR’s will be under 25% in the population.

##9.4.4 a) Chi-squared = 13.294

n<-932
o_weekday<-(n-216)/n
o_weekend<-216/n
e_weekday<-5/7
e_weekend<-2/7
birthmatrix<-matrix(c(o_weekend,e_weekend,o_weekday,e_weekday), ncol=2, byrow=TRUE)
rownames(birthmatrix)<-c("weekend", "weekday")
colnames(birthmatrix)<-c("observed", "expected")
birthmatrix<-as.table(birthmatrix); birthmatrix
##          observed  expected
## weekend 0.2317597 0.2857143
## weekday 0.7682403 0.7142857
null.probs = c(e_weekend, e_weekday)
birthnum =c(n*o_weekend, n*o_weekday)
chisq.test(birthnum, p=null.probs)
## 
##  Chi-squared test for given probabilities
## 
## data:  birthnum
## X-squared = 13.294, df = 1, p-value = 0.0002662
  1. Ho: Women giving birth have no preference for if they give birth on a weekend or weekday. Ha: Women giving birth show a preference for giving birth on a weekend or weekday.
  2. We reject the null, and state that woman do show a preference to give birth on a weekday rather than a weekend.

##9.4.5 A chi square test gives a value of chi square = 1.551 and a p-value of 0.6706 (>alpha =.10) meaning that we would fail to reject the null: the ratio of offspring (observed phenotypes) reflect the mendilian genetic (expected genotypes) ratios. There is no significant eidence that the data is inconsitent with the Mendilian model.

null.probs= c(9/16, 3/16, 3/16, 1/16)
WS<-111
Ws<-37
wS<-34
ws<-8
offspringdist = c(WS,Ws,wS,ws)
chisq.test(offspringdist, p=null.probs)
## 
##  Chi-squared test for given probabilities
## 
## data:  offspringdist
## X-squared = 1.5509, df = 3, p-value = 0.6706