prep_sim_data: Prepare data for simulation

View source: R/prep_functions.R

prep_sim_dataR Documentation

Prepare data for simulation

Description

Prepare data for simulation

Usage

prep_sim_data(
  time_map_data,
  by_days = 1,
  start_day = 1,
  time_before = 365,
  event_name = "any_ssd",
  cp_method = "lm_quad",
  specify_cp = NULL,
  set_cp_method = NULL,
  eval_criteria = "AIC",
  week_period = FALSE,
  prediction_bound_for_sim = FALSE,
  auto_reg = FALSE,
  dur_bins = 1:30
)

Arguments

time_map_data

a time_map of visits

by_days

the number of days to aggregate by in counting periods

start_day

When to start counting prior to the index

event_name

The variable name for the event indicator

cp_method

The change-point method to fit visit counts (i.e. "lm","lm_quad","lm_cube", "quad", "cube", "exp", "spline", "cusum", "pettitt", or "set_cp"). "set_cp" is not a change point detection method, rather it is a method to specify the change point and method used to model the data prior to the specified change point

specify_cp

Set a specific change point you want to use instead of searching for optimal change point. Enter a postive integer value repersenting the days before the index on which you you want to specify the change point. (e.g. 100 would be 100 days before the index) This is a required argument if cp_method = "set_cp"

set_cp_method

The method used to model the data prior to a specified change point for the "set_cp" cp_method (i.e. "linear", "cubic", "exponential", etc.)

eval_criteria

The evaluation criteria used to find change points, if using a linear regression method

week_period

Logical to incorporate a "day of the week" effect into the linear model, if method is "pettitt" of "cusum". Note this is only sensible for one-day period aggregation

prediction_bound_for_sim

Logical to specify whether or not to use the estimated predicted value or the upper bound 90 prediction value in the simulations. The defualt is FALSE which uses the estimated predicited value

auto_reg

Logical that determines whether expected counts use a time-series framework that incorporates autoregression. Will automatically fit periodicity, automatically setting week_period to TRUE. Only relevant for cusum and pettitt methods

dur_bins

Numeric vector containing all days for which the simulations should calculate delay duration statistics. If values contained in this vector are greater than the changepoint, they will be omitted from the output.

Examples


## Example to detect change point using cusum ##
out <- prep_sim_data_delay(time_map_data, by_days=1, start_day=1, event_name = "any_ssd", cp_method = "cumsum")

## Examples showing different ways to specify a change point ##

# Using a change point detection method (e.g. cumsum or lm_cube), but enforce a specific change point
cp <- 21
out <- prep_sim_data_delaydx(time_map_data, by_days=1, start_day=1, event_name = "any_ssd", cp_method = "cumsum", specify_cp = cp)

# Using the "set_cp" in the cp_method argument to apply a cubic model to the data prior to the change point
cp <- 21
out <- prep_sim_data_delaydx(time_map_data, by_days=1, start_day=1, event_name = "any_ssd", cp_method = "set_cp", specify_cp = cp,
set_cp_method = "cubic")




aarmiller/delaySim documentation built on Jan. 2, 2023, 11:23 p.m.