How to find r square in matlab

1,078 次查看(过去 30 天)
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

采纳的回答

Guillaume
Guillaume 2014-9-17
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 个评论
Qiang Sun
Qiang Sun 2017-7-22
编辑:Qiang Sun 2017-7-22
R^2 CAN be delivered with Matlab intrinsic functions!

请先登录,再进行评论。

更多回答(3 个)

Qiang Sun
Qiang Sun 2017-7-22
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 2014-9-17
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 个评论
Qiang Sun
Qiang Sun 2017-7-22
编辑:Qiang Sun 2017-7-22
R^2 CAN be delivered with Matlab intrinsic functions!

请先登录,再进行评论。


TheodorM1991
TheodorM1991 2017-10-4
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!

Translated by