A formula such as "Reaction ~ Days + (Days | Subject)".
The data frame: an object of columns.
Optionaloptions: LmerOptions
REML, and contrasts and levels as in lm (see LmerOptions for the keys accepted).
// 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
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()andisSingular().The formula has random-effects terms
(lhs | group)(correlated effects of the columns oflhswithin each level ofgroup) or(lhs || group)(uncorrelated);groupmay bea:b(the combinations),a/b(nested:b:aanda) 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 (rowslists 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
lmerreturned itself: a copy of it (structuredClone,{ ...fit }, JSON orpostMessage) lacks the internal values they use and is a TypeError. The fields of a copy keep their values.