How to extract coefficients values from a regression model results? How to clear?
조회 수: 15 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Saptarshi
2023년 5월 2일
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
Very Determined
2023년 5월 11일
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.
참고 항목
카테고리
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!