Thomas Jason
Thomas Jason

Reputation: 568

How to calculate 'compare' funtion in Matlab

I am studying Root-Mean-Square Error (RMSE) and Normalized Root-Mean-Square Error (NRMSE).

According to Wikipedia's article and according to Matlab's function.

Why is the NRMSE value different between NRMSE manually by Wikipedia and NRMSE by compare code of MATLAB?

Could you teach me how to calculate compare function mathematically?

For example, I made like below. The method by Wikipedia:

Vt = 1:11;
V1 = [11.5 7.6 6.7 8.3 7.7 7.4 6.5 5.6 6.6 11.2 11.9]; % obseved data
V2 = [11.9 10.8 8.3 9.6 11.4 10.2 12.4 9.6 8.3 8 9]; % estimationd data
RMSE = sqrt(mean((V1-V2).^2)); % RMSE = 3.14107
NRMSE = RMSE/(max(V2)-min(V2)) % NRMSE = 0.71

The compare inner function of MATLAB:

% to use compare
VV1 = iddata(V1', Vt');
VV2 = iddata(V2', Vt');
compare(VV1,VV2) % -48.46%

Upvotes: 1

Views: 997

Answers (1)

alpereira7
alpereira7

Reputation: 1550

According to compare documentation, the estimation of NRMSE by Matlab is not the same as yours.

You need to know that there are many ways to calculate RMSE and NRMSE. From the Wikipedia article you linked on Root-mean-square deviation:

there is no consistent means of normalization in the literature.

You chose one way, and Matlab has another.

fit

So if you want to match Matlab's results, you should do:

NRMSE = 100*(1 - norm(V1-V2)/norm(V1-mean(V1)))
[y,fit,x0] =compare(VV1,VV2); fit

This returns

 NRMSE =
  -48.4595

 fit =
  -48.4595

Upvotes: 2

Related Questions