简体   繁体   English

风险比 Plot 来自 mgcv::gam cox.ph model

[英]Hazard Ratio Plot from mgcv::gam cox.ph model

I am navigating through different packages that let fit non-linear predictors in the context of COX PH models.我正在浏览不同的包,这些包可以在 COX PH 模型的上下文中拟合非线性预测变量。

However, I was looking to produce plots to represent the non-linear relationship between a continuous predictor and the risk (Hazard Ratio) of an event in a survival analysis.但是,我一直在寻找生成图来表示连续预测变量与生存分析中事件的风险(风险比)之间的非线性关系。 While I was able to do easily with the rms package, I was looking to produce a similar plot using mgcv .虽然我能够轻松地使用rms package,但我希望使用mgcv

Here is a toy example using colon database in survival .这是一个在survival中使用colon数据库的玩具示例。

library(rms)
library(survival)
library(mgcv)

dd <- datadist(colon)
options(datadist="dd")

#Using rms
rms.spline <- cph(Surv(time, status) ~ rcs(age,3), data=colon)
ggplot(rms::Predict(cph.spline, age=seq(40,80, by=1), fun=exp)) 

Here's the output, which is quite what's I have in mind:这是 output,这正是我的想法: 在此处输入图像描述

Then with the mgcv package:然后使用 mgcv package:

gam.model <-gam(time ~ s(age), data=colon, family="cox.ph", weights=status)
plot(gam.model)

And the output:和 output:

在此处输入图像描述

It is clear that this time the plot is not representing the predictor against the Hazard Ratio, and I had a very hard time in figuring out a) what actually the y axis in this plot represent (I suppose log-hazard?), and b) how to plot the predictor against HR instead.很明显,这次 plot 不代表风险比的预测变量,我很难弄清楚 a) 这个 plot 中的 y 轴实际上代表什么(我想是对数风险?),和 b ) 如何将 plot 改为针对 HR 的预测变量。

I believe that you are correct that it is plotting the log of the hazard ratio.我相信你是正确的,它正在绘制风险比的对数。 Here is a way to plot it in the original coordinates using base R. Modification for ggplot would be straightforward.这是使用基数 R 在原始坐标中将其变为 plot 的方法。对 ggplot 的修改将很简单。 Often, you can use type="response" in the predict call, but this does not work for the Cox PH family in gam.通常,您可以在预测调用中使用 type="response",但这不适用于 gam 中的 Cox PH 系列。

age = seq(40, 80, 1)
y = predict(gam.model, newdata = data.frame(age=age), se.fit=TRUE)
plot(age, exp(y$fit), ylim=c(.8, 1.3))
lines(age, exp(y$fit + 1.96 * y$se.fit))
lines(age, exp(y$fit - 1.96 * y$se.fit))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM