我有一个具有时变连续曝光和时变三级分类变量的数据集。我想绘制从暴露的三次样条项及其与分类变量的每个级别的分类变量的相互作用中获得的风险比。我想在 R 中使用 rms 包。我该怎么做?
我的做法对吗
library(survival)
library(rms)
# Fit Cox proportional hazards model
model <- cph(Surv(time_start, time_end, composite_mace) ~ rcs(exposure,3) * category,
data =data, x=TRUE, y=TRUE)
p <- Predict(model, exposure, risk_cat, ref.zero = TRUE, fun = exp)
# Plot hazard ratios
ggplot(p, aes(x = exposure, y = label, ymin = lower, ymax = upper)) +
geom_pointrange(position = position_dodge(width = 0.8)) +
facet_wrap(~ category, nrow = 1) +
xlab("Exposure") +
ylab("Hazard ratio") +
ggtitle("Hazard ratios of exposure and interaction with categorical variable")
此外,我真的需要分类变量预测变量的参考类别吗?
我得到了结果,但我不确定我的方法是否正确