I have a set of numbers in an Array in PHP. I.e.
[1,2,3,4,5,6,7,999,9999,10000,-20,-800,25,26,27,28]
.
I want to foreach
over each element, calculate the Standard Deviation and the Average for this array and then figure out if one of the numbers is close to my Average Value.
I want to know on a scale from 1 to 0 if the number is close to my average (0.99xx.. result) or if its more far away (0.0xx.. result). This way I could determine wheter or not the given integer is close to the Average.
This should be used for a score mechanism that should get a "closer to average == better" logic.
If I do checks on MIN() and MAX(), numbers far away from respective numbers will always score as good, so this is polluting the actual result.
One more close to reality example is a set of the following data:
[0.2000, 0.3000, 0.3000, 0.9000, 0.8000, 0.7500, 0.1500, 0.4000, 0.3000, 0.6500, 0.8000]
Technically speaking I want to know whether or not the current iteration value is close to my average value, or not. If its close, the result number should be closer to 1. If its far away from my average it should be closer to 0. The further away, the closer to 0. The closer to the average, the closer to 1.
How could I do this in PHP? Note, this question is not about calculating averages.