多因素cox回歸分析reference的問題

別人的例子

image.png
image.png

自己的例子

只是轉(zhuǎn)換變量為因子

library(dplyr)
library(forcats)
library(survival)

N <- 20
df <- data.frame(
  time=rexp(N),
  event=as.integer(rbinom(N, 1, .5)),
  treatment_=c(rep("control", N/2), rep("active", N/2)))

str(df)
df$treatment_=factor(df$treatment_,levels = c("active","control"))

#In the model summary below, exp(coef) for "treatment_control" is the hazard ratio of control:active , where active is the "reference" since it is alphabetically before "control"
cox1 <- coxph(Surv(time, event) ~ treatment_, data=df)
print(cox1)
# Call:
#   coxph(formula = Surv(time, event) ~ treatment_, data = df)
# 
# coef exp(coef) se(coef)     z     p
# treatment_control 0.3021    1.3527   0.6885 0.439 0.661
# 
# Likelihood ratio test=0.19  on 1 df, p=0.6593
# n= 20, number of events= 9


## reverse
df$treatment_=factor(df$treatment_,levels = c("control","active"))

#df$treatment_  <- df$treatment_ %>% as.factor() %>% forcats::fct_rev()
cox2 <- coxph(Surv(time, event) ~ treatment_, data=df)
print(cox2)


# Call:
#   coxph(formula = Surv(time, event) ~ treatment_, data = df)
# 
# coef exp(coef) se(coef)      z     p
# treatment_active -0.3021    0.7393   0.6885 -0.439 0.661
# 
# Likelihood ratio test=0.19  on 1 df, p=0.6593
# n= 20, number of events= 9 

HR=exp(coef)

設(shè)置因子為0和1

## set 0,1
df$treatment_class=ifelse(df$treatment_ =="control",1,2)
## df$treatment_class=factor(df$treatment_class,levels = c(1,2)) ## not run
cox3 <- coxph(Surv(time, event) ~ treatment_class, data=df)
print(cox3)
# 
# Call:
#   coxph(formula = Surv(time, event) ~ treatment_class, data = df)
# 
# coef exp(coef) se(coef)      z     p
# treatment_class2 -0.3021    0.7393   0.6885 -0.439 0.661
# 
# Likelihood ratio test=0.19  on 1 df, p=0.6593
# n= 20, number of events= 9

總的對比來說,如果變量改成1和2,reference一般是1的那個,如果設(shè)置了factor,那一般是左邊那個。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容