training_synthetic_data"

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(spect)

Generating unit test data

It can be useful to create a data set with a known distribution for testing novel modeling approaches. In this case, the sample data set generated is used for unit testing the spect package.

rng_seed <- 42
set.seed(rng_seed)

syn_data <- create_synthetic_data(sample_size=2500,
                      censor_percentage = 0.1,
                      perturbation_shift = 6)


source_data <- select(syn_data, -c(baseline_time_to_cancel, perturbed_baseline))

predict_data <- source_data[1:10,]
modeling_data <- source_data[11:nrow(source_data),]

Training the model then becomes a straightforward call to spect_train.

event_indicator_var <- "cancel_event_detected"
survival_time_var <- "total_months"
obs_window <- 48
alg="glm"

result <- spect_train(model_algorithm=alg, modeling_data=modeling_data,
                      event_indicator_var=event_indicator_var,
                      survival_time_var=survival_time_var,
                      obs_window=obs_window, use_parallel=FALSE)


Try the spect package in your browser

Any scripts or data that you put into this service are public.

spect documentation built on April 11, 2025, 6:17 p.m.