mhglm: Fitting Moment Hierarchical Generalized Linear Models

Description Usage Arguments Details Value Note Author(s) References See Also Examples

View source: R/mhglm.R


mhglm is used to fit a moment hierarchical generalized linear model.


mhglm(formula, family = gaussian, data, weights, subset,
      na.action, start = NULL, etastart, mustart, offset,
      control = list(), model = TRUE, method = "",
      x = FALSE, z = FALSE, y = TRUE, group = TRUE,
      contrasts = NULL), z, y, group, weights = rep(1, nobs),
          start = NULL, etastart = NULL, mustart = NULL,
          offset = rep(0, nobs), family = gaussian(), 
          control = list(), intercept = TRUE)


formula, family, data, weights, subset, na.action, start, etastart, mustart, offset, model, contrasts, intercept

These arguments are analogous to the similarly-named arguments for the glm and functions.


a list of parameters for controlling the fitting process. For this is passed to mhglm.control.


the method to be used in fitting the model. The default method "" uses moment-based estimates; the alternative "model.frame" returns the model frame and does no fitting.

x, z, y, group

For mhglm: logical values indicating whether the response vector, model matrices, and grouping factor used in the fitting process should be returned as components of the returned value.

For x is a fixed effect design matrix of dimension n * p, z is a random effect design matrix of dimension n * q, y is a vector of observations of length n, and group is a grouping factor vector of length n.


These functions are analogues of glm and, meant to be used for fitting hierarchical generalized linear models. A typical predictor has the form response ~ terms + (reterms | group) where response is the (numeric) response vector, terms is a series of terms which specifies a linear predictor for response, reterms is a series of terms with random coefficients (effects), and group is a grouping factor; observations with the same grouping factor share the same random effects.

Currently, only one random effect term is allowed, along with a single level of hierarchy; random effect terms of the form reterms | g1/.../gQ are not supported.


mhglm returns an object of class inheriting from "mhglm".

The function summary can be used to obtain or print a summary of the results.

The generic accessor functions fixef, ranef, VarCorr, sigma, fitted.values and residuals can be used to extract various useful features of the value returned by mhglm.


If the moment-based random effect covariance is not positive-semidefinite, then a warning will be issued, and a projection of the estimate to the positive-semidefinite cone will be used instead.


Patrick O. Perry


Perry, P. O. (2015) "Fast Moment-Based Estimation for Hierarchical Models", Preprint.

See Also

terms.mhglm, model.matrix.mhglm, and predict.mhglm for mhglm methods, and the generic functions fitted.values, residuals, summary, vcov, and weights.

Generic functions fixef, ranef, VarCorr, and sigma for features related to mixed effect models.

glmer (package lme4) for fitting generalized linear mixed models with likelihood-based estimates.


## The following examples are adapted from lme4:
(fm1 <- mhglm(Reaction ~ Days + (Days | Subject), gaussian, sleepstudy))

(gm <- mhglm(cbind(incidence, size - incidence) ~ period + (1 | herd),
             data = cbpp, family = binomial))

Example output

Loading required package: nlme
Loading required package: Matrix

Attaching package: 'lme4'

The following object is masked from 'package:nlme':


mhglm(formula = Reaction ~ Days + (Days | Subject), family = gaussian, 
    data = sleepstudy)

Random effects:
            Variance Std. Dev.
(Intercept)   565.52    23.781
Days           32.68     5.717

Fixed effects:
            Estimate Std. Error t value Pr(> |t|)    
(Intercept)  251.405      6.632  37.906   < 2e-16 ***
Days          10.467      1.502   6.968  1.07e-10 ***
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for gaussian family taken to be 654.9)

mhglm(formula = cbind(incidence, size - incidence) ~ period + 
    (1 | herd), family = binomial, data = cbpp)

Random effects:
            Variance Std. Dev.
(Intercept)   0.2174    0.4662

Fixed effects:
            Estimate Std. Error t value Pr(> |t|)    
(Intercept)  -1.0555     0.2018  -5.230  1.69e-07 ***
period2      -0.8365     0.2951  -2.835  0.004582 ** 
period3      -0.7566     0.3182  -2.378  0.017421 *  
period4      -1.1718     0.3537  -3.314  0.000921 ***
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

(Dispersion parameter for binomial family taken to be 1)

mbest documentation built on May 30, 2017, 12:43 a.m.