View source: R/predict_general_mdl_avg_trend.R
predict_general_mdl_avg_trend | R Documentation |
predict_general_mdl
on groups to generate average trend and apply to original datapredict_general_mdl_avg_trend()
uses a general model object from R to fit a model
to groups within the data, and then bring that fitted prediction back to the
original data. The function uses any general modelling function from R for model fitting
and prediction, with full details on requirements available from predict_general_mdl()
.
The function also allows for inputting of data type and source information
directly into the data frame if the type_col
and source_col
are specified
respectively.
predict_general_mdl_avg_trend(
df,
model,
formula,
average_cols = NULL,
weight_col = NULL,
group_models = FALSE,
...,
ret = c("df", "all", "error", "model"),
scale = NULL,
probit = FALSE,
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",
pred_upper_col = "pred_upper",
pred_lower_col = "pred_lower",
upper_col = "upper",
lower_col = "lower",
filter_na = c("predictors", "response", "all", "none"),
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. |
model |
An R function that outputs a model object with a |
formula |
A formula that will be supplied to the model, such as |
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. |
group_models |
Logical, whether or not to run separate models for each group
defined by |
... |
Other arguments passed to the model function. |
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. |
scale |
Either |
probit |
Logical value on whether or not to probit transform the response
prior to model fitting. Probit transformation is performed after any scaling
determined by |
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 " |
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. |
pred_upper_col |
Column name to store upper bound of confidence interval
generated by the |
pred_lower_col |
Column name to store lower bound of confidence interval
generated by the |
upper_col |
Column name that contains upper bound information, including
upper bound of the input data to the model. Values from |
lower_col |
Column name that contains lower bound information, including
lower bound of the input data to the model. Values from |
filter_na |
Character value specifying how, if at all, to filter |
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 fitted values. Defaults to replacing only missing values, but can be used to replace all values or none. |
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 |
predict_..._avg_trend()
functions need to be used carefully. Ensure that average_cols
and variables in the formula
match, and any formula
variables not in average_cols
are numeric that can be averaged. Even though the modeling won't use the group_col
,
it should be provided if necessary to be used in error metric calculations, and provision
of types
into type_col
. Similarly, the sort_col
is necessary for types
, but
also needs to be in average_cols
if error_correct
, group_models
, or shift_trend
is
going to be used.
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.