[R] flexsurvspline with offset

Bonnett, Laura |jbcm@he @end|ng |rom ||verpoo|@@c@uk
Tue May 14 14:15:23 CEST 2024


Dear all,

I am using R 4.4.0 via RStudio (2024.04.0) on a Windows PC.  The code below worked on the previous version of the flexsurv but is not working since my recent update (version 2.3).

The code that was working is:

library(survival)

rfs  <- pmax(rotterdam$recur, rotterdam$death)
rfstime <- with(rotterdam, ifelse(recur==1, rtime, dtime))
fit1 <- flexsurvspline(Surv(rfstime, rfs) ~ age + meno + size + er,  k=2, data = rotterdam)

# obtain the linear predictor for each patient
predf <- model.matrix(fit1) %*% fit1$res[-(1:4),"est"]

# Predict baseline survival at 5 years
y5_Flex_1 <- summary(fit1,type="survival",t=5)
y5_Flex <- y5_Flex_1[[1]]$est
y5_Flex

# Shrinkage factor
vanH <- 0.9589255
heuristic_lp_flex = vanH*predf      

# Now calculate the shrunken model baseline survival prob at 5 years by fixing the shrunken lp as an offset and predicting the baseline survival
fit1_shrunk <- flexsurvspline(Surv(rfstime,rfs)~offset(heuristic_lp_flex),k=2,data=rotterdam)

The error message is
Error in model.matrix.default(forms[[i]], m) :
  model frame and formula mismatch in model.matrix()

Any suggestions gratefully received!!!

Kind regards,
Laura

	[[alternative HTML version deleted]]



More information about the R-help mailing list