enw_formula | R Documentation |
This function allows models to be defined using a flexible formula interface that supports fixed effects, random effects (using lme4 syntax). Note that the returned fixed effects design matrix is sparse and so the index supplied is required to link observations to the appropriate design matrix row.
enw_formula(formula, data, sparse = TRUE)
formula |
A model formula that may use standard fixed
effects, random effects using lme4 syntax (see |
data |
A |
sparse |
Logical, defaults to |
A list containing the following:
formula
: The user supplied formula
parsed_formula
: The formula as parsed by parse_formula()
extended_formula
: The flattened version of the formula with
both user supplied terms and terms added for the user supplied
complex model components.
fixed
: A list containing the fixed effect formula, sparse design
matrix, and the index linking the design matrix with observations.
random
: A list containing the random effect formula, sparse design
matrix, and the index linking the design matrix with random effects.
Functions used to help convert formulas into model designs
as_string_formula()
,
construct_re()
,
construct_rw()
,
enw_manual_formula()
,
parse_formula()
,
re()
,
remove_rw_terms()
,
rw()
,
rw_terms()
,
split_formula_to_terms()
# Use meta data for references dates from the Germany COVID-19
# hospitalisation data.
obs <- enw_filter_report_dates(
germany_covid19_hosp[location == "DE"],
remove_days = 40
)
obs <- enw_filter_reference_dates(obs, include_days = 40)
pobs <- enw_preprocess_data(
obs, by = c("age_group", "location"), max_delay = 20
)
data <- pobs$metareference[[1]]
# Model with fixed effects for age group
enw_formula(~ 1 + age_group, data)
# Model with random effects for age group
enw_formula(~ 1 + (1 | age_group), data)
# Model with a random effect for age group and a random walk
enw_formula(~ 1 + (1 | age_group) + rw(week), data)
# Model defined without a sparse fixed effects design matrix
enw_formula(~1, data[1:20, ])
# Model using an interaction in the right hand side of a random effect
# to specify an independent random effect per strata.
enw_formula(~ (1 + day | week:month), data = data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.