Save coefficients from fitlme function in a table
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
alphabetagamma
am 30 Jul. 2022
Kommentiert: Abderrahim. B
am 30 Jul. 2022
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.
0 Kommentare
Akzeptierte Antwort
Abderrahim. B
am 30 Jul. 2022
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)
%
lme = fitlme(tbl,'CityMPG~Horsepower+(1|EngineType)+(Horsepower-1|EngineType)');
% Retrieve and convert to table fitlme coefficients
coef_tbl = dataset2table(lme.Coefficients)
% In case you want to convert Name from cell to categorical.
coef_tbl.Name = categorical(coef_tbl.Name)
Hope this helps
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dimensionality Reduction and Feature Extraction finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!