MATLAB: How to obtain the R-squared and adjusted R-squared values from STEPWISEFIT in the Statistics Toolbox R2011a (Statistics Toolbox version 7.5)

adjustedr-squaredStatistics and Machine Learning Toolboxstepwisefit

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?

Best Answer

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.