How can put random effects in the formula of Fit linear mixed model?
조회 수: 3 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Gautam Pendse
2015년 11월 19일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!