tune.nn.time: Tune a 1-Layer Survival Neural Network

View source: R/tune.nn.time.R

tune.nn.timeR Documentation

Tune a 1-Layer Survival Neural Network

Description

This function finds the optimal n.nodes, decay, batch.size, and epochs parameters for a survival neural network

Usage

tune.nn.time(times, failures, group, cov.quanti,
cov.quali, data, cv, n.nodes, decay, batch.size, epochs)

Arguments

times

The name of the variable related the numeric vector with the follow-up times.

failures

The name of the variable related the numeric vector with the event indicators (0=right censored, 1=event).

group

The name of the variable related to the exposure/treatment. This variable shall have only two modalities encoded 0 for the untreated/unexposed patients and 1 for the treated/exposed ones. The default value is NULL: no specific exposure/treatment is considered. When a specific exposure/treatment is considered, it will be forced in the algorithm or related interactions will be tested when possible.

cov.quanti

The name(s) of the variable(s) related to the possible quantitative covariates. These variables must be numeric.

cov.quali

The name(s) of the variable(s) related to the possible qualitative covariates. These variables must be numeric with two levels: 0 and 1. A complete disjunctive form must be used for covariates with more levels.

data

A data frame for training the model in which to look for the variables related to the status of the follow-up time (times), the event (failures), the optional treatment/exposure (group) and the covariables included in the previous model (cov.quanti and cov.quali).

cv

The value of the number of folds. The default value is 10.

n.nodes

The number of hidden nodes optimized over.

decay

The value of the weight decay optimized over.

batch.size

The value of batch size

epochs

The value of epochs

Details

The function runs the deepsurv function of the survivalmodels package.

Value

optimal

The value of lambda that gives the minimum mean cross-validated error.

results

The data frame with the mean cross-validated errors for each lambda values.

Author(s)

Yohann Foucher <Yohann.Foucher@univ-poitiers.fr>

Camille Sabathe <camille.sabathe@univ-nantes.fr>

References

Katzman et al. DeepSurv: personalized treatment recommender system using a Cox proportional hazards deep neural network. BMC Medical Research Methodology, 18(1), 24. 1018. https://doi.org/10.1186/s12874-018-0482-1

Examples


# On a linux machine

# Install Python 

# sudo apt install python3-pip

# Install Python Miniconda for CPU computaion on a linux machine

# Download the file from https://docs.conda.io/en/latest/miniconda.html#linux-installers

  # chmod +x Miniconda3-latest-Linux-x86_64.sh 
  # ./Miniconda3-latest-Linux-x86_64.sh 
  # conda create --name torch python=3.8
  # conda activate torch
  # conda install pytorch torchvision torchaudio cpuonly -c pytorch
  # conda install -c conda-forge pycox

# export PATH="/home/username/.local/bin:$PATH"

# remotes::install_github("RaphaelS1/survivalmodels")
# install_pycox(method = "auto",  conda = "auto",  pip = TRUE,  install_torch = TRUE )
# install_keras(method = "auto",  conda = "auto",  pip = TRUE,  install_tensorflow = TRUE)

# use_condaenv(condaenv = "~/miniconda3/envs/torch", conda = "auto", required = FALSE)

# data(dataDIVAT2)

# The estimation of the hyperparameters

# tune.model<-tune.nn.time(times="times", failures="failures", data=dataDIVAT2[1:500,],
#    cov.quanti=c("age"),  cov.quali=c("hla", "retransplant", "ecd"),
#    cv=3, n.nodes=c(1, 2), decay=0, batch.size=256L, epochs=1L)

# the estimated nodesize value

# tune.model$optimal
# tune.model$results

# The estimation of the training modelwith the corresponding lambda value

# model<-nn.time(times="times", failures="failures", data=dataDIVAT2,
#   cov.quanti=c("age"),  cov.quali=c("hla", "retransplant", "ecd"),
#   n.nodes=tune.model$optimal$n.nodes, decay=0, batch.size=256L, epochs=1L)

# The resulted predicted survival of the first subject of the training sample
# plot(y=model$predictions[1,], x=model$times, xlab="Time (years)", ylab="Predicted survival",
#      col=1, type="l", lty=1, lwd=2, ylim=c(0,1))


RISCA documentation built on March 31, 2023, 11:06 p.m.

Related to tune.nn.time in RISCA...