Effacer les filtres
Effacer les filtres

How to find r square in matlab

614 vues (au cours des 30 derniers jours)
Pooja
Pooja le 17 Sep 2014
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

Réponse acceptée

Guillaume
Guillaume le 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 commentaire
Qiang Sun
Qiang Sun le 22 Juil 2017
Modifié(e) : Qiang Sun le 22 Juil 2017
R^2 CAN be delivered with Matlab intrinsic functions!

Connectez-vous pour commenter.

Plus de réponses (3)

Qiang Sun
Qiang Sun le 22 Juil 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 le 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 commentaire
Qiang Sun
Qiang Sun le 22 Juil 2017
Modifié(e) : Qiang Sun le 22 Juil 2017
R^2 CAN be delivered with Matlab intrinsic functions!

Connectez-vous pour commenter.


TheodorM1991
TheodorM1991 le 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!

Translated by