# Chapter 10 R examples surgery = matrix(c(41,8,15,11), nrow=2) colnames(surgery) = c("Real", "Sham") rownames(surgery) = c("Success", "No Success") # For a directional test, need to divide the given P-value from chisq.test by 2 to get the real P-value: chisq.test(surgery, correct=FALSE) # The prop.test function gives you the P-value of the directional test directly: prop.test(surgery, correct=FALSE,alternative = "greater") testing = matrix(c(9,52,8,51), nrow=2) colnames(testing) = c("Female","Male") rownames(testing) = c("HIV Test", "No HIV Test") testing chisq.test(testing, correct=FALSE) # Fisher's exact test: flu = matrix(c(15,13,3,10), nrow=2) fisher.test(flu, alternative="greater") fisher.test(flu, alternative="two.sided") # To get the two-sided test, could simply type: fisher.test(flu) # Large-sample CI for p1-p2: success = c(274, 72) total = c(347, 298) prop.test(success, total, conf.level=0.95, correct=FALSE)