How can put random effects in the formula of Fit linear mixed model?

3 views (last 30 days)
Suppose we have the data set :
ID Res X1 X2 Z1 Z2
1 1 1.5 22 2.3 657
1 2 1.8 23 2.4 674
2 3 2.1 18 2.5 681
2 1 2.5 20 2.4 682
3 2 1.9 21 2.4 684
3 3 1.5 25 2.1 674
(ID: Id number, Res: Response, X1,X2: fixed effects, Z1,Z2: random effect)
To fit Y=XA+ZB I can use lme = fitlme(tbl,formula) in Matlab so I make the table
tbl=table(D(:,1),D(:,2),D(:,3),D(:,4),D(:,5),D(:,6),'VariableNames',{'Id','Response','FE1','FE2','RE1','RE1'});
Now to fit we need to use
lme = fitlme(tbl,'y ~ fixed + (random1|grouping1) + ... + (randomR|groupingR)');
So I put Response, FE1 and FE2 as y and fixed respectively:
lme = fitlme(tbl,'Response ~ FE1 + FE2 + (RF1|???)+(RF2|???)');
In the Matlab we need to use the grouping variables for the formula where the grouping variables can be categorical, logical, character arrays, or cell arrays of strings.
My question is how can make the grouping variables ?! or how put random effects RF1 and RF2 in the formula with respect my data? or which formula is correct for my data?
I do not understand why matlab needs to grouping variables?!
Bests Ali

Answers (1)

Gautam Pendse
Gautam Pendse on 19 Nov 2015
Have a look at the examples here:
You can use "categorical" to work with categorical data. Have a look at this page:
Hope this helps,
Gautam

Community Treasure Hunt

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

Start Hunting!