[R] Glmnet survival cox predict
Amir Hadanny
@m|r@h@d @end|ng |rom gm@||@com
Fri Nov 15 19:49:52 CET 2019
Hi all,
i'm trying to get the prediction probabilities for a survival elastic net.
When i use try to predict using the train model on the test set, it creates
an object with the number rows of the train data (6400 rows) instead of the
test data (2400 rows). I really don't understand why, and that doesn't let
me check for performance c-index.
the code:
data<-read.csv("old4.csv", header=TRUE)
library(imputeMissings)
data<-impute(data,object = NULL ,method = "median/mode")
trainstatus<-train$DIED1095
trainTime<-train$TIME
y<-Surv(trainTime,trainstatus)
trainX<-train[-c(12,63,64,65,66,67,68,69,70,71)]
x<-data.matrix(trainX)
library(glmnet)
fit <- glmnet(x,Surv(trainTime,trainstatus),family="cox",alpha=0.1,
,maxit=10000)
max.dev.index <- which.max(fit$dev.ratio)
optimal.lambda <- fit$lambda[max.dev.index]
optimal.beta <- fit$beta[,max.dev.index]
nonzero.coef <- abs(optimal.beta)>0
selectedBeta <- optimal.beta[nonzero.coef]
selectedTrainX <- x[,nonzero.coef]
coxph.model<- coxph(Surv(train$TIME,train$DIED365) ~x,data=train,
init=selectedBeta,iter=0)
coxph.predict<-predict(coxph.model,test)
nrow(test)
2872
nrow(train
6701
length(coxph.predict)
6701
[[alternative HTML version deleted]]
More information about the R-help
mailing list