Brenda Carolina
Brenda Carolina

Reputation: 137

brier function from survival library is not working on my cox model

I've been trying to compute brier score for several time points in order to make a plot of this metric but brier function from survival package is not working. Please see below my code:

library(haven)
library(dplyr)
library(rsample)
library(survival)

location <- "https://www.cancerdata.org/system/files/publications/Stage3_anonymized.sav"
dataset  <-  read_sav(location)
# Replace values with labels
raw.dat <- zap_labels(dataset)


# import data
pre.dat <- raw.dat %>%
  mutate(age             = as.numeric(gsub(",", ".", age)),
         bmi             = as.numeric(gsub(",", ".", bmi)),
         eqd2            = as.numeric(gsub(",", ".", eqd2)),
         fev1pc_t0       = as.numeric(gsub(",", ".", fev1pc_t0)),
         eqd2            = as.numeric(gsub(",", ".", eqd2)),
         gtv1            = as.numeric(gsub(",", ".", gtv1)),
         tumorload_total = as.numeric(gsub(",", ".", tumorload_total)),
         survmonth       = as.numeric(gsub(",", ".", survmonth)),
         survyear        = as.numeric(gsub(",", ".", survyear)), 
         group           = as.integer(gsub(",", ".", group)))

final.dat <- pre.dat %>%
  mutate(

         dumsmok2        = relevel(factor(dumsmok2), ref="1"),
         t_ct_loc        = relevel(factor(t_ct_loc), ref="1"),
         tstage          = relevel(factor(tstage), ref="1"),
         nstage          = relevel(factor(nstage), ref="1"),
         stage           = relevel(factor(stage), ref="1"),
         timing          = relevel(factor(timing), ref="1"),
         group           = relevel(factor(group ), ref="1"),
         age.cat         = relevel(factor(case_when(age <=70 ~ "<=70",
                                                    age > 70 ~ "70+")), ref="<=70"), 
         ott.cat         = relevel(factor(case_when(ott <=28 ~ "<=28",
                                                    ott > 28 ~ "28+")), ref="<=28"),
         histology       = relevel(factor(case_when(hist4g  == 1 ~ "SCC",
                                                    hist4g  == 2 ~ "Adenocarcinoma",
                                                    hist4g  == 3 ~ "Large cell carcinoma",
                                                    hist4g  == 4 ~ "Other",
                                                    is.na(hist4g) ~ "Unknown")), ref="SCC"), 
         plns            = relevel(factor(case_when(countpet_all6g  == 1 ~ "0", 
                                                    countpet_all6g  == 2 ~ "1",
                                                    countpet_all6g  == 3 ~ "2",
                                                    countpet_all6g  == 4 ~ "3",
                                                    countpet_all6g  >=5 ~  "4+")), ref="0"),
         who.ps           = relevel(factor(case_when(who3g  == 1 ~ "0",  
                                                     who3g  == 2 ~ "1",
                                                     who3g  == 3 ~ "2+")), ref="0")
         
         )

lung.split <- final.dat  %>%
  initial_split(prop = 0.8, strata = "deadstat")
train.data <- training(lung.split)
test.data  <- testing(lung.split)


# cox modeling
cox.model.final <- coxph(Surv(survmonth, deadstat) ~ age.cat + gender + who.ps + 
                           tstage + gtv1 + plns + ott.cat + 
                           eqd2 + strata(group), data = train.data)
summary(cox.model.final)

# look at some time points
time.points <- seq(0.1,1,0.1)

brier(cox.model.final, time.points)

I got this error

# Error in p1[i, ] : incorrect number of dimensions

My idea is to plot eventually in the x-axis the time and in the y-axis the corresponding brier score computed at that time. Any ideas on how to solve this issue? I also tried the function "Brier" from SurvMetrics library but I got other errors.

Upvotes: 0

Views: 39

Answers (0)

Related Questions