Using Linear Mixed Models with two fixed factors and a random factor
5 views (last 30 days)
Show older comments
Hari krishnan
on 11 Oct 2021
Commented: the cyclist
on 11 Oct 2021
I am trying to make a Linear Mixed Model to see if there is a statistical significance with two fixed factors ('ANTS and LABEL') with the ('STATE') as a random factor. Can anyone suggest to me how to proceed with such a model in Matlab?
Data file is attached alongside a sample code. Is the code right?
m = fitlme(data, 'RATE ~ (ANT*LABEL) + (1 | STATE)');
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF pValue Lower Upper
{'(Intercept)' } 0.033027 0.0056879 5.8065 294 1.6533e-08 0.021832 0.044221
{'ANTS' } -0.00012262 0.00065256 -0.1879 294 0.85108 -0.0014069 0.0011617
{'LABEL_Poor nest' } -0.015508 0.0080189 -1.934 294 0.054076 -0.03129 0.00027342
{'ANTS:LABEL_Poor nest'} 0.00036122 0.0009203 0.3925 294 0.69497 -0.00145 0.0021724
0 Comments
Accepted Answer
the cyclist
on 11 Oct 2021
Edited: the cyclist
on 11 Oct 2021
You can fit such a model using the fitlme function from the Statistics and Machine Learning Toolbox.
I think the following code fits the model you mentioned:
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/764231/Entry_rates.xlsx'); % You can just read in your local file
mdl = fitlme(data,'RATE ~ ANTS + LABEL + (1|STATE)')
But I strongly recommend you read the documentation carefully, to understand how to specify the model you want to fit.
6 Comments
the cyclist
on 11 Oct 2021
The first model I suggested treats ANTS as continuous numeric by default, so we need to convert it to categorical before putting it in the model.
This model has the interaction term as well:
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/764231/Entry_rates.xlsx'); % You can just read in your local file
data.ANTS = categorical(data.ANTS);
m = fitlme(data, 'RATE ~ (ANTS*LABEL) + (1 | STATE)')
Does that align better with the output you would expect, and can interpret?
More Answers (0)
See Also
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!