丁香实验_LOGO
登录
提问
我要登录
|免费注册

R语言用psm构建完nomogram后画校准曲线时报错

相关实验:滴定曲线实验

user-title

月影逝水

代码

#nomogram构建

rm(list=ls())

library(Hmisc)

library(grid)

library(lattice)

library(Formula)

library(ggplot2)

library(rms)

library(survival)

load('shuchushuju^_ph.Rdata')

ph=no_ph

#变量赋值

gender=ph$gender

age=ph$age

T=ph$T

OS.time=ph$OS.time

OS=ph$OS

riskScore=ph$riskScore

 

 

y=Surv(OS.time,OS)

ddist=datadist(age,gender,T,riskScore)

options(datadist='ddist')

f=psm(y~gender+age+T+riskScore,dist='lognormal')

surv=Survival(f)

pdf(file = 'nomogram.pdf',width=6,height=5)

nomogram=nomogram(f,fun=list(function(x)surv(1,x),function(x)surv(3,x)),

         funlabel = c('1-year Survival Probability','3-year Survival Probability'))

plot(nomogram,xfrac=.7)

dev.off()

 

#校准曲线

cal=calibrate(f,method = 'boot',B=1000)

报错

Error in survest.psm(fit, times = u, conf.int = FALSE)$surv : 

 $ operator is invalid for atomic vectors

wx-share
分享

2 个回答

user-title

loveliufudan

有帮助

根据您提供的代码,您可能是因为没有正确调用survest.psm()函数,导致在进行预测生存曲线时出现了错误。可以尝试以下更改代码:

#nomogram构建

rm(list=Is())

library (Hmisc)

library (grid)

library(lattice)

library (Formula)

library (ggplot2)

library(rms)

library (survival)

load('shuchushuju^ _ph.Rdata')

ph=no ph

#变量赋值

gender=ph$gender

age=ph$age

T=ph$T

OS.time=ph$OS.time

OS=ph$OS

riskScore=ph$riskScore

y=Surv(OS.time,OS)

ddist=datadist(age,gender,T,riskScore)

options(datadist='ddist')

f=psm(y~gender+age+T+riskScore,dist='lognormal')

surv=Survival(f)

pdf(file = 'nomogram.pdf',width=6,height=5)

nomogram=nomogram(f,fun=list(function(x)surv (1,x),function(x)surv(3,x)),

funlabel = c('1-year Survival Probability', '3-year Survival Probability'))

plot(nomogram, xfrac=.7)

dev.off()

#校准曲线

cal=calibrate(f, method = 'boot', B = 1000)

#绘制校准曲线

plot(cal, xlab = 'Predicted Probabilities', ylab = 'Observed Probabilities',

ylim = c(0, 1), xlim = c(0, 1), col = 'red')

abline(a = 0, b = 1, lty = 2, lwd = 2)

在校准曲线绘制中,需要调用calibrate()函数,并使用返回的结果进行绘制。绘制校准曲线的代码应该位于 dev.off()之后。请注意,您可能需要修改xlab和ylab以适应您的数据。



user-title

土井挞克树

有帮助

校准曲线格式输入不对,转换一下格式。

提问
扫一扫
丁香实验小程序二维码
实验小助手
丁香实验公众号二维码
扫码领资料
反馈
TOP
打开小程序