4
$\begingroup$

I have a medical database containing 7 input variables (4 are binary) and a binary outcome variable (Survival: yes/no). My objective is to train and test an algorithm that predict probability of survival (not a binary output).

I used nnet package. But it returned for me a binary output (using "raw" and "class" type). Which method can i use? Is there any R CRAN Packages to predict probability of survival using neural networks or others machine learning algorithms?

Thank you very much

$\endgroup$
  • $\begingroup$ Are you perhaps interested in the pros & cons of different ML algorithms for situations like this? Note that CV is not an R Q&A site (you may want to read our FAQ). Regarding your outcome variable, do you have survival durations or just yes / no? Might there be any censoring? $\endgroup$ – gung - Reinstate Monica Nov 22 '12 at 22:41
  • $\begingroup$ I have both. but my primer y outcome is 1-year-survival. $\endgroup$ – user1594303 Nov 23 '12 at 4:58
6
$\begingroup$

I like to use the caret package for predictive modeling, as it provided a unified interface to a variety of algorithms, including nnet. It's very easy to get predicted probabilities for any model that supports them, neural networks included:

set.seed(42)
require(caret)
model <- train(Species~., data=iris, method='nnet', 
               trControl=trainControl(method='cv'))
model
probs <- predict(model, iris, type='prob')
head(probs)
     setosa versicolor    virginica
1 0.9881512 0.01143536 0.0004134043
2 0.9839565 0.01550938 0.0005341130
3 0.9866016 0.01293839 0.0004599962
4 0.9820605 0.01735453 0.0005849775
5 0.9884653 0.01113064 0.0004040207
6 0.9875201 0.01204961 0.0004302507
$\endgroup$
  • $\begingroup$ Hello! Thank you for this example. I had a problem with the predict() step because it showed Error in eval(expr, envir, enclos) : object 'Id1002025' not found. I can't move on since I haven't found a solution to this and I want to simulate OP's goal for multi-time survival predictions. $\endgroup$ – Saggy Manatee And Swan Folk Jan 3 '14 at 20:30
  • 1
    $\begingroup$ @llorgge Very odd. I am getting the same error when I re-run this code. One of the newer versions of caret must have introduced a bug. Oddly, if I try other methods (e.g. rpart or glm instead of nnet) I get the same error. It must be a problem with the predict function in caret. $\endgroup$ – Zach Jan 3 '14 at 20:40
  • 1
    $\begingroup$ @llorgge I changed the example to use the iris dataset. It would appear there is a very specific bug in caret when using the formula interface for classification models that contain factors. $\endgroup$ – Zach Jan 3 '14 at 21:01
  • 1
    $\begingroup$ @llorgge You should probably post a separate question, with a reproducible example. I'm not sure caret works with survival data. $\endgroup$ – Zach Jan 3 '14 at 21:20
  • 1
    $\begingroup$ @HaskellFun It does take a test set. see ?predict.train. I updated my answer to demonstrate. $\endgroup$ – Zach Apr 28 '16 at 13:06
3
$\begingroup$

I would second the recommendation of an "ensemble" method such as Random Forests. There is a variant of RF, "randomSurvivalForest" that is specific to survival analysis. Here is a link to the the R manual for the package randomSurvivalForest.

$\endgroup$
0
$\begingroup$

you can try for example the glm function with the family=binomial and the logit link (or the probit) doing a logistic regression, which outputs are probabilitys.. Here you have a link logistic regression R

You also can try with trees or with "ensembles" of trees , boosting, bagging or random forest wuth packages like rpart ,randomForest etc If your dependent variable is 1/0 you will have outcomes with estimated proportions.

CART trees R

randomForest CRAN .

$\endgroup$
0
$\begingroup$

You might also want to look at package RSNNS, which provides an R interface to the package SNNS, with ample functionality for general neural networks.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.