How is R-square calculated in curve fitting tool for LAR and bisqaure robust fit option?

5 views (last 30 days)
I find that for a polynomial fit with Bisquare or LAR robust fit option, the r-square value I calculate doesn't match with the curve fitting tool result. does the curve fitting tool use a different formulation than the one explained in here?
please help.
  2 Comments
Rik
Rik on 20 Dec 2019
Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue. That would help to determine if there is a float rounding error, a bug in your code, or a bug in Matlab.
Gediyon Moges Girma
Gediyon Moges Girma on 20 Dec 2019
as an Example, let's try to predict y from an independent variable x,
x = [1; 2 ;3 ;4; 5];
y = [1 ;12; 20; 8; 46];
fit the above data with a polynomial fit of second order. For different selection of robust fit option, I calculated the r-square, adjusted r-sq, RMSE and SSE using the following formulation.
%%
predicted = 2.429*x.^2 -5.971*x+8.6; % Robust off
y_mean = mean (y);
st = sum ((y_mean-y).^2);
sr = sum(( y - predicted).^2);
r2 = (st-sr)/st
residual = predicted-y;
n = size (y,1); % the number of observation
p = 3; % number of coefficient
R_sq_adj = 1-((n-1)/(n-p))*(sr/st) % adjusted r-square
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
robust off.JPG
%%
predicted = 2.365*x.^2 -5.585*x+8.212; % bisquare result
y_mean = mean (y);
st = sum ((y_mean-y).^2);
sr = sum(( y - predicted).^2);
r2 = (st-sr)/st
residual = predicted-y;
n = size (y,1); % the number of observation
p = 3; % number of coefficient
R_sq_adj = 1-((n-1)/(n-p))*(sr/st) % adjusted r-square
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
bisquare.JPG
%%
predicted = 0.875*x.^2 +6*x-5.875; % LAR result
y_mean = mean (y);
st = sum ((y_mean-y).^2);
sr = sum(( y - predicted).^2);
r2 = (st-sr)/st
residual = predicted-y;
n = size (y,1); % the number of observation
p = 3; % number of coefficient
R_sq_adj = 1-((n-1)/(n-p))*(sr/st) % adjusted r-square
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
LAR.JPG
It can be observed that there is variation between my calculated result and the curve fitting tool. and I can't figure out why. This difference is not only in the r-sq value but also on RMSE and SSE as well.

Sign in to comment.

Answers (1)

ME
ME on 20 Dec 2019
Does this link help at all?
It looks like LAR doesn't so much minimise an R^2 value but rather minimises the absolute differences. Could that be your issue and why they don't match?
  1 Comment
Junxi Zhang
Junxi Zhang on 3 Feb 2020
LAR minimize the absolute differences, so the fitted model using LAR has different coefficients. That's easy to understand.
However, if we use function "fit" with LAR in command line as well as app "curve fitting tool", the coefficients are the same but the goodness of fit is different. That is to say, SSE, R-sqaure and RMSE are much better in app "curve fitting tool" than in function "fit", which is the same as values calculated manually.

Sign in to comment.

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!