View source: R/predict_average.R
predict_average | R Documentation |
predict_average()
does simple infilling and prediction using averages.
Similar to other predict functions, it also allows filling in of type and source
if necessary. However, it does not provide confidence bounds on the estimates,
like other predict_...
model-based functions provide.
predict_average(
df,
col = "value",
average_cols = NULL,
weight_col = NULL,
flat_extrap = TRUE,
ret = c("df", "all", "error"),
test_col = NULL,
test_period = NULL,
test_period_flex = NULL,
group_col = "iso3",
obs_filter = NULL,
sort_col = "year",
sort_descending = FALSE,
pred_col = "pred",
type_col = NULL,
types = c("imputed", "imputed", "projected"),
source_col = NULL,
source = NULL,
scenario_detail_col = NULL,
scenario_detail = NULL,
replace_obs = c("missing", "all", "none"),
error_correct = FALSE,
error_correct_cols = NULL,
shift_trend = FALSE
)
df |
Data frame of model data. |
col |
Name of column to extrapolate/interpolate. |
average_cols |
Column name(s) of column(s) for use in grouping data for averaging, such as regions. If missing, uses global average of the data for infilling. |
weight_col |
Column name of column of weights to be used in averaging, such as country population. |
flat_extrap |
Logical value determining whether or not to flat extrapolate using the latest average for missing rows with no data available. |
ret |
Character vector specifying what values the function returns. Defaults to returning a data frame, but can return a vector of model error, the model itself or a list with all 3 as components. |
test_col |
Name of logical column specifying which response values to remove
for testing the model's predictive accuracy. If |
test_period |
Length of period to test for RMChE. If |
test_period_flex |
Logical value indicating if |
group_col |
Column name(s) of group(s) to use in |
obs_filter |
String value of the form " 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()`. |
sort_col |
Column name(s) to use to |
sort_descending |
Logical value on whether the sorted values from |
pred_col |
Column name to store predicted value. |
type_col |
Column name specifying data type. |
types |
Vector of length 3 that provides the type to provide to data produced in the model. These values are only used to fill in type values where the dependent variable is missing. The first value is given to missing observations that precede the first observation, the second to those after the last observation, and the third for those following the final observation. |
source_col |
Column name containing source information for the data frame.
If provided, the argument in |
source |
Source to add to missing values. |
scenario_detail_col |
Column name containing scenario_detail information
for the data frame. If provided, the argument in |
scenario_detail |
Scenario details to add to missing values (usually the name of the model being used to generate the projection, optionally with relevant parameters). |
replace_obs |
Character value specifying how, if at all, observations should
be replaced by infilled values. By default, replaces missing values in |
error_correct |
Logical value indicating whether or not whether mean error
should be used to adjust predicted values. If |
error_correct_cols |
Column names of data frame to group by when applying error correction to the predicted values. |
shift_trend |
Logical value specifying whether or not to shift predictions
so that the trend matches up to the last observation. If |
For each year where at least 1 data point is available, the average is calculated
as the prediction. If flat_extrap
, then the latest average is flat extrapolated
to the end of the data. When using test_col
, the average may not be available
for certain groups, so flat extrapolation will be relied on, meaning that the
COR
metric output by errors is difficult to interpret or use properly.
Depending on the value passed to ret
, either a data frame with
predicted data, a vector of errors from model_error()
, a fitted model, or a list with all 3.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.