Calculate adjusted R2 for constant model

Is there a way of calculating the adjusted R2 of a constant model (y= constant) for a set of fitted data in Matlab?

 Accepted Answer

R2=1-mean((y-constant).^2)/var(y);

3 Comments

Thanks! And what about adjusted R2? (So there is no table for matlab to show automatically? Like in the fitlm, it can do that.)
And what about adjusted R2?
I believe for a constant model, R2 and adjusted R2 are the same.
(So there is no table for matlab to show automatically? Like in the fitlm, it can do that.)
With a constant model, fitlm will just estimate the constant as the mean of the data, giving R2 and adjusted R2 equal to zero. Since R2 is trivial in this case, I guess the ouput display doesn't show it, but you can still access it from the output, e.g.,
mdl=fitlm(1:10,rand(1,10),'constant');
mdl.Rsquared
ans = struct with fields:
Ordinary: 0 Adjusted: 0
Thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 15 Mar 2022

Commented:

on 16 Mar 2022

Community Treasure Hunt

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

Start Hunting!