我正在R上运行prop.test。这是列联表和prop.test的输出。 “ a”是数据帧的名称。 “ cluster”和“ AD_2”是两个二分变量。
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
从列联表中可以看出,样本估计值的条件是AD_2为“否”,即0.7659176 = 1227 /(1227 + 375)和0.6515513 = 546 /(546 + 292)。作为a $ cluster == pos阳性事件,而AD_2 == yes是危险因素,我想将AD_2的比例条件设为“是”。
答案 0 :(得分:1)
R表本质上是矩阵。 `prop.test函数可以处理矩阵,因此在切换列时使用相同的数据:
> 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
我认为另一种方法可能是将列交换为:
table(a$cluster,a$AD_2)[ , 2:1]