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

问题描述 投票:0回答:1

以下示例适用于构建Cox比例风险模型并尝试生成预测误差曲线的任何人,但会收到错误消息:

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

以下是重现错误的代码:

LIBRARIES

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

The Data

#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 Proportional Hazards

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

cox1 <- coxph(fitform1, data = lc)

PREDICTION ERROR CURVES

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

survival-analysis cox-regression survival cox hazard
1个回答
1
投票

SOLUTION

更改:

cox1 <- coxph(fitform1, data = lc)

至:

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

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

© www.soinside.com 2019 - 2024. All rights reserved.