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

    Function lmer

    • Fit a linear mixed model by REML (default) or maximum likelihood. Equivalent to lme4::lmer() in R. With the quantities of its methods: fixef(), coef(summary()) (without p-values), vcov(), sigma(), VarCorr(), ranef(), fitted(), residuals(), logLik(), AIC(), BIC(), deviance(), REMLcrit() and isSingular().

      The formula has random-effects terms (lhs | group) (correlated effects of the columns of lhs within each level of group) or (lhs || group) (uncorrelated); group may be a:b (the combinations), a/b (nested: b:a and a) and so on, as in lme4. The fixed-effects part is coded as in lm; aliased columns are dropped (with a message). Rows with a missing value in a variable of the formula are dropped (rows lists those used).

      The covariance parameters θ are the lower triangles of the relative covariance factors of the terms; the estimate is the exact minimiser of the profiled criterion (lme4's optimiser stops close to it, so lme4's values typically differ in the 5th to 9th significant digit). Elements on the boundary are exactly 0, and the fit is then singular. The computation is sparse (a sparse Cholesky factorisation, as in lme4), so many groups are handled quickly.

      The functions that take the fit (lmerSummary, lmerAnova, lmerContest and the others) need the object lmer returned itself: a copy of it (structuredClone, { ...fit }, JSON or postMessage) lacks the internal values they use and is a TypeError. The fields of a copy keep their values.

      Parameters

      • formula: string

        A formula such as "Reaction ~ Days + (Days | Subject)".

      • data: DataFrame

        The data frame: an object of columns.

      • Optionaloptions: LmerOptions

        REML, and contrasts and levels as in lm (see LmerOptions for the keys accepted).

      Returns LmerResult

      // R: lme4::lmer(y ~ 1 + (1 | g), data)
      const fit = lmer("y ~ 1 + (1 | g)", {
      y: [9.8, 10.4, 10.1, 12.3, 12.9, 12.0, 8.1, 7.6, 8.4],
      g: ["a", "a", "a", "b", "b", "b", "c", "c", "c"],
      });
      fit.fixef; // [10.177778]
      fit.sigma; // 0.39299
      fit.varCorr[0].sd; // [2.1726]
      fit.ranef[0].levels; // ["a", "b", "c"]
      fit.ranef[0].values; // [[-0.076939], [2.1982], [-2.1213]]
      fit.REMLcrit; // 19.015