Using Linear Mixed Models with two fixed factors and a random factor
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
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
채택된 답변
the cyclist
2021년 10월 11일
편집: the cyclist
2021년 10월 11일
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)')
mdl =
Linear mixed-effects model fit by ML
Model information:
Number of observations 298
Fixed effects coefficients 3
Random effects coefficients 11
Covariance parameters 2
Formula:
RATE ~ 1 + ANTS + LABEL + (1 | STATE)
Model fit statistics:
AIC BIC LogLikelihood Deviance
-1158.9 -1140.4 584.45 -1168.9
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF pValue Lower Upper
{'(Intercept)' } 0.031647 0.0044726 7.0757 295 1.0864e-11 0.022844 0.040449
{'ANTS' } 5.8999e-05 0.00046026 0.12819 295 0.89809 -0.00084681 0.00096481
{'LABEL_Poor nest'} -0.012768 0.0039439 -3.2373 295 0.0013442 -0.020529 -0.0050059
Random effects covariance parameters (95% CIs):
Group: STATE (11 Levels)
Name1 Name2 Type Estimate Lower Upper
{'(Intercept)'} {'(Intercept)'} {'std'} 7.5587e-18 NaN NaN
Group: Error
Name Estimate Lower Upper
{'Res Std'} 0.034041 0.031415 0.036887
But I strongly recommend you read the documentation carefully, to understand how to specify the model you want to fit.
댓글 수: 6
Hari krishnan
2021년 10월 11일
편집: Hari krishnan
2021년 10월 11일
In the model you have suggested, does the intercept means that their is a significant difference between the 'LABEL', while no significant difference between the 'ANTS' in each label?
I was wondering tha the output contains two P values for multiple labels..
You really should make sure you understand Wilkinson notiation, and how to specify the exact model you want.
The difference between your formula and mine is that your formula will include the interaction term ANTS*LABEL.
Thank you for your comment.
There is an interaction between the predictor variable (ANTS) and Category (LABEL) as they are related. But I should also get a P value for each 'LABEL' category as there are multiple groups in the each 'LABEL', right?
I have two questions, trying to clarify:
- Is ANTS a continuous variable, or categorical?
- Are you trying to predict RATE from ANTS and LABEL (with STATE as random)? Or are you trying to predict LABEL from ANTS (with STATE as random, and ignoring RATE)? Or something else?
- ANTS is a categorical variable
- I am trying to predict RATE from ANTS and LABEL (with STATE as random)
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)')
m =
Linear mixed-effects model fit by ML
Model information:
Number of observations 298
Fixed effects coefficients 32
Random effects coefficients 11
Covariance parameters 2
Formula:
RATE ~ 1 + ANTS*LABEL + (1 | STATE)
Model fit statistics:
AIC BIC LogLikelihood Deviance
-1102.9 -977.18 585.44 -1170.9
Fixed effects coefficients (95% CIs):
Name Estimate SE tStat DF pValue Lower Upper
{'(Intercept)' } 0.03472 0.010729 3.2361 266 0.0013653 0.013595 0.055845
{'ANTS_2' } -0.00018056 0.014824 -0.01218 266 0.99029 -0.029369 0.029007
{'ANTS_3' } -0.0037793 0.014824 -0.25494 266 0.79897 -0.032967 0.025409
{'ANTS_4' } -0.005943 0.014824 -0.40089 266 0.68882 -0.035131 0.023245
{'ANTS_5' } -0.003487 0.014824 -0.23522 266 0.81422 -0.032675 0.025701
{'ANTS_6' } 0.0032408 0.014824 0.21861 266 0.82712 -0.025947 0.032429
{'ANTS_7' } -0.0024946 0.014824 -0.16828 266 0.86649 -0.031683 0.026693
{'ANTS_8' } -0.0020313 0.014824 -0.13703 266 0.89111 -0.031219 0.027157
{'ANTS_9' } -0.0075855 0.014824 -0.5117 266 0.60929 -0.036773 0.021602
{'ANTS_10' } -0.0038417 0.014824 -0.25915 266 0.79572 -0.03303 0.025346
{'ANTS_11' } -0.0023158 0.015589 -0.14855 266 0.88202 -0.033009 0.028378
{'ANTS_12' } -0.0037099 0.01672 -0.22188 266 0.82458 -0.03663 0.029211
{'ANTS_13' } -0.0022144 0.01672 -0.13244 266 0.89474 -0.035135 0.030706
{'ANTS_14' } 0.00054688 0.01752 0.031214 266 0.97512 -0.03395 0.035043
{'ANTS_15' } -0.0039004 0.01752 -0.22262 266 0.824 -0.038397 0.030596
{'ANTS_16' } -0.0043122 0.018583 -0.23205 266 0.81668 -0.040901 0.032277
{'LABEL_Poor nest' } -0.011158 0.014824 -0.75269 266 0.4523 -0.040346 0.01803
{'ANTS_2:LABEL_Poor nest' } -0.0077307 0.020714 -0.37322 266 0.70928 -0.048514 0.033053
{'ANTS_3:LABEL_Poor nest' } 9.4789e-05 0.020714 0.0045762 266 0.99635 -0.040689 0.040878
{'ANTS_4:LABEL_Poor nest' } -0.0033669 0.020965 -0.1606 266 0.87253 -0.044645 0.037911
{'ANTS_5:LABEL_Poor nest' } -0.0050268 0.020714 -0.24268 266 0.80844 -0.04581 0.035757
{'ANTS_6:LABEL_Poor nest' } -0.0076487 0.020714 -0.36926 266 0.71223 -0.048432 0.033135
{'ANTS_7:LABEL_Poor nest' } -0.0012082 0.020714 -0.05833 266 0.95353 -0.041992 0.039575
{'ANTS_8:LABEL_Poor nest' } 0.00011595 0.020714 0.0055978 266 0.99554 -0.040668 0.0409
{'ANTS_9:LABEL_Poor nest' } 0.0022824 0.020714 0.11019 266 0.91234 -0.038501 0.043066
{'ANTS_10:LABEL_Poor nest'} 0.00078623 0.020714 0.037957 266 0.96975 -0.039997 0.04157
{'ANTS_11:LABEL_Poor nest'} -0.0023263 0.021807 -0.10667 266 0.91513 -0.045264 0.040611
{'ANTS_12:LABEL_Poor nest'} -0.00027695 0.023423 -0.011824 266 0.99058 -0.046396 0.045842
{'ANTS_13:LABEL_Poor nest'} -0.0039373 0.023423 -0.16809 266 0.86664 -0.050056 0.042182
{'ANTS_14:LABEL_Poor nest'} 0.00067151 0.024566 0.027335 266 0.97821 -0.047696 0.049039
{'ANTS_15:LABEL_Poor nest'} 0.0014948 0.024566 0.06085 266 0.95152 -0.046873 0.049863
{'ANTS_16:LABEL_Poor nest'} 0.0053685 0.026081 0.20584 266 0.83707 -0.045983 0.05672
Random effects covariance parameters (95% CIs):
Group: STATE (11 Levels)
Name1 Name2 Type Estimate Lower Upper
{'(Intercept)'} {'(Intercept)'} {'std'} 0 NaN NaN
Group: Error
Name Estimate Lower Upper
{'Res Std'} 0.033928 0.031311 0.036764
Does that align better with the output you would expect, and can interpret?
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Cluster Analysis and Anomaly Detection에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
