> ## Comparing two proportions ## > > # Table 2.3, p. 27 (attack v. no attack) > > x<-c(189,104) # placebo, aspirin, > n<-c(11034,11037) > > # test H0:p1=p2 (equal probabilities of heart attack) > prop.test(x,n,p=c(.5,.5)) 2-sample test for given proportions with continuity correction data: x out of n, null probabilities c(0.5, 0.5) X-squared = 20911.98, df = 2, p-value < 2.2e-16 alternative hypothesis: two.sided null values: prop 1 prop 2 0.5 0.5 sample estimates: prop 1 prop 2 0.01712887 0.00942285 > prop.test(x,n) 2-sample test for equality of proportions with continuity correction data: x out of n X-squared = 24.4291, df = 1, p-value = 7.71e-07 alternative hypothesis: two.sided 95 percent confidence interval: 0.004597134 0.010814914 ## contains only positive values sample estimates: ## ==> taking aspirin appears to result in a diminished risk of heart attack (MI). prop 1 prop 2 0.01712887 0.00942285 > # Test H0:p1=p2 v. H1:p1>p2 > prop.test(x,n,alt="greater") 2-sample test for equality of proportions with continuity correction data: x out of n X-squared = 24.4291, df = 1, p-value = 3.855e-07 alternative hypothesis: greater 95 percent confidence interval: 0.005082393 1.000000000 sample estimates: prop 1 prop 2 0.01712887 0.00942285 > > # sample difference of proportions: > temp<-prop.test(x,n) > names(temp$estimate)<-NULL # optional > temp$estimate[[1]]-temp$estimate[[2]] [1] 0.007706024 ## very small ==> makes it seem as if the two groups differ by a trivial amount. > > # relative risk > temp$estimate[[1]]/temp$estimate[[2]] [1] 1.817802 ## The sample % of MI cases was 82% higher for the group taking placebo. > ## ==> the difference may have important public health implications. > # odds ratio > x[1]*(n[2]-x[2])/(x[2]*(n[1]-x[1])) [1] 1.832054 ## The estimated odds of MI for group taking placebo equal 1.83 times that for group taking aspirin ==> the estimated odds of MI were 83% higher for the placebo group. > # Table 2.4, p. 32 (Smoker v.s MI) > > x<-c(172,173) # smoker, non-smoker > n<-c(262, 519) > > # test H0:p1=p2 (equal probabilities of ........ ) > prop.test(x,n,p=c(.5,.5)) 2-sample test for given proportions with continuity correction data: x out of n, null probabilities c(0.5, 0.5) X-squared = 82.0439, df = 2, p-value < 2.2e-16 alternative hypothesis: two.sided null values: prop 1 prop 2 0.5 0.5 sample estimates: prop 1 prop 2 0.6564885 0.3333333 > # Test H0:p1=p2 v. H1:p1>p2 > prop.test(x,n,alt="greater")$p.value [1] 8.67911e-18 > > # odds ratio > temp<-prop.test(x,n) > names(temp$estimate)<-NULL # optional > x[1]*(n[2]-x[2])/(x[2]*(n[1]-x[1])) [1] 3.822222 >