필터 지우기
필터 지우기

Save coefficients from fitlme function in a table

조회 수: 9 (최근 30일)
alphabetagamma
alphabetagamma 2022년 7월 30일
댓글: Abderrahim. B 2022년 7월 30일
I am running a fixed effects model using the lme function and would like to save the coefficients in a table. I tried the following
coefficient_table = cell2table(cell(0,4), 'VariableNames', {'Estimate', 'SE', 'tStat', 'pValue'});
fe = fitlme(data_table, strcat(var1, '~', var2));
value = fe.Coefficients(2:end, :);
However, class(value) is 'classreg.regr.lmeutils.titleddataset', and not a table. The same problem does not arise when I fit a linear regreression model with fitlm function. Then, the class(value) = table
Ultimately, I want to save all the coefficients in
coefficient_table = [coefficient_table; value];
How can I convert the class of value to a table? Or is there another way to save the coefficients into a table? I'd really appreciate your help.

채택된 답변

Abderrahim. B
Abderrahim. B 2022년 7월 30일
Hi
You need to use dataset2table.
Demo:
load imports-85
tbl = table(X(:,12),X(:,14),X(:,24),'VariableNames',{'Horsepower','CityMPG','EngineType'});
head(tbl, 5)
ans = 5×3 table
Horsepower CityMPG EngineType __________ _______ __________ 111 21 13 111 21 13 154 19 37 102 24 35 115 18 35
%
lme = fitlme(tbl,'CityMPG~Horsepower+(1|EngineType)+(Horsepower-1|EngineType)');
% Retrieve and convert to table fitlme coefficients
coef_tbl = dataset2table(lme.Coefficients)
coef_tbl = 2×8 table
Name Estimate SE tStat DF pValue Lower Upper _______________ ________ _______ ______ ___ __________ ________ _________ {'(Intercept)'} 37.276 2.8556 13.054 201 1.3147e-28 31.645 42.906 {'Horsepower' } -0.12631 0.02284 -5.53 201 9.8848e-08 -0.17134 -0.081269
% In case you want to convert Name from cell to categorical.
coef_tbl.Name = categorical(coef_tbl.Name)
coef_tbl = 2×8 table
Name Estimate SE tStat DF pValue Lower Upper ___________ ________ _______ ______ ___ __________ ________ _________ (Intercept) 37.276 2.8556 13.054 201 1.3147e-28 31.645 42.906 Horsepower -0.12631 0.02284 -5.53 201 9.8848e-08 -0.17134 -0.081269
Hope this helps
  댓글 수: 2
alphabetagamma
alphabetagamma 2022년 7월 30일
편집: alphabetagamma 2022년 7월 30일
Thank you, that was very helpful. :)
Abderrahim. B
Abderrahim. B 2022년 7월 30일
My pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by