[R] Glmnet survival cox predict
dw|n@em|u@ @end|ng |rom comc@@t@net
Fri Nov 15 23:00:17 CET 2019
On 11/15/19 10:49 AM, Amir Hadanny wrote:
> 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.
If you call most `predict` functions with a second argument that fails
to contain the predictors in the model, it returns the predictions on
the original data. The only place where the `test` object appears prior
to the predict operation is in your call to `predict.coxph`, so my guess
is that it fails to meet the requirements of the function for a valid
newdata argument. (Another thought was that maybe `test` didn't exist,
but that should have thrown an error with the predict call and the nrow
But since you don't provide code that creates `test` or even an
unambiguous way of examining its structure, that is entirely a guess.
And finally ... Rhelp is a plain text mailing list, so please to read
the message at the bottom of every transmission from the mailserver ...
i.e. read the Posting Guide. (It is not at all difficult to get
gmail.com to send plain text.)
> the code:
> data<-read.csv("old4.csv", header=TRUE)
> data<-impute(data,object = NULL ,method = "median/mode")
> fit <- glmnet(x,Surv(trainTime,trainstatus),family="cox",alpha=0.1,
> 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,
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help