coxmodelframe.coxph中的错误(对象):无效对象集x = true coxph中的true



以下示例是针对正在建立COX比例危害模型并试图产生预测错误曲线的任何人,但要获得错误说明:

coxmodelframe.coxph中的错误(对象):无效对象将x = true在coxph的呼叫中。

这是重现错误的代码:

library(survival)
library(survminer)
library(pec)
library(Hmisc)
library(rms)
library(riskRegression)
#install.packages("doMC", repos="http://R-Forge.R-project.org")
library(doMC)

数据

#Load and store the data
lcOrig <- read.csv("cancer.csv")
#Replace all the 1's with 0's (censored)
lcOrig$status <- gsub(pattern = "1", replacement = "0", x = lcOrig$status, fixed = TRUE)
#Replace all the 2's with 1's (death)
lcOrig$status <- gsub (pattern = "2", replacement = "1", x = lcOrig$status, fixed = TRUE)
#Do the same thing for sex (0 = Males, 1 = Females)
lcOrig$sex <- gsub(pattern = "1", replacement = "0", x = lcOrig$sex, fixed = TRUE)
lcOrig$sex <- gsub(pattern = "2", replacement = "1", x = lcOrig$sex, fixed = TRUE)
#Change the class of these variables to integer.
lcOrig$status <- as.integer(lcOrig$status)
lcOrig$sex <- as.integer(lcOrig$sex)
lcOrig$ph.ecog <- as.integer(lcOrig$ph.ecog)
#Remove missing values and column with over 20% missing data.
apply(lcOrig, 2, function(x) sum(is.na(x))/length(x))
lcOrig <- lcOrig[, c(1:9, 11)]
lc <- lcOrig[complete.cases(lcOrig), ]

COX比例危害

fitform1 <- Surv(time, status) ~ inst + age + sex + ph.ecog + ph.karno + pat.karno + wt.loss
cox1 <- coxph(fitform1, data = lc)

预测错误曲线

extends <- function(...) TRUE
library("doMC")
registerDoMC()
set.seed(0692)
fitpec1 <- pec(list("CPH" = cox1), data = lc, formula = fitform1, splitMethod = "cv10", B = 5, keep.index = TRUE, keep.matrix = TRUE)

最后一行代码会导致以下错误:coxmodelframe.coxph中的错误(对象):无效对象设置x = true在coxph

的呼叫中

解决方案

更改:

cox1 <- coxph(fitform1, data = lc)

to:

cox1 <- coxph(fitform1, data = lc, x = TRUE)

这不是2年前的要求,而是现在。我希望这有助于您节省一些时间!

相关内容

  • 没有找到相关文章

最新更新