coxModelFrame.coxph(object)中的错误:对coxph的调用中无效的对象集x = TRUE

时间:2019-03-11 15:50:10

标签: survival-analysis cox-regression survival cox hazard

以下示例适用于正在构建Cox比例危害模型并尝试生成预测误差曲线但得到错误说明的任何人:

coxModelFrame.coxph(object)中的错误:无效的对象 在对coxph的调用中设置x = TRUE。

以下是重现该错误的代码:

图书馆

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(object)中的错误:无效的对象 在对coxph的调用中将x = TRUE设置

1 个答案:

答案 0 :(得分:1)

解决方案

更改:

cox1 <- coxph(fitform1, data = lc)

收件人:

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

2年前这不是以前的要求,但现在是。我希望这可以帮助您节省一些时间!