# in-class solutions
##Exercise 1
outbreak<-cbind(Outbreak,case)
detach(Outbreak)
attach(outbreak)
##Exercise 2
case.beef<-table(case,beefcurry)
case.beef<-prop.table(case.beef,2)
case.beef
barplot(case.beef,beside=T,names.arg=c("No Beef Curry","Beef Curry", "Missing"), col=c("pink","red"),main="Proportion of Cases by Food Category")
legend("topleft", legend=c("Case", "Not Case"),fill=c("red","pink"))
##Exercise 3
eclair.eat<-ifelse(eclair>0 & eclair!=90, 1, ifelse(eclair==0, 0, NA))
riskratio(eclair.eat,case)
oddsratio(eclair.eat,case)
#Exercise 4. Based on the outbreak data, carry out an appropriate test and report the results for testing the hypothesis that people who drank water were more likely to get diarrhea than those who did not.
table(water[which(water != 9)],diarrhea[which(water !=9)])
##note that there are large enough sample sizes in each group to do a normal chi square test
water.cases<-length(which(diarrhea==1 & water==1))
no.water.cases<-length(which(diarrhea==1 & water==0))
cases.total<-c(water.cases, no.water.cases)
water.total<-length(which(water==1))
no.water.total<-length(which(water==0))
people.total<-c(water.total, no.water.total)
prop.test(cases.total, people.total, alternative="greater")
##OR alternatively you could do the following:
cases.water.matrix<-matrix(c(water.cases,nowater.cases,water.total-water.cases,nowater.total-nowater.cases),2,2)
chisq.test(cases.water.matrix)
#Exercise 5
age.alc.table<-tapply(ncases,list(agegp,alcgp),sum)
chisq.test(age.alc.table)
tab<-cbind(c(25,15),c(27,11))