Вопрос

I have two vectors of values and I want to compare them statistically. For simplicity assume A = [2 3 5 10 15] and B = [2.5 3.1 4.8 10 18]. I want to compute the standard deviation, the root mean square error (RMSE), the mean, and present conveniently, maybe as histogram. Can you please help me how to do it so that I understand? I know question is probably simple, but I am new into this. Many thanks!

edited: This is how I wanted to implement RMSE.

dt = 1;
for k=1:numel(A)
err(k)=sqrt(sum(A(1,1:k)-B(1,1:k))^2/k);
t(k) = dt*k; 
end

However it gives me bigger values than I expect, since e.g. 3 and 3.1 differ only in 0.1. This is how I calculate error between reference value of each cycle with corresponding estimated in that cycle. Can you tell me, am I doing right, or what's wrong?

abs_err = A-B;
Это было полезно?

Решение

The way you are looping through the vectors is not element by element but rather by increasing the vector length, that is, you are comparing the following at each iteration:

      A(1,1:k)    B(1,1:k)
      --------    --------
k=1   [2]         [2.5]
 =2   [2 3]       [2.5 3.1]
 =3   [2 3 5]     [2.5 3.1 4.8]
....

At no point do you compare only 2 and 2.1!

Assuming A and B are vectors of identical length (and both are either column or row vectors), then you want functions std(A-B), mean(A-B), and if you look in matlab exchange, you will find a user-contributed rmse(A-B) but you can also compute the RMSE as sqrt(mean((A-B).^2)). As for displaying a histogram, try hist(A-B).

In your case:

dt = 1;
for k=1:numel(A)
    stdab(k) = std(A(1,1:k)-B(1,1:k));
    meanab(k) = mean(A(1,1:k)-B(1,1:k));
    err(k)=sqrt(mean((A(1,1:k)-B(1,1:k)).^2));
    t(k) = dt*k; 
end

You can also include hist(A(1,1:k)-B(1,1:k)) in the loop if you want to compute histograms for every vector pair difference A(1,1:k)-B(1,1:k).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top