How to find r square in matlab
498 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (3)
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
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!