简体   繁体   English

在R中绘制cox比例风险模型

[英]plotting cox proportional hazard model in R

I'm trying to plot a cox proportional hazard model in R. (or a logit model) I used the following code (which I copied from https://sites.google.com/site/daishizuka/toolkits/plotting-logistic-regression-in-r ) 我正在尝试在R中绘制一个cox比例风险模型(或logit模型)我使用了以下代码(我从https://sites.google.com/site/daishizuka/toolkits/plotting-logistic-复制了该代码回归r

c<-coxph(formula=Surv(year, promo)~prov.yrs, data=cul)
curve(predict(c, data.frame(prov.yrs=x), type="risk"), add=TRUE)

I get the error message 我收到错误消息

Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  invalid graphics state

I believe there is something wrong with plotting this, so I was wondering if there is a way to plot this. 我相信绘制这个有什么问题,所以我想知道是否有办法来绘制这个。 I get the same error message when I use glm. 当我使用glm时,我收到相同的错误消息。 Any help will be appreciated!! 任何帮助将不胜感激!!

The example you copied from shows a logistic regression, but you are fitting a coxph model, they are very different in how they are handled. 您复制的示例显示了逻辑回归,但您正在拟合一个coxph模型,它们在处理方式上有很大差异。

If you just want a plot of the the hazard ratio then your code will basically work (except you are adding to a plot that is not there, which may be what generates the error, try changing add to FALSE ). 如果您只想要一个风险比图,那么您的代码基本上可以工作(除非您添加到不存在的图,这可能是产生错误的图,尝试将add更改为FALSE )。

If you want to plot the survival curve(s) then use the survfit function to get the predicted survival information and plot that. 如果你想绘制生存曲线,那么使用survfit函数来获得预测的生存信息并绘制出来。

The error message suggests you did not have a device open or perhaps there was some other problem with the plot you were trying to add to? 错误消息表明您没有打开设备,或者您尝试添加的图表可能还有其他问题? That code produces a plot over a range input [0,1] with a toy example I built from the coxph help page. 该代码使用我在coxph帮助页面上构建的玩具示例在范围输入[0,1]上生成绘图。 Perhaps your range for the 'prov.yrs' is different than an existing plot, or there is no device open? 也许你的'prov.yrs'的范围与现有的情节不同,或者没有设备打开? Try plot.new() , plot whatever else you were going to use, and then rerun? 尝试plot.new() ,绘制你要使用的其他内容,然后重新运行? (The add=TRUE will suppress plotting of the box, axes and labels.) (add = TRUE将禁止绘制框,轴和标签。)

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

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