I am trying to calculate the restricted mean survival time grouped by the covariates but I get an error. Could you please have a look at the code example code below and let me know what the problem is?
library(survival)
library(flexsurv)
data <- survival::lung
formula <- Surv(data$time, data$status) ~data$sex
fsmodel_exponential<-flexsurvreg(formula,dist = "exp")
#Produces the expected results
rate_exponential<-fsmodel_exponential$res[1]
rmst_exp <- rmst_exp(t = 30, rate = rate_exponential, start = 0)
rmst_exp
#Gives error for the covariate
rate_exponential_sex<- fsmodel_exponential$res[2]
rmst_exp2 <- rmst_exp(t = 30, rate = rate_exponential_sex, start = 0)
rmst_exp2