使用替换系数法使coxnet-lasso兼容coxph的分析

目前R中用于构建LASSO模型的包主要是glmnet,当我们确定λ后,该如何画列线图、森林图等常规COXPH回归常用的可视化方法呢?Memo_Cleon指出可以提取lasso的回归系数然后替换常规回归模型的系数。

导出lasso系数

1
2
3
4
5
6
7
lasso <- glmnet(x = x, y = y, family = 'cox', alpha = 1)
set.seed(0)
lasso.cv <- cv.glmnet(x,y,family="cox", alpha=1,nfolds=10, type.measure = 'C')
lasso.cf <- coef(lasso.cv, s="lambda.1se")
lasso.cf <- as.data.frame(as.matrix(lasso.cf))
names(lasso.cf) <- 'coef'
saveRDS(lasso.cf, 'lasso.cf.rds')

替换rms包的cph结果的系数

1
2
lasso.cf <- readRDS('../A_ref_A_fiig.3_A_B/lasso.cf.rds')
f1$coefficients <- lasso.cf[names(f1$coefficients),'coef']

替换survival包的coxph结果的系数

1
res.cox$coefficients <- lasso.cf[names(res.cox$coefficients),'coef']

注意:coxph系数替换后其他量不会重新计算,基本没用


使用替换系数法使coxnet-lasso兼容coxph的分析
https://b.limour.top/1965.html
Author
Limour
Posted on
August 11, 2022
Licensed under