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

조회 수: 4 (최근 30일)
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
Rik
Rik 2019년 12월 20일
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 2019년 12월 20일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

ME
ME 2019년 12월 20일
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
Junxi Zhang
Junxi Zhang 2020년 2월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by