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