从 glmnet 对象中提取基线风险函数 h0(t)
我想知道时间 t >> h(t,X) = h0(t) exp[Σ βi*Xi] 的风险函数。如何从 R 中的 glmnet 对象中提取基线危险函数 h0(t)?
我所知道的是,Survival Packages 中的函数“basehaz()”只能从 coxph 对象中提取基线危险函数。
我还发现了一个函数, glmnet.basesurv(time, event, lp, times.eval = NULL, centered = FALSE)
. 但是当我尝试使用这个功能时,出现了错误。
错误:找不到函数“glmnet.basesurv”
下面是我的代码,使用 glmnet 拟合 cox 模型并获得所选变量的系数。是否可以从这个 glmnet 对象中获取基线危险函数 h0(t)?
代码
# Split data into training data and testing data
set.seed(101)
train_ratio = 2/3
sample <- sample.int(nrow(x), floor(train_ratio*nrow(x)), replace = F)
x.train <- x[sample, ]
x.test <- x[-sample, ]
y.train <- y[sample, ]
y.test <- y[-sample, ]
surv_obj <- Surv(y.train[,1],y.train[,2])
#
my_alpha = 0.5
fit = glmnet(x = x.train, y = surv_obj, family = "cox",alpha = my_alpha) # fit the model with elastic net method
plot(fit,xvar="lambda", main="cox model coefficient paths(glmnet.fit)\n\n") # Plot the paths for the fit
fit
# cross validation to find out best lambda
cv_fit = cv.glmnet(x = x.train,y = surv_obj , family = "cox",nfolds = 10,alpha = my_alpha)
tencrossfit <- cv_fit$glmnet.fit
plot(cv_fit, main="Cross-validated Deviance(10 folds cv.glmnet.fit)\n\n")
plot(tencrossfit, main="cox model coefficient paths(10 folds cv.glmnet.fit)\n\n")
max(cv_fit$cvm)
summary(cv_fit$cvm)
cv_fit$lambda.min
cv_fit$lambda.1se
coef.min = coef(cv_fit, s = "lambda.1se")
pred_min_value2 <- predict(cv_fit, s=cv_fit$lambda.min, newx=x.test,type="link")
我非常感谢您能提供的任何帮助。