Bootstrap linear regression MSE
7 views (last 30 days)
Show older comments
I am trying to use bootstrap on the MSE, R-squared output generated from linear regression model. However, I am having trouble figuring out how to set it up with the correct arguments.
I tried to do something like:
X1 = outcomes;
X2 = modcomes;
mdl = LinearModel.fit(X1, X2);
resid = outcomes - modcomes;
% Simple bootstrap example
N_Boot = 1000;
SSE = zeros(N_Boot,1);
R_Sqrd = zeros(N_Boot,1);
for i = 1:N_Boot
[foo_b , GoF_b] = LinearModel.fit(modcomes, outcomes + resid);
SSE(i) = GoF_b.sse;
R_Sqrd(i) = GoF_b.rsquare;
end
mean(SSE)
std(SSE)
mean(R_Sqrd)
std(R_Sqrd)
1 Comment
Adam Danz
on 28 Jul 2019
Edited: Adam Danz
on 28 Jul 2019
If you're using matlab r2013b or later, you should use fitlm() instead of LinearModel.fit(). They have virtually the same inputs and both produce the LinearModel object. The model contains a field "Residuals" that contains (you guessed it) the residuals of the model. There is no documented second output and I haven't tried doing that myself so I'm not sure what's in the 2nd output in your code.
What are modcomes and outcomes?
Answers (0)
See Also
Categories
Find more on Linear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!