[Experimental]
Fit a generalized linear mixed effect model using lme4::glmer(). This function is still in early development stage.

glme_model(
  data,
  model = NULL,
  response_variable,
  random_effect_factors = NULL,
  non_random_effect_factors = NULL,
  family,
  two_way_interaction_factor = NULL,
  three_way_interaction_factor = NULL,
  id,
  estimation_method = "REML",
  opt_control = "bobyqa",
  na.action = stats::na.omit,
  quite = FALSE
)

Arguments

data

data frame

model

lme4 model syntax. Support more complicated model. Note that model_summary will only return fixed effect estimates. This is not tested. [Experimental]

response_variable

DV (i.e., outcome variable / response variable). Length of 1. Support dplyr::select() syntax.

random_effect_factors

random effect factors (level-1 variable for HLM people) Factors that need to estimate fixed effect and random effect (i.e., random slope / varying slope based on the id). Support dplyr::select() syntax.

non_random_effect_factors

non-random effect factors (level-2 variable for HLM people). Factors only need to estimate fixed effect. Support dplyr::select() syntax.

family

a GLM family. It will passed to the family argument in glmer. See ?glmer for possible options.

two_way_interaction_factor

two-way interaction factors. You need to pass 2+ factor. Support dplyr::select() syntax.

three_way_interaction_factor

three-way interaction factor. You need to pass exactly 3 factors. Specifying three-way interaction factors automatically included all two-way interactions, so please do not specify the two_way_interaction_factor argument. Support dplyr::select() syntax.

id

the nesting variable (e.g. group, time). Length of 1. Support dplyr::select() syntax.

estimation_method

character. ML or REML default to REML.

opt_control

character. default is bobyqa. See ?lme4::glmerControl for more options.

na.action

default is stats::na.omit. Another common option is na.exclude

quite

suppress printing output

Value

An object of class glmerMod representing the linear mixed-effects model fit.

Examples

fit <- glme_model(
  response_variable = incidence,
  random_effect_factors = period,
  family = "poisson", # or you can enter as poisson(link = 'log')
  id = herd,
  data = lme4::cbpp
)
#> Warning: The following columns are coerced into numeric: herd, period
#> Fitting Model with glmer: 
#>  Formula = incidence ~ period + (1 + period | herd)
#>  Family = poisson