# R analysis of 2 by 2 tables # Inference for the difference of two proportions (independent samples) # We use the Christmas tree data given in class ## 95% CI for pi_1 - pi_2: # We can specify the number of successes and the sample sizes for each sample: prop.test(c(64,89), n=c(160,261), conf.level=0.95, correct=FALSE)$conf.int # Or we can equivalently specify the number of successes and # number of failures for each sample: prop.test(matrix(c(64,89,96,172),nrow=2,ncol=2,byrow=FALSE), conf.level=0.95, correct=FALSE)$conf.int ## Testing for a difference between pi_1 and pi_2: # We can specify the number of successes and the sample sizes for each sample: prop.test(c(64,89), n=c(160,261), alternative="two.sided", correct=FALSE) # Or we can equivalently specify the number of successes and # number of failures for each sample: prop.test(matrix(c(64,89,96,172),nrow=2,ncol=2,byrow=FALSE), alternative="two.sided", correct=FALSE) ######################################################################### # Small-sample inference for the difference of two proportions (independent samples) # Can use Fisher's exact test with the fisher.test() function in R: fisher.test(matrix(c(1,4,5,2),nrow=2,ncol=2,byrow=FALSE), alternative = "less", conf.int = FALSE) # P-value given as 0.1212. # 95% CI for odds ratio: fisher.test(matrix(c(1,4,5,2),nrow=2,ncol=2,byrow=FALSE), conf.int = TRUE, conf.level=0.95)