Categories &

Functions List

Function Reference: fitlme

statistics: lme = fitlme (tbl, formula)
statistics: lme = fitlme (…, name, value)

Fit a linear mixed-effects model specified by a formula.

fitlme (tbl, formula) fits the linear mixed-effects model described by formula to the variables in the table tbl, and returns a LinearMixedModel object.

formula is a character vector in Wilkinson notation extended with random-effects terms, for example "y ~ x1 + x2 + (1 | g)". The part to the left of ~ names the response; the fixed-effects part uses the usual operators (+, *, :, ^, and -1 to drop the intercept); and each random-effects term (expr | group) adds random intercepts and slopes expr grouped by the factor group (or an interaction of factors, e.g. g1:g2). As with fixed effects, a random intercept is implicit unless suppressed with 0 or -1.

Rows of tbl with missing values in any model variable are removed before fitting.

The following name/value pairs are accepted:

"FitMethod"
The estimation criterion, "ML" (maximum likelihood, the default) or "REML" (restricted maximum likelihood).

See also: LinearMixedModel, fitlmematrix, fitlm, parseWilkinsonFormula

Source Code: fitlme

Random-intercept model: sleep-study-like data with per-subject intercepts.

 subject = reshape (repmat (1:6, 5, 1), [], 1);
 days = repmat ((0:4)', 6, 1);
 b0 = reshape (repmat ([1 -1 0.5 -0.5 0.2 -0.2], 5, 1), [], 1);
 y = 250 + 10 * days + 15 * b0 + 3 * sin (1:30)';
 tbl = table (y, days, subject);
 lme = fitlme (tbl, "y ~ days + (1 | subject)", "FitMethod", "REML");
 disp (lme.Coefficients);
  2x7 table

                   Estimate       SE        tStat     DF    pValue     Lower      Upper     
                   ________    ________    _______    __    ______    _______    _______    

    (Intercept)     250.594     4.40499    56.8886    28         0     241.57    259.617    
    days            9.71719    0.304485    31.9135    28         0    9.09348    10.3409