设置使用R中的coxph函数计算的危险比的参考组

时间:2018-04-27 19:50:29

标签: r cox-regression

当我在下面的数据集上运行coxph(Surv(Time, Status)~Class, data = df)时,它总是按字母顺序设置参考组,在这种情况下,MutantA将是参考组。有没有办法告诉它让WT成为参考组?

df

Time    Status  Class
3   1   WT
4   1   WT
5   1   WT
7   1   WT
7   1   WT
7   1   WT
7   1   WT
2   1   WT
2   1   WT
2   1   WT
5   1   WT
6   1   WT
7   1   WT
8   1   MutantA
9   1   MutantA
2   1   MutantA
12  1   MutantA
3   1   MutantA
4   1   MutantA
5   1   MutantA
7   1   MutantA
7   1   MutantA
7   1   MutantA
7   0   MutantA
2   1   MutantA
2   1   MutantA
2   1   MutantA
5   1   MutantB
6   0   MutantB
7   1   MutantB
8   1   MutantB
9   1   MutantB
2   1   MutantB
12  1   MutantB
3   1   MutantB
4   0   MutantB
5   1   MutantB
7   1   MutantB
7   0   MutantB
7   1   MutantB
7   0   MutantB
2   1   MutantB
2   1   MutantB
2   1   MutantB
5   1   MutantB
6   1   MutantC
7   1   MutantC
8   1   MutantC
9   1   MutantC
2   1   MutantC
12  1   MutantC
11  1   MutantC
4   1   MutantC
3   1   MutantC
6   1   MutantC
7   1   MutantC
11  1   MutantC
3   1   MutantC
2   1   MutantC
6   1   MutantC

1 个答案:

答案 0 :(得分:2)

是的,您只需要通过将Class作为第一级别来更改因子列WT中的级别的顺序:

df$Class <- factor(df$Class, levels = c("WT","MutantA","MutantB","MutantC"))
# or using Gregor's comment:
df$Class = relevel(df$Class, ref = "WT")
coxph(Surv(Time, Status)~Class, data  = df)

Call:
coxph(formula = Surv(Time, Status) ~ Class, data = df)

               coef exp(coef) se(coef)     z     p
ClassMutantA -0.557     0.573    0.406 -1.37 0.171
ClassMutantB -0.688     0.503    0.395 -1.74 0.082
ClassMutantC -0.689     0.502    0.401 -1.72 0.085