月影逝水
代码
#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
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以适应您的数据。
土井挞克树
校准曲线格式输入不对,转换一下格式。
相关产品推荐