0

I need to determine the relative difference between each element in vector 'A' and its corresponding element in 'B'. The vectors are:

A = 18.40,6.06,12.46,25.25,60.00,30.77,48.95,35.77,29.73,38.40,36.36,35.33,20.18,82.46,34.25,10.83,49.08,25.00,63.06,-5.31,15.55,35.02,15.96
B = -2.40,-43.94,-2.36,-6.57,21.82,11.83,20.92,15.45,17.57,24.80,24.24,24,14.8,74.85,33.33,10.83,49.21,25.56,64.72,-5.54,16.39,40.11,36.17 

Normally I would simply divide A by B to get the ratio between the two numbers, however these data vectors contain negative numbers meaning the magnitude of the absolute difference (A-B) between A and B is not being captured. Is there a way to transform the data such that I always get a positive ratio between the two numbers and that for example A=6.06 and B=-43.94 (absolute difference = 50.00) gives a larger ratio than e.g. A=60.00 and B=21.82?

Thank you for your time,

Laura

1 Answers1

1

You may use the formula for relative difference: $$\frac{|x-y|}{\max(|x|,|y|)}.$$ It is always positive but between the values of $x, y$ at least one must be non-zero.

aleph
  • 37
  • Thank you for your answer. Could you please explain what you mean by the comma between the absolute values of x and y? – Laura Jul 06 '17 at 09:19
  • Yes off course. It means that between the absolute values of $x ,y$ you pick the maximum. – aleph Jul 06 '17 at 10:18
  • Thank you. To make sure I have this absolutely correct, could you please confirm that an example calculation from the first elements of the data vectors would be:

    (18.40--2.40) / 18.4

    I.e. the max value used is of the specific x and y values and not of the maximum of the whole data vector?

    – Laura Jul 06 '17 at 10:29
  • Yes, that is correct :) – aleph Jul 06 '17 at 10:53