Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Calculating R^2 using Robust fit with nlinfit

Subject: Calculating R^2 using Robust fit with nlinfit

From: Sumit

Date: 13 Mar, 2012 21:57:19

Message: 1 of 5

Hello,

I am using nlinfit function to do Robust Regression. I want to calculate R^2.

C = corrcoef(yfit, y);
Rsq = C(1,2)^2;

I am also Calculating RSquare as follows.

Rsq1 = 1 - sum(r.^2)/sum((y - mean(y)).^2);

Rsq is equal to Rsq1 if the Robust regression is off. However, if I use the 'Robust' option, then Rsq is not equal to Rsq1.

Can somebody explain the reason for this.

Sums80

Subject: Calculating R^2 using Robust fit with nlinfit

From: Bruno Luong

Date: 14 Mar, 2012 06:52:10

Message: 2 of 5

Just a guess, but Robust could remove some outliner data, thus R^2 changes.

Bruno

Subject: Calculating R^2 using Robust fit with nlinfit

From: Phil Goddard

Date: 14 Mar, 2012 14:48:12

Message: 3 of 5

A description of what the robust fit does is given (near the end) of the documentation,

http://www.mathworks.com/help/toolbox/stats/nlinfit.html

Phil.

Subject: Calculating R^2 using Robust fit with nlinfit

From: Tom Lane

Date: 14 Mar, 2012 15:15:24

Message: 4 of 5

> C = corrcoef(yfit, y);
> Rsq = C(1,2)^2;
>
> Rsq1 = 1 - sum(r.^2)/sum((y - mean(y)).^2);
>
> Rsq is equal to Rsq1 if the Robust regression is off. However, if I use
> the 'Robust' option, then Rsq is not equal to Rsq1.

That's right, the two are the same for least squares.

It's not so clear about how to define R-square for robust fits. We know a
least squares fit maximizes R-square, so the usual definition will never
yield a better R-square for a robust fit. Other definitions might replace
the residuals in the formula you wrote with some sort of weighted values, or
might replace the sum of squared residuals by a multiple of a robust
estimate of the error variance.

If there's a standard definition in use, I haven't seen it (but would like
to).

-- Tom

Subject: Calculating R^2 using Robust fit with nlinfit

From: eliasestatistica@gmail.com

Date: 6 Sep, 2013 23:30:44

Message: 5 of 5

It's just you get the gradient matrix, and from it obtain a linear model, just so you can determine the R2.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us