## Math Tip for Coders:

Remember when averaging percentages, unlike plain values,no matter if its a simple mean, a moving average, or a exponential moving average, you always want to use the repeated operator on percentages compared to the one you would use on plain values. I know thats confusing and really only makes sense with an example.

So each of the following operators is the repeated form of the prior: +, *,^ (exponent)

Similarly the following: -, / , roots (like square root)

So for a simple mean with plain values you would average three values by doing:

(a + b + c)/3

However if your doing that for percentages that formula doesnt work instead you do:

(a * b * c) ^ (1/3)

Remember taking something to the power of 1/3 is the same as taking the third root.

Also keep in mind the variables here must be percentages such that they are anywhere from 0 to infinity. If you invested in something and you made no money and lost no money it would be 1, for 100%, if you lost all your money its 0, if you lost half its 0.5 (50%), if you doubled your money its 2.0 (200%) and so on

So if you inveted in three different things, and each time you doubled your money, and you wanted to know what your average percentage of return on investment was you would do: (2 * 2 * 2) ^ (1/3) and that would give you your mean, 2.. If you treated it like normal values and added then divided while it would work in this case it would give you **significantly** incorrect values in other cases.

As I stated this holds true for more complex types of averages too, take exponential moving average as an example. For plain values with EMA you apply each new value to just the previous EMA (and dont need to worry about combining all the values at once).. So if you flipped a coin 100 times and and took the EMA of the first 99 and now want to know know the EMA after the 100th flip (1 being heads and 0 being tails) you do:

(last_value * (1 - alpha) + current_value * alpha)

that gives you your current EMA where alpha is any number from 0 to 1... now to apply that to percentages again you take each operator and make it the next one up so for percentages it is actually:

(last_percentage^(1-alpha) * current_percentage^alpha)

@freemo Does this apply to sets of percentages that are constrained to 0 <= 1 ? That is, percentages that are never above 100%?

@Pat Depends on why it is constrained in that way.. does it truely represent situations where the final value has always decreased? then if so, yes..

@freemo Yes, like relative humidity or percentage of reflected light.

Follow

@Pat yes it would apply in those cases as well.

@freemo Thank you. (I was not aware this and I've probably made that mistake before without even realizing it.)

@Pat Most people have, another common mistake is you cant extend percentages across time by multiplying.. for example "I made 5% in one day, if i can do this every day for 10 days then I can make 50% in a week!

you would have to instead take the power: 1.05^10 = 1.628, so in face if you make 5% a day then if you do that every day over 10 days you would make 62.8%

@Pat Actually sorry a bit sleep deprived and someone pointed out an important fact.. This only applies to a sequence where the relative percentage refers to the total accumulated at each check point, not independent events and not percentages relative to a fixed absolute.. so in fact for relative humidity the plain way would work.

@Pat yes we are talking about compounding, but norally people are used to only working with compounding percentages when the percentages are fixed (and its easy).. im describing how to take the average of a changing percentage that represents a continuously compounding change.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.