prop.test,调整其他课程

问题描述 投票:0回答:1

我在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)。作为$ cluster == pos积极事件和AD_2 ==是风险因素,我想将AD_2上的比例调整等于'是'。

r chi-squared
1个回答
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]
© www.soinside.com 2019 - 2024. All rights reserved.