I want to get predictions for the lung dataset available from penalized R package using the coxph R function for Cox proportional hazard model.
I have the following example code.
library(survival)
library(pec)
library(penalized)
data("lung")
data <- lung
trainind <- sample(1:n,n*0.7)
testind <- (1:n)[-trainind]
frm <- as.formula(paste("Surv(time, status)~",paste(names(data[,-c(2,3)]), collapse="+")))
cox <- coxph(frm,data=data[trainind,])
PredError <- pec(list(Cox=cox),Hist(time,status)~1,data=data[testind,])
I get the following error from the above
Error in UseMethod("predictEventProb", object) : no applicable method for 'predictEventProb' applied to an object of class "coxph"
Can someone solve this problem?
Two problems must be addressed in the
data
dataset:- delete (or impute) missing values
- recode
status
variable as 0 and 1