rStats.js v1.3.0
    Preparing search index...

    Function glmer

    • Fit a generalized linear mixed model by the Laplace approximation (nAGQ = 1, default), by adaptive Gauss-Hermite quadrature (nAGQ from 2 to 100) or with the fixed effects from the penalised IRLS (nAGQ = 0). Equivalent to lme4::glmer() in R. With the quantities of its methods: fixef(), coef(summary()) (without p-values), vcov(), sigma(), VarCorr(), ranef(), fitted(), predict(), residuals() of the four types, deviance(), logLik(), AIC(), BIC() and isSingular().

      The families are binomial, poisson, Gamma, inverse.gaussian and gaussian (not with the identity link: that is lmer), with the links of glm and lme4's own inverse links and variance functions. The formula is as in lmer; a binomial response may be 0/1 values, booleans, strings or a factor (the first level failure), proportions with the numbers of trials as weights, or cbind(successes, failures) with two column names on the left-hand side.

      The estimate is the exact minimiser of the Laplace deviance computed at the exact conditional mode of the random effects (lme4's optimiser and its penalised IRLS stop early, so lme4's values typically differ in the 4th to 6th significant digit, its standard errors by up to about 1%). Elements of θ on the boundary are exactly 0, and the fit is then singular. lme4's warnings about its optimiser and its convergence checks are not given.

      The scale of the response: lme4's Laplace criterion leaves out the dispersion, so for the poisson, inverse.gaussian and gaussian families it is not invariant to the scale of the response (or of the prior weights). Where the information about the random effects at the start, Σ W z² of a column of Z (W the working weights at the starting means), is above 2^40 (the penalised system then loses about 40 of its 53 bits), or below 2^-40 and the fit fails or a term ends at θ = 0 on a criterion flat to rounding, the result is a RangeError saying so. For data like the example below: poisson counts up to about 1e11 (prior weights up to about 2^34), inverse.gaussian with the log link up to about 1e13, gaussian with the log link from about 1e-6 to 5e4 fit; beyond, the RangeError. Gamma fits are not limited by the scale of the response (its criterion is invariant; with the log link a tiny response is rescaled).

      Adaptive Gauss-Hermite quadrature (nAGQ > 1) needs a single scalar random-effects term such as (1 | g), with R's errors otherwise. It is offered for binomial and poisson only: for Gamma, inverse.gaussian and gaussian it is a RangeError, since lme4 holds the dispersion at 1 there, so that its estimates would not be maximum likelihood. Its logLik, AIC and BIC are those of the log-likelihood, unlike R's, which leave out the constant of the saturated model (aic − Σ deviance residuals) for nAGQ > 1: they differ from R's by that constant and are comparable with the Laplace fit's.

      Parameters

      • formula: string

        A formula such as "cbind(inc, notinc) ~ period + (1 | herd)" or "y ~ x + (1 | g)".

      • data: DataFrame

        The data frame: an object of columns.

      • Optionaloptions: GlmerOptions

        family, link, weights, offset, nAGQ, start, and contrasts and levels as in lmer (see GlmerOptions for the keys accepted).

      Returns GlmerResult

      // R: lme4::glmer(y ~ x + (1 | g), data, family = poisson)
      const fit = glmer("y ~ x + (1 | g)", {
      y: [2, 3, 6, 7, 8, 1, 0, 3, 2, 5, 4, 6, 9, 8, 13, 0, 2, 1, 4, 3],
      x: [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5],
      g: ["a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "d", "d", "d", "d", "d"],
      }, { family: "poisson" });
      fit.fixef; // [0.2512, 0.3242]
      fit.coefTable.stdError; // [0.4183, 0.08098]
      fit.varCorr[0].sd; // [0.5423]
      fit.ranef[0].values; // [[0.2840], [-0.4170], [0.6920], [-0.4819]]
      fit.logLik; // -39.392