Skip to contents

Fit a linear or GAM model to RoC scores and return the fitted values.

Usage

make_trend(data_source, sel_method = c("linear", "non_linear"), silent = FALSE)

Arguments

data_source

data.frame with columns ROC and Age.

sel_method

character. Which trend to fit:

  • "linear" - a linear model fitted between RoC and age.

  • "non_linear" - a conservative GAM (RoC ~ s(age, k = 3)) using the mgcv package.

silent

logical. If TRUE, do not warn about RoC values of zero (default = FALSE).

Value

numeric vector of fitted values, one per row of data_source.

Details

Both trends assume a Gamma distribution of RoC (Tweedie with power 2) with a log link, which is defined only for values above zero. RoC values of zero are therefore replaced, for the fit only, by half of the smallest RoC value above zero (see util_replace_zero_roc()), with a warning unless silent = TRUE.

ROC must not contain NA, because the fitted values must match the rows of data_source; remove such rows first (see util_skip_na_roc()).