when i run coxph(Surv(Time, Status)~Class, data = df)
on data set like below it always sets the reference group by alphabetical order, in this case MutantA would be the reference group. Is there a way to tell it to make WT the reference group ?
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
Yes, you just need you change the order the levels in your factor column Class
by making WT
your first level:
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