glmnetオブジェクトからベースラインハザード関数h0(t)を抽出する
時刻t >> h(t、X)= h0(t)exp [Σβi* Xi]でハザード関数を知りたい。 Rのglmnetオブジェクトからベースラインハザード関数h0(t)をどのように抽出できますか?Rのglmnetオブジェクトからベースラインハザード関数h0(t)を抽出するには?
私が知っていることは、Survival Packagesの "basehaz()"関数が、coxphオブジェクトからのベースラインハザード関数を抽出できるということです。
私はまた、関数glmnet.basesurv(time, event, lp, times.eval = NULL, centered = FALSE)
を見つけました。しかし、この関数を使用しようとすると、エラーが発生します。
Error: could not find function "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")
私は本当にあなたが提供することができます任意の助けに感謝。
ありがとうございました。私はhdnomパッケージをインストールしましたが、まだ動作しません。 glmnet.basesurv(時間、イベント、プレ_min_value2、times.eval = 30、中央揃え= FALSE) エラー:「glmnet.basesurv」機能を見つけることができませんでした 他のパッケージをインストールする必要がありますか? このウェブページ(https://www.rdocumentation.org/packages/hdnom/versions/4.6)からglmnet.basesurv関数を見つけるのは奇妙です。 –