带偏移的flexsurv样条线

问题描述 投票:0回答:1

我正在尝试使用 R 中

flexsurvspline
内的偏移函数来强制回归系数的权重固定为 1。

我在 Windows PC 上通过 RStudio (2024.04.0) 使用 R 4.4.0。下面的代码适用于以前版本的 flexsurv,但自从我最近更新(版本 2.3)以来就不再工作了。

有效的代码是:

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)

错误信息是

model.matrix.default(forms[[i]], m) 中的错误: model.matrix() 中的模型框架和公式不匹配

如有任何建议,感激不尽!!!

r
1个回答
0
投票

谢谢你——确实如此!我已经两次尝试发布此感谢信息,所以希望这是第三次幸运!

再次感谢, 劳拉

© www.soinside.com 2019 - 2024. All rights reserved.