FcmC
FcmC

Reputation: 143

prop.test, conditioning on the other class

I am running prop.test on R. Here are the contingency table and the output of the prop.test. 'a' is the name of the data frame. 'cluster' and 'AD_2' are two dichotomic variables.

 table(a$cluster,a$AD_2)

         no  yes
   neg 1227  375
   pos  546  292

 prop.test(table(a$cluster,a$AD_2))

    2-sample test for equality of proportions with continuity 
 correction

data:  table(a$cluster, a$AD_2)
X-squared = 35.656, df = 1, p-value = 2.355e-09
alternative hypothesis: two.sided
95 percent confidence interval:
0.07510846 0.15362412
sample estimates:
   prop 1    prop 2 
0.7659176 0.6515513

Sample estimates are conditioned on AD_2 being 'no' as can been seen from the contingency table, i.e. 0.7659176 = 1227/(1227+375) and 0.6515513 = 546/(546+292). Being a$cluster==pos the positive event and AD_2==yes the risk factor, I would like to reverse the proportions conditioning on AD_2 equal to 'yes'.

Upvotes: 0

Views: 271

Answers (1)

IRTFM
IRTFM

Reputation: 263451

R tables are essentially matrices. The `prop.test function can handle matrices, so use the same data with the columns switched:

> prop.test( matrix(c( 375,292,1227,546), 2))

    2-sample test for equality of proportions with continuity correction

data:  matrix(c(375, 292, 1227, 546), 2)
X-squared = 35.656, df = 1, p-value = 2.355e-09
alternative hypothesis: two.sided
95 percent confidence interval:
 -0.15362412 -0.07510846
sample estimates:
   prop 1    prop 2 
0.2340824 0.3484487 

I think another method might have been to swap the columns with:

table(a$cluster,a$AD_2)[ , 2:1]

Upvotes: 1

Related Questions