I'm unsure why I do not get standard errors or confidence intervals when I fit parametric survival models and compute the predicted mean survival times using the avg_predictions().
I tried using different parametric distributions as well out of curiosity and that didn't change anything.
I run the following code:
library(survival)
library(flexsurv)
library(marginaleffects)
data(lung)
# fit flexible parametric survival model
fmodel1 <- list(
"Weibull" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "weibull"),
"Gamma" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "gamma"),
"Gengamma" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "gengamma"),
"llogis" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "llogis"),
"llnorm" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "lognormal"),
"gompertz" = flexsurvreg(Surv(time, status) ~ factor(sex), data = lung, dist = "gompertz")
)
# using marginaleffects with flexsurv
avg_predictions(fmodel1$Weibull, variables = "sex")
Below is the result I get:
sex Estimate Std. Error z Pr(>|z|) S 2.5 % 97.5 %
1 331 NA NA NA NA NA NA
2 490 64.5 7.6 <0.001 44.9 363 616
Columns: sex, estimate, std.error, statistic, p.value, s.value, conf.low, conf.high
Type: response
I'm unsure why this produces NAs for all uncertainty estimates for the reference level of the sex
variable.