Azzera filtri
Azzera filtri

How to extract coefficients values from a regression model results? How to clear?

24 visualizzazioni (ultimi 30 giorni)
Hello,
Could anybody help me please to extract the coefficients values (or other relevant data) from the model results such as: mdl.Coefficients
ans =
Estimate SE tStat pValue
_________ _________ _______ __________
b1 -0.17489 0.025051 -6.9813 2.0592e-07
b2 -0.47334 0.024024 -19.702 3.7536e-17
b3 -0.028464 0.0058363 -4.877 4.6488e-05
b4 -0.023999 0.0072508 -3.3099 0.0027401
I tried mdl.Coefficients (1,2) for instance, but this gives me a table like below instead of just the number (0.025051 in this case).
ans =
SE
________
b1 0.025051
I tried get command as well but it didn't work. Also I am wondering how I can clear a part of the regression results. I have a lot of observations that take the whole memory and I need to clear them from the mdl results. (like mdl.VariableInfo, mdl.ObservationInfo, etc.)
Thanks

Risposte (1)

Saptarshi
Saptarshi il 2 Mag 2023
Hi VD.
I had the very same question! It's a fundamental question, and points to a fundamental complaint that I have about MathWorks, and software companies in general. While Matlab's model-fitting commands are very powerful, what good is a program (or an algorithm) if you can't access the results?
Well, even though your question is "beneath" the geniuses at MathWorks to answer, I may have found a solution. The solution basically revolves around accessing the fitlm results as a sub-table, and then calling the first element (the number) within it.
To extract b1, or instance, try to get it by direct reference:
mdl.Coefficients(1,1).(1) % extracts b1 coefficient. (Or I have the array indices switched...)
mdl.Coefficients(1,2).(1) % This should extract the SE of b1, if that is what you are looking for
mdl.Coefficients(2,1).(1) % should extract b2
Try it out and please let us know if it works.
  1 Commento
Very Determined
Very Determined il 11 Mag 2023
Thanks for the response. I am done with the code as it dates back to years ago. I will try it once I got chance to rework on the same problem and I will let you know then.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by