I have a survival dataset where time
and status
variable are given along with some survival probabilities at (say) time = 12
, calculated based on some indices for each individual in the dataset. Now, I would like to calculate the brier scores for each index in the dataset and choose the best one. Here is my sample code:
set.seed(99)
library(dplyr)
library(survival)
library(prodlim)
library(pec)
# simulated survival data data
data <- SimSurv(100)
# add two incides
data$index1<-runif(100, 0.4, 0.9)
data$index2<-runif(100, 0.5, 1)
I tried the following using pec
package in R .
# let's try for one index
models<-as.matrix(data$index1)
# try pec package, which provides brier score
PredError <- pec(object=models,
formula = Surv(time, status)~1, cens.model="marginal",
data=data, verbose=F, maxtime=200, times = 12)
But I got the following error message:
Error in predictSurvProb.matrix(object = c(0.596092602680437, 0.675279439869337, :
Prediction matrix has wrong dimensions:
Requested newdata x times: 100 x 102
Provided prediction matrix: 100 x 1
Anyone has any suggestion on how to resolve the issue?
While using matrix as object times argument is adjusted inside the function so if you change the times argument to zero and exact to FALSE, code runs successfully.
models <- as.matrix(data$index1)
PredError <- pec(object = models, formula = Surv(time, status) ~ 1, cens.model = "marginal", data = data, verbose = T, maxtime = 200, times = 0, exact = FALSE)
Also if you change the object to other type except matrix then the code works fine.
For example
models <- list("Cox.X1" = coxph(Surv(time, status) ~ index1, data = data, x = TRUE, y = TRUE))
PredError <- pec(object = models, formula = Surv(time, status) ~ 1, cens.model = "marginal", data = data, verbose = T, maxtime = 200, times = 12)
For details regarding the object argument please refer below statement:
A named list of prediction models, where allowed entries are (1) R-objects for which a predictSurvProb method exists (see details), (2) a call that evaluates to such an R-object (see examples), (3) a matrix with predicted probabilities having as many rows as data and as many columns as times. For cross-validation all objects in this list must include their call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.