How can I obtain the R-squared and adjusted R-squared values from STEPWISEFIT in the Statistics Toolbox R2011a (Statistics Toolbox version 7.5)?

10 views (last 30 days)
I am using STEPWISEFIT as part of one of my programs. If I run STEPWISE (i.e. the GUI version), I can recover the R-squared and the adjusted R-squared values. However, if I use the programmatic function STEPWISEFIT, the R-squared and adjusted R-squared do not seem to be part of the outputs. How can I obtain these statistics?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Oct 2012
The R-squared and adjusted R-squared statistics are not available in the ‘stats’ output of the programmatic STEPWISEFIT function. As a workaround, you can derive the values of the R-squared and adjusted R-squared statistics from other values that are in the output, by using the following commands
[b,se,pval,inmodel,stats,nextstep,history] = stepwisefit(XX,y);
% To obtain R-squared values
n = length(y);
rsq = 1 - (history.rmse.^2/var(y)) .* ((n-1-history.df0)/(n-1))
% To obtain Adjusted R-Squared values.
adjrsq = 1 - history.rmse.^2/var(y)
Note that the RMSE field in "history" corresponds to the root mean square errors for the model at each step. Hence, "rsq" and "adjrsq" will be vectors, where the elements correspond to the R-squared values at different steps.

More Answers (0)

Products


Release

R2011a

Community Treasure Hunt

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

Start Hunting!