title: 使用替换系数法使coxnet-lasso兼容coxph的分析 tags: [] id: '1965' categories:
目前R中用于构建LASSO模型的包主要是glmnet,当我们确定λ后,该如何画列线图、森林图等常规COXPH回归常用的可视化方法呢?Memo_Cleon指出可以提取lasso的回归系数然后替换常规回归模型的系数。
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')
lasso.cf <- readRDS('../A_ref_A_fiig.3_A_B/lasso.cf.rds')
f1$coefficients <- lasso.cf[names(f1$coefficients),'coef']
res.cox$coefficients <- lasso.cf[names(res.cox$coefficients),'coef']
注意:coxph系数替换后其他量不会重新计算,基本没用