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

12 ビュー (過去 30 日間)
Gediyon Moges Girma 2019 年 12 月 19 日
コメント済み: Junxi Zhang 2020 年 2 月 3 日
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?
##### 2 件のコメント表示非表示 1 件の古いコメント
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
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
%%
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
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
%%
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
RMSE = (mean(residual.^2))^0.5
SSE = sum (residual.^2)
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 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 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.

サインインしてコメントする。

R2018a

### Community Treasure Hunt

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

Start Hunting!

Translated by