1
$\begingroup$

So I've been trying to perform a discrete time survival analysis in R.

I have been using the discSurv package to generate the augmented data matrix for the full dataset and performed an stratified train-test split.

This has just been an initial approach, but in order to test more complex procedures, I want to successfully understand what is happening each step.

After i have generated the augmented dataset (using the dataLong function), I proceed to train a GAM model.

However, here is where i come into trouble. First of all, i don't know how to select which variables to model via a spline function, nor the parameters that should accompany them.

Moreover, which are the appropiate metrics to analyze the model with. How could I predict on the test dataset, and how could i visualize these results within R.

I have worked previously with other machine learning algorithms, but i'm very new to GAM and I can't seem to find any examples related to survival prediction analysis.

$\endgroup$

closed as unclear what you're asking by Michael Chernick, mdewey, mkt, Siong Thye Goh, kjetil b halvorsen May 27 at 12:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

0
$\begingroup$

There are a lot of question rolled into one, each one potentially very difficult. Here are some suggestions:

1.) How to select which variables to fit with a spline:

  • Each continuous variable should be considered to potentially have non-linear effects and modeled by splines, unless you have prior knowledge that informs the functional shape of the effect. Because GAMs fit penalized splines, covariates with linear effects will be estimated as such. The select argument in ?mgcv::gam in combination with the gamma parameter can help to keep the models sparse (See also my answer here; you can think of the gamma as a potential tuning parameter in machine learning lingo).

    • GAMs (for survival) can become arbitrary complex, e.g., you could have different baseline hazards in different groups (of a categorical variable), bivariate smooth effects, time-varying effects, etc... (see this and this for some examples).

    • When the model gets very complex, i.e., a lot of (non-linear) effects, you could consider boosting the GAM, e.g. using mboost package, which performs variable and smoothness selection simultaneously.

2.) Prediction on the test data set: Prediction in theory is relatively straight forward. Your test data has to be formatted the same way as the training data (i.e. long format). Then you can call predict(model, newdata, type = "response") to get predictions (of the hazard). In practice, you have to decide at which time-points you want to make a prediction. To predict survival probability at $t = 10$, you also have to have all data-splits for $t < 10$, etc.

3.) For evaluation of your predictions the most popular measures are the C-Index (similar to AUC in binary classification) or the Prediction Error Curve (Brier Score evaluated at multiple time-points). Unlike most machine learning evaluations, the evaluation of the model is performed at different time points of the follow-up (different models can potentially be better/worse at the beginning/the end of the follow-up). You can also calculate an overall measure though, e.g. Integrated PEC. There is a package pec that does all of this as described in this tutorial. There are also examples for visualization and interpretation. You can adapt it directly to your GAM/boosted GAM, by writing a custom predictSurvProb function if it doesn't exist already (see examples in the tutorial). The discSurv package also provides functionality for this, see ?brierScore and ?concorIndex and examples therein.

$\endgroup$
  • $\begingroup$ Thank you very much, this is exactly what i needed! I greatly appreciate your time and effort to answer my questions. Wish you the best! $\endgroup$ – baseking May 27 at 7:58

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