find_cp_loss_fun: find_cp_loss_fun

Description Usage Arguments Value Examples

View source: R/cp_functions.R

Description

Identify change point using a loss function method and find expected SSD visits/calculate misses. This is done by fitting a linear model for data prior to i, with i ranging from period 0 to max period - 2. For a specified loss function, the first local minima is used used to identifiy the optimal change point

Usage

1
2
3
4
5
6
7
8
9
find_cp_loss_fun(
  data,
  var_name = "n_miss_visits",
  return_miss_only = FALSE,
  return_loss_fun_tab_only = FALSE,
  week_period = FALSE,
  specify_cp = NULL,
  loss_function = "RMSE"
)

Arguments

data

A dataframe output by count_prior_events_truven

var_name

A character string of outcome for which to apply analysis

return_miss_only

Logical to only return miss information

return_loss_fun_tab_only

Logical to only return loss function table that includes estimates for all loss functions available

week_period

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

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)

loss_function

The loss function used to identify the change point (mean squared error (MSE), root mean squared error (RMSE), mean absolute error (MAE), mean squared log error (MSLE), or root mean squared log error (RMSLE)

Value

A list containing miss information, changepoint information, predictions, the model itself, and a plot of the middle finger curve and model.

Examples

1
2
3
4
cp_result_pettit <- final_time_map %>%
filter(days_since_dx >= -180) %>%
count_prior_events_truven(event_name = "any_ssd", start_day = 1, by_days = 1) %>%
find_cp_loss_fun(var_name = "n_miss_visits", return_miss_only = FALSE, week_period=TRUE, loss_function = "MAE")

aarmiller/delayDX documentation built on July 11, 2021, 4:01 p.m.