predict_sw_reg: Compute the prediction of a model built with 'sw_reg'

Description Usage Arguments Value See Also Examples

View source: R/sw_reg.R

Description

Given a model built wtih sw_reg, predict_sw_reg allows to get the predictions of the model for new observations

Usage

1
predict_sw_reg(obj, newdata)

Arguments

obj

A list output by sw_reg

newdata

A data.frame which contains the same variables as the ones used for the training

Value

A list with the following elements :

pred

The vector of the predicted values for phi(T') (with T' = min(T, max_time)) for the observations of newdata

pred_KMloc

The vector of the predicted values for phi(T') for the observations of newdata with inner Kapaln Meier weights (require obj to be trained with mode_w_rf = 2). See sw_reg for more information

surv_KMloc

The matrix which contains the estimated values of the survival curves at time_points with inner Kapaln Meier weights, for the observations of newdata (require mode_sw_RF = 2)

time_points

The vector of the time points where the survival curves are evaluated (require mode_sw_RF = 2)

See Also

sw_reg

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# ------------------------------------------------
#   Load "transplant" data
# ------------------------------------------------
data("transplant", package = "survival")
transplant$delta = 1 * (transplant$event == "ltx") # create binary var
# which indicate censoring/non censoring

# keep only rows with no missing value
transplant_bis = transplant[stats::complete.cases(transplant),]

# ------------------------------------------------
#   Basic call to train a model
# ------------------------------------------------

set.seed(17)
train_lines = sample(1:nrow(transplant_bis), 600)
res = sw_reg(y_var = "futime",
                                   delta_var = "delta",
                                   x_vars = setdiff(colnames(transplant_bis),
                                                    c("futime", "delta", "event")),
                                   train = transplant_bis[train_lines,],
                                   types_w_ev = c("KM", "Cox", "RSF", "unif"),
                                   mode_sw_RF = 2)

# ------------------------------------------------
#   Predict on new data
# ------------------------------------------------

pred = predict_sw_reg(obj = res,
                                            newdata = transplant_bis[-train_lines,])

YohannLeFaou/sword documentation built on May 28, 2019, 3:21 p.m.