fix(growth): use centile and percentile correctly
1. The calculation made in `Grownth.Calc.Centile.compute/4` converts a given z-score into the expected measurement value. This can be used to get specific values for key z-scores, such as, -3, -2, 2 and 3. 2. To calculate the percentile of a given z-score the system uses the cumulative distribution function.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
defmodule Growth.Calc.Centile do
|
||||
@moduledoc """
|
||||
Calculate percentile for a given measurement and the fitted values of Box-Cox by age/height:
|
||||
Calculate the value of measurement at a given z-score and fitted values of Box-Cox by age/height:
|
||||
|
||||
* **power** `t:Growth.Calc.ZScore.l/0`
|
||||
* **median** `t:Growth.Calc.ZScore.m/0`
|
||||
@@ -12,9 +12,9 @@ defmodule Growth.Calc.Centile do
|
||||
|
||||
iex> measures =
|
||||
...> [
|
||||
...> [30, -1.7862, 16.9392, 0.1107],
|
||||
...> [14, -1.3592, 20.4951, 0.12579],
|
||||
...> [19, -1.6318, 16.049, 0.10038]
|
||||
...> [-3.0, -1.7862, 16.9392, 0.1107],
|
||||
...> [2, -1.3592, 20.4951, 0.12579],
|
||||
...> [-1.2, -1.6318, 16.049, 0.10038]
|
||||
...> ]
|
||||
iex> Enum.map(measures, &apply(Growth.Calc.Centile, :compute, &1))
|
||||
[:na, :na, 19.0]
|
||||
@@ -32,17 +32,15 @@ defmodule Growth.Calc.Centile do
|
||||
|
||||
## Examples:
|
||||
|
||||
iex> Growth.Calc.Centile.compute(19, -1.6318, 16.049, 0.10038)
|
||||
iex> Growth.Calc.Centile.compute(0.0, -1.6318, 16.049, 0.10038)
|
||||
19.0
|
||||
|
||||
"""
|
||||
def compute(y, l, m, s) do
|
||||
zscore = ZScore.raw(y, l, m, s)
|
||||
def compute(z_score, l, m, s) when -3 <= z_score and z_score <= 3 do
|
||||
m * :math.pow(1 + l * s * z_score, 1 / l)
|
||||
end
|
||||
|
||||
if -3 <= zscore and zscore <= 3 do
|
||||
m * :math.pow(1 + l * s * zscore, 1 / l)
|
||||
else
|
||||
:na
|
||||
end
|
||||
def compute(_z_score, _l, _m, _s) do
|
||||
:na
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user