LinearModel.fit results to array
7 views (last 30 days)
Show older comments
Hi,
I would like to ask about results from LinearModel.fit function. I used the function and it ran smoothly. However, I could not extract the result properly.
I have a 100 set of X and Y. What I would like to have is a array showing coefficient and R-square of all. I basically try to do a loop and have LinearModel.fit function inside. My problem is I could not write out coefficient from mdl.Coefficients and r-square from mdl.Rsquared.Ordinary value to save into my array.
I crated array 100 x 1 to save R-square value from each set. To sum up, how can I save the values of results from each set to array?
Thank you.
0 Comments
Answers (3)
Leah
on 26 Aug 2013
I was able to do it, i made a dataset mid to hold everything
md = LinearModel.fit()
mid.RsqAdj=md.Rsquared.Adjusted;
mid.Intercept=md.Coefficients.Estimate(1);
for c=2:length(md.CoefficientNames)
mid.(md.CoefficientNames{c})=md.Coefficients.Estimate(c);
end
the cyclist
on 26 Aug 2013
mdl.Coefficients
is a variable of type dataset.
mdl.Coefficients.Estimate
will be an array of doubles, which I think is what you need.
2 Comments
the cyclist
on 27 Aug 2013
Does calling this code give you a 5x1 double for mdl.Coefficients.Estimate?
load hald
X = ingredients; % predictor variables
y = heat; % response
mdl = LinearModel.fit(X,y)
mdl.Coefficients.Estimate
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!