Merge GHRmodels
Description
This function stack together two or more objects GHRmodels object, returning one GHRmodels object that contains all the input models. All models included in the stack must have the same family, outcome, and data. If any model_id is duplicated across the inputs the new_name argument must be provided to ensure unique IDs.
stack_models(..., new_name = NULL, vs_first = FALSE)Arguments
...: Two or moreGHRmodelsobjects, or a single list of them.new_name:NULL(default) or a character used to build the new model IDs.vs_first: Logical. If TRUE columns comparing the model vs the first model are kept in themod_gof, otherwise are discarded. Default is FALSE. Set to TRUE only when models contained in theGHRmodelsobject to be stacked are compared with the same first models.
Details
Combine (Stack) Multiple GHRmodels Objects
Returns
A single GHRmodels object containing all models from the inputs.
See Also
subset_models for subsetting GHRmodels objects, fit_models for fitting INLA models.
Examples
data(dengue_MS)
dengue_MS <- dengue_MS[dengue_MS$year %in% 2010:2012, ]
# Formulas
formulas1 <- "dengue_cases ~ tmin + f(month, model='rw2')"
formulas2 <- "dengue_cases ~ tmax + f(month, model='rw2')"
# Fit
fitmod1 <- fit_models(
formulas = formulas1,
data = dengue_MS,
family = "nbinomial",
offset_var = "pop100000"
)
fitmod2 <- fit_models(
formulas = formulas2,
data = dengue_MS,
family = "nbinomial",
offset_var = "pop100000"
)
# Stack
stacked <- stack_models(fitmod1, fitmod2, new_name = "mod")