Mixed terms and fitlmematrix

4 views (last 30 days)
Andrew
Andrew on 18 Oct 2013
Answered: Peng Li on 7 Aug 2020
Hi all,
I'm trying to create a linear mixed effect model where I have three fixed effects (X1, X2, X3) and one random effect (Z1) using fitlmematrix.m.
The issue I'm having is that I'm not sure how to get results for "mixed" terms, i.e. X1*X2, X2*X3, X1*X2*X3. When I look up the help for the linear mixed model class I can see the "Formula" member, but I'm not sure how to specify it when calling fitlmematrix.m.
I'm under the impression that LMMs handle mixed terms differently to including them directly in the system matrix (i.e. creating X4 = X1*X2 etc).
Any help on how to get the mixed terms into the model would be greatly appreciated, Andrew

Answers (1)

Peng Li
Peng Li on 7 Aug 2020
For new versions of MATLAB, you can use fitlm, fitlme, fitglme which allows table input, and allows formulas.
But if you use fitlmematrix, you can generate the interaction items manually but timing the two variables, or three variables together. You may need to center the continuous variables in order for a 'meaningful' results.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!