glmm: Fit a GLMM

Description Usage Arguments Details Value Examples

View source: R/fit.R

Description

Fit a GLMM

Usage

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

Arguments

formula

a two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-effects terms are distinguished by vertical bars ("|") separating expressions for design matrices from grouping factors.

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" (an importance sampling approximation).

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 offset terms can be included in the formula instead or as well, and if more than one is specified their sum is used. See model.offset.

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 at every stage of optimization.

lme4_control

the result of a call to lme4_control, containing control parameters passed to lme4. See ?lme4_control.

Details

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

nAGQ

the number of adaptive Gaussian quadrature points. Only used if method = "AGQ". Defaults to 15.

nSL

the level of sparse grid storage. Only used if method = "SR". Defaults to 3.

nIS

the number of samples to use for importance sampling. Only used if method = "IS". Defaults to 1000.

order

the order of Laplace approxiation. only used if method = "Laplace". Defaults to 1.

check_Laplace

should quality of first-order Laplace approximation be checked? Only used if method = "Laplace" and order = 1. Defaults to TRUE.

divergence_threshold

if check_Laplace = TRUE, warn about quality of inference using the first-order Laplace approximation if measure of divergence from inference with second-order Laplace approximation exceeds divergence_threshold. Defaults to 0.1.

Value

An object of the class glmmFit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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
## Not run: 
  (mod_AGQ <- glmm(response ~ covariate + (1 | cluster) + (1 | group),
                   data = three_level, family = binomial, method = "AGQ",
                   control = list(nAGQ = 15)))

## End(Not run)

# We can fit with the Sequential Reduction approximation
## Not run: 
  (mod_SR <- glmm(response ~ covariate + (1 | cluster) + (1 | group),
                  data = three_level, family = binomial, method = "SR",
                  control = list(nSL = 3)))

## End(Not run)
# the estimates of the random effects standard deviations
# are larger than those using the Laplace approximation

glmmsr documentation built on April 10, 2018, 9:07 a.m.