1

I'm doing a WLS estimation and actually the RMSE (Root mean square error) given by the "fitlm" function is different by the one calculated by hand.

Here there is the MATLAB code

%% Generating data
x=unifrnd(0,30,100,1);
y=sin(x).*x;

wi=x; % weights
m_hat=fitlm(x,y,'Weights',wi); % the model
b_hat = m_hat.Coefficients.Estimate; % coefficients
y_hat = b_hat(1)+b_hat(2)*x; % model estimation

% RMSE extracted
rmse=m_hat.RMSE; % rmse "extracted" from fitlm

% RMSE by hand
RMSE_with_formula=sqrt(sum((y-y_hat).^2)/m_hat.DFE))

Can somebody explain why? Which is the correct one? Thanks.

  • Where in the "hand" calculation do you include the weights? – whuber Apr 10 '19 at 14:09
  • i didn't calculated it with weights. Should i ? If yes, can you show me how the formula changes? My professor explained that only IC for coefficients changes on WLS respect on OLS or on a normal regression model. – Domenico Giambalvo Apr 10 '19 at 14:15
  • An unweighted RMSE hardly makes sense: it would be inconsistent with the purpose of the weights. Indeed, one wonders whether *any* RMSE would make sense in general: how would you interpret it? – whuber Apr 10 '19 at 14:21
  • yes, the RMSE has a general sense. But an unweighted RMSE in WLS model doesn't have sense. Where should i put the weights in the by "hand" formula? – Domenico Giambalvo Apr 10 '19 at 14:25
  • If in your code you do not divide by m_hat.DFE, do the results match? – James Phillips Apr 10 '19 at 15:36

0 Answers0