How to find r square in matlab

1,252 views (last 30 days)
Pooja
Pooja on 17 Sep 2014
Answered: TheodorM1991 on 4 Oct 2017
I need to find R square value from my data. I could get the command 'rsquare' from some online source. But when I tried to use it in matlab2013, it is giving error
rsquare(X(:,1),X_du(:,1))
Undefined function 'rsquare' for input arguments of type 'double'.
Even help rsquare gives
rsquare not found.
Please help to find rsquare. Thanks in advance

Accepted Answer

Guillaume
Guillaume on 17 Sep 2014
As Michael said, you need to make the rsquare function you've downloaded available to matlab. I'm not going to repeat what he said, so if it's all you want accept his answer.
However, also have a look at this page from matlab's help which explains in great details how to calculate R^2 using standard matlab functions. No downloads or toolbox required.
  1 Comment
Qiang Sun
Qiang Sun on 22 Jul 2017
Edited: Qiang Sun on 22 Jul 2017
R^2 CAN be delivered with Matlab intrinsic functions!

Sign in to comment.

More Answers (3)

Qiang Sun
Qiang Sun on 22 Jul 2017
There are at least two ways to get R^2 with MATLAB intrinsic functions.
1. using MATLAB multiple linear regression function " regress ". The "stats(1)" will give you R^2.
2. using MATLAB correlation coefficients function " corrcoef ", which gives you the R. So the R.*R shows you the R^2.

Michael Haderlein
Michael Haderlein on 17 Sep 2014
rsquare is not a function which is delivered with Matlab. Either you have to write it by yourself or you find some source (e.g. file exchange). In any case, the function must be in a directory which is listed in the Matlab path. So, usually you would
- save it in your Documents\Matlab folder or
- you add the respective path with addpath() or with a right click in the Matlab current folder window or, third option,
- you set this folder as your current folder.
  1 Comment
Qiang Sun
Qiang Sun on 22 Jul 2017
Edited: Qiang Sun on 22 Jul 2017
R^2 CAN be delivered with Matlab intrinsic functions!

Sign in to comment.


TheodorM1991
TheodorM1991 on 4 Oct 2017
For Matlab 2013 which I am using at work, if you do a linear regression for instance you must define an object: Mdl1=LinearModel.fit(x,y);(so you use LinearModel.fit) Then, for R^2, you use Mdl1.Rsquared.Ordinary or Mdl1.Rsquared.Adjusted. In fact all you have to do for accessing a property is to create the model and Double Click on It.You will see exactly in the header the name and how to write it on keyboard.

Community Treasure Hunt

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

Start Hunting!