Linear mixed-effects model class

A `LinearMixedModel`

object represents a model
of a response variable with fixed and random effects. It comprises
data, a model description, fitted coefficients, covariance parameters,
design matrices, residuals, residual plots, and other diagnostic information
for a linear mixed-effects model. You can predict model responses
with the `predict`

function and generate random data
at new design points using the `random`

function.

You can fit a linear mixed-effects model using `fitlme(tbl,formula)`

if
your data is in a table or dataset array. Alternatively, if your model
is not easily described using a formula, you can create matrices to
define the fixed and random effects, and fit the model using `fitlmematrix(X,y,Z,G)`

.

anova | Analysis of variance for linear mixed-effects model |

coefCI | Confidence intervals for coefficients of linear mixed-effects model |

coefTest | Hypothesis test on fixed and random effects of linear mixed-effects model |

compare | Compare linear mixed-effects models |

covarianceParameters | Extract covariance parameters of linear mixed-effects model |

designMatrix | Fixed- and random-effects design matrices |

disp | Display linear mixed-effects model |

fit | Fit linear mixed-effects model using tables |

fitmatrix | Fit linear mixed-effects model using design matrices |

fitted | Fitted responses from a linear mixed-effects model |

fixedEffects | Estimates of fixed effects and related statistics |

plotResiduals | Plot residuals of linear mixed-effects model |

predict | Predict response of linear mixed-effects model |

random | Generate random responses from fitted linear mixed-effects model |

randomEffects | Estimates of random effects and related statistics |

residuals | Residuals of fitted linear mixed-effects model |

response | Response vector of the linear mixed-effects model |

In general, a formula for model specification
is a string of the form `'y ~ terms'`

. For the linear
mixed-effects models, this formula is in the form ```
'y ~ fixed
+ (random1|grouping1) + ... + (randomR|groupingR)'
```

, where `fixed`

and `random`

contain
the fixed-effects and the random-effects terms.

Suppose a table `tbl`

contains the following:

A response variable,

`y`

Predictor variables,

`X`

, which can be continuous or grouping variables_{j}Grouping variables,

`g`

,_{1}`g`

, ...,_{2}`g`

,_{R}

where the grouping variables in `X`

and _{j}`g`

can
be categorical, logical, character arrays, or cell arrays of strings._{r}

Then, in a formula of the form, `'y ~ fixed + (random`

,
the term _{1}|g_{1})
+ ... + (random_{R}|g_{R})'`fixed`

corresponds to a specification of
the fixed-effects design matrix `X`

, `random`

_{1} is
a specification of the random-effects design matrix `Z`

_{1} corresponding
to grouping variable `g`

_{1},
and similarly `random`

_{R} is
a specification of the random-effects design matrix `Z`

_{R} corresponding
to grouping variable `g`

_{R}.
You can express the `fixed`

and `random`

terms
using Wilkinson notation.

Wilkinson notation describes the factors present in models. The notation relates to factors present in models, not to the multipliers (coefficients) of those factors.

Wilkinson Notation | Factors in Standard Notation |
---|---|

`1` | Constant (intercept) term |

`X^k` , where `k` is a positive
integer | `X` , `X` ,
..., `X` |

`X1 + X2` | `X1` , `X2` |

`X1*X2` | `X1` , `X2` , ```
X1.*X2
(elementwise multiplication of X1 and X2)
``` |

`X1:X2` | `X1.*X2` only |

`- X2` | Do not include `X2` |

`X1*X2 + X3` | `X1` , `X2` , `X3` , `X1*X2` |

`X1 + X2 + X3 + X1:X2` | `X1` , `X2` , `X3` , `X1*X2` |

`X1*X2*X3 - X1:X2:X3` | `X1` , `X2` , `X3` , `X1*X2` , `X1*X3` , `X2*X3` |

`X1*(X2 + X3)` | `X1` , `X2` , `X3` , `X1*X2` , `X1*X3` |

Statistics and Machine Learning Toolbox™ notation always includes a constant term
unless you explicitly remove the term using `-1`

.
Here are some examples for linear mixed-effects model specification.

**Examples:**

Formula | Description |
---|---|

`'y ~ X1 + X2'` | Fixed effects for the intercept, `X1` and `X2` .
This is equivalent to `'y ~ 1 + X1 + X2'` . |

`'y ~ -1 + X1 + X2'` | No intercept and fixed effects for `X1` and `X2` .
The implicit intercept term is suppressed by including `-1` . |

`'y ~ 1 + (1 | g1)'` | Fixed effects for the intercept plus random effect for the
intercept for each level of the grouping variable `g1` . |

`'y ~ X1 + (1 | g1)'` | Random intercept model with a fixed slope. |

`'y ~ X1 + (X1 | g1)'` | Random intercept and slope, with possible correlation between
them. This is equivalent to `'y ~ 1 + X1 + (1 + X1|g1)'` . |

`'y ~ X1 + (1 | g1) + (-1 + X1 | g1)' ` | Independent random effects terms for intercept and slope. |

`'y ~ 1 + (1 | g1) + (1 | g2) + (1 | g1:g2)'` | Random intercept model with independent main effects for `g1` and `g2` ,
plus an independent interaction effect. |

Value. To learn how value classes affect
copy operations, see Copying Objects in
the MATLAB^{®} documentation.

Was this topic helpful?