0
$\begingroup$

I have a set of statistics that I need to find the overall ratio to. This example will work with only two items so I'll write them down:

 A  |  B
---------
12  |  5
 6  |  2

The total ratio needs to be worked out as: (12 + 6) / (5 + 2)
Which is 2.57

The problem however, is that the ratio of each row can be modified by a user, meaning the source values A and B can only be used as "default" sources.

To allow partial modification of the entire set by modifying specific ratios I saved the ratios of each individual row like this:

 A  |  B  | R
-------------
12  |  5  | 2.4
 6  |  2  | 3

I then attempted to come to the same overall ratio (since at the moment these ratios are un-modified), however getting the mean average did not work:

(2.4 + 3) / 2 = 2.7

The fact that the ratios can be modified make the original source data completely irrelevant in the overall statistic, but I still need to arrive at 2.57, is this possible?

I am prepared to change the type of modifiable information stored against each row, providing it can still be used to represent a percentage.

$\endgroup$
2
$\begingroup$

I dont understand programming, but what I can tell you is $\frac{a+b}{c+d} \neq \frac{\frac{a}{b}+\frac{c}{d}}{2}$, that is why it didn't work. What you can do is may be, try $\frac{a+b}{c+d}=\frac{\frac{a}{b}+1}{\frac{c}{d}+1}.\frac{b}{d}$.

In you example $a=12,b=6,c=5,d=2$ which will give you $2.57$

$\endgroup$
  • $\begingroup$ That actually works really well $x = ((($a / $b) + 1) / (($c / $d) + 1)) * ($b / $d);, I'm just trying to test it on a third row now. $\endgroup$ – Flosculus Jul 15 '15 at 8:34
  • $\begingroup$ Unfortunately it doesn't work, because it depends on b and d as being true after the modification. Since the use case I'm working with deals with an indeterminate modifier I'll have to write this off as impossible. Still I gave you +1, I don't know how you thought of that algorithm :) $\endgroup$ – Flosculus Jul 15 '15 at 10:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.