Learn R Programming

glmmsr (version 0.1.0)

glmm: Fit a GLMM

Description

Fit a GLMM

Usage

glmm(formula, subformula = NULL, data = NULL, family = gaussian,
  method = NULL, control = list(), weights = NULL, offset = NULL,
  prev_fit = NULL, verbose = 1L)

Arguments

formula
a two-sided linear formula object describing both the fixed-effects and fixed-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-eff
subformula
a subformula, describing how a substituted variable depends on covariates, or a list of subformulas, if there is more than one Sub() term in formula.
data
an optional data frame, list or environment containing the variables named in formula, and in any of the subformulas.
family
a GLM family, see glm and family.
method
the method used to approximate the likelihood. The options are "Laplace", "AGQ" (the adaptive Gaussian quadrature approximation, from lme4), "SR" (the sequential reduction approximation) and "IS"
control
a list of extra parameters controlling the approximation to the likelihood. See 'Details' for more information.
weights
an optional vector of prior weights to be used in the fitting process. Should be NULL or a numeric vector.
offset
this can be used to specify an a priori known component to be included in the linear predictor during fitting. This should be NULL or a numeric vector of length equal to the number of cases. One or more
prev_fit
a glmmFit object, the result of a previous model fit.
verbose
controls how much detail to print out while fitting the model. For verbose = 0, print nothing. For verbose = 1 (the default), print output approximately once a second during model fitting. For verbose = 2, print out the parameter value and log-likelihood

Value

  • An object of the class glmmFit

Details

The control argument is a list, used to specify further arguments controlling the approximation to the likelihood: [object Object],[object Object],[object Object]

Examples

Run this code
# Fit a three-level model with the Laplace approximation to the likelihood
(mod_Laplace <- glmm(response ~ covariate + (1 | cluster) + (1 | group),
                     data = three_level, family = binomial,
                     method = "Laplace"))

# if we try to fit with adaptive Gaussian quadrature, we get an error
(mod_AGQ <- glmm(response ~ covariate + (1 | cluster) + (1 | group),
                   data = three_level, family = binomial, method = "AGQ",
                   control = list(nAGQ = 15)))

# We can fit with the Sequential Reduction approximation
(mod_SR <- glmm(response ~ covariate + (1 | cluster) + (1 | group),
                  data = three_level, family = binomial, method = "SR",
                  control = list(nSL = 3)))
# the estimates of the random effects standard deviations
# are larger than those using the Laplace approximation

Run the code above in your browser using DataLab