-1

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;
beginh
  • 1,133
  • 3
  • 26
  • 36
  • The only error in your code is the use of the ^2 without a dot, that should probably be .^2 – Buck Thorn Aug 04 '13 at 17:33
  • Please see my most recent edited answer. There may be some confusion on your part regarding how the looped index k is affecting the choice of data used at each iteration. – Buck Thorn Aug 04 '13 at 17:40

1 Answers1

0

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).

Buck Thorn
  • 5,024
  • 2
  • 17
  • 27
  • yes I saw those functions but they are incorporating only A vector. I want to compare both vectors with each other, B assuming as reference. But I don't understand from Matlab help how.. – beginh Aug 04 '13 at 13:17
  • hmm, I don't really understand your question then. Do you want to use A as a set of reference values? – Buck Thorn Aug 04 '13 at 13:28
  • @TryHard yes, I want this to be my reference and compare how good B is estimated. Please consider my update, comes in few seconds. – beginh Aug 04 '13 at 14:25
  • your explanation is just good! If you could please specify about braces, because there lack some and I want ot be sure I get it well: like that? --> **(mean((A(1,1:k)-B(1,1:k)).^2)** – beginh Aug 04 '13 at 18:28
  • 1
    @beginh : yes, I mixed up your notation and mine. Thanks for pointing it out! – Buck Thorn Aug 04 '13 at 18:31