predict_simple_fn() does simple linear interpolation and flat extrapolation
on specified columnn in a data frame using zoo::na.approx().
Usage
predict_simple_fn(
df,
model,
col,
test_col = NULL,
group_col = NULL,
obs_filter = NULL,
pred_col = "pred",
sort_col = NULL,
sort_descending = FALSE
)Arguments
- df
Data frame of model data.
- model
Type of simple extrapolation or interpolation to perform:
forward: Justflat_extrapandlinear_interp. (default)all: All offlat_extrap,linear_interp, andback_extrapflat_extrap: Flat extrapolation from latest observed point.linear_interp: Linear interpolation between observed data points.back_extrap: Flat extrapolation from first observed data point backwards.both_extrap: Bothflat_extrapandback_extrap.
- col
Name of column to extrapolate/interpolate.
- test_col
Name of logical column specifying which response values to remove for testing the model's predictive accuracy. If
NULL, ignored. Seemodel_error()for details on the methods and metrics returned.- group_col
Column name(s) of group(s) to use in
dplyr::group_by()when supplying type, calculating mean absolute scaled error on data involving time series, and ifgroup_models, then fitting and predicting models too. IfNULL, not used. Defaults to"iso3".- obs_filter
String value of the form "
logical operatorinteger" that specifies the number of observations required to fit the model and replace observations with predicted values. This is done in conjunction withgroup_col. So, ifgroup_col = "iso3"andobs_filter = ">= 5", then for this model, predictions will only be used foriso3vales that have 5 or more observations. Possible logical operators to use are>,>=,<,<=,==, and!=.If `group_models = FALSE`, then `obs_filter` is only used to determine when predicted values replace observed values but **is not** used to restrict values from being used in model fitting. If `group_models = TRUE`, then a model is only fit for a group if they meet the `obs_filter` requirements. This provides speed benefits, particularly when running INLA time series using `predict_inla()`.- pred_col
Column name to store predicted value.
- sort_col
Column name(s) to use to dplyr::arrange() the data prior to supplying type and calculating mean absolute scaled error on data involving time series. If NULL, not used. Defaults to "year". For
predict_simple(), the first value insort_colis passed tozoo::na.approx()asxoutto ensure linear interpolation is based onsort_colindexing rather than default data frame indexing.- sort_descending
Logical value on whether the sorted values from
sort_colshould be sorted in descending order. Defaults toFALSE.
