2024-06-06 01:33:06 +00:00
|
|
|
defmodule Growth.Calc.Centile do
|
|
|
|
@moduledoc """
|
|
|
|
measures =
|
|
|
|
[
|
|
|
|
[30, -1.7862, 16.9392, 0.1107],
|
|
|
|
[14, -1.3592, 20.4951, 0.12579],
|
|
|
|
[19, -1.6318, 16.049, 0.10038]
|
|
|
|
]
|
|
|
|
Enum.map(measures, &apply(Growth.Calc.Centile, :compute, &1))
|
|
|
|
"""
|
|
|
|
|
2024-06-06 11:34:02 +00:00
|
|
|
alias Growth.Calc.ZScore
|
|
|
|
|
2024-06-06 01:33:06 +00:00
|
|
|
# TODO: (jpd) add documentation and typespecs
|
|
|
|
|
|
|
|
def compute(y, l, m, s) do
|
2024-06-06 11:34:02 +00:00
|
|
|
zscore = ZScore.raw(y, l, m, s)
|
2024-06-06 01:33:06 +00:00
|
|
|
|
2024-06-06 11:34:02 +00:00
|
|
|
if -3 <= zscore and zscore <= 3 do
|
|
|
|
m * :math.pow(1 + l * s * zscore, 1 / l)
|
|
|
|
else
|
|
|
|
:na
|
2024-06-06 01:33:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|