dsps_predict: Predicting the event time from DSP

View source: R/dsps_predict.R

dsps_predictR Documentation

Predicting the event time from DSP

Description

Predicted event time based on DSP method.

Usage

dsps_predict(fit, newdata)

Arguments

fit

is the return object from function dsp_fit

newdata

a dataframe in which to look for time-dependent covariates with which to predict. The last two columns, in order, are time (time) and unique identifier for subject (subjectid). The order of the rest time-dependent covariates should match the order as in the training data used in function dsp_fit. For each subject, time-dependent covariates should be supplied at each unique event time in the training data. Missing values should be imputed before making prediction.

Value

a dataframe with predicted event time

Examples


## Example 1 - With training data splitting

set.seed(1236)
dat <- sim_data(n=100, er=0.6)

# Split the data by 7/3

subject_list <- unique(dat$Z$subjectid)

train_id <- sample(subject_list, round(length(subject_list)*0.7))
test_id <- subject_list[!subject_list %in% train_id]

# Data for training, keep only at risk data points
dat_train <- dat$Z %>%
    filter(at_risk == 1) %>%
    filter(subjectid %in% train_id) %>%
    select(-at_risk)

fit <- dsp_fit(dat_train,
               C=2^2,
               kernel="semi_linear")

# Data for testing
newdata <- dat$Z %>%
    filter(subjectid %in% test_id) %>%
    select(-at_risk, -event)

# Making prediction
predict.dsp <- dsp_predict(fit, newdata = newdata)





## Example 2 - Make event time prediction for large testing data

set.seed(1236)
dat <- sim_data(n=100, er=0.6)

dat_train <- dat$Z %>%
    filter(at_risk == 1) %>%
    select(-at_risk)

fit <- dsp_fit(dat_train,
               C=2^2,
               kernel="semi_linear")


dat_test <- sim_data(n=1000, er=1, time_points=fit$train_dat$unq_t_obs)

predict.dsp <- dsp_predict(fit, select(dat_test$Z, -at_risk, -event))


Wenyi-Xie/DSP documentation built on Sept. 14, 2022, 10:03 p.m.