Calculating relative difference between two data sets which include negative numbers

3.8k Views Asked by At

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

There are 1 best solutions below

4
On

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.