chore(growth): return nil when measure isn't set

This commit is contained in:
João Paulo Dubas 2024-06-11 11:42:17 +00:00
parent 88b8e811a8
commit 2545a796c3
Signed by: joao.dubas
SSH Key Fingerprint: SHA256:V1mixgOGRc/YMhGx/DNkOSmJxgA2vHNrDZEk3wt/kOA
2 changed files with 32 additions and 10 deletions

View File

@ -2,9 +2,9 @@ defmodule Growth.Calc.Centile do
@moduledoc """
Calculate percentile for a given measurement and the fitted values of Box-Cox by age/height:
* power
* median
* coefficientof variation
* **power** `t:Growth.Calc.ZScore.l/0`
* **median** `t:Growth.Calc.ZScore.m/0`
* **coefficientof variation** `t:Growth.Calc.ZScore.s/0`
This calculation is described in the [instructions provided by the World Health Organization](https://cdn.who.int/media/docs/default-source/child-growth/growth-reference-5-19-years/computation.pdf).
@ -23,7 +23,7 @@ defmodule Growth.Calc.Centile do
alias Growth.Calc.ZScore
@spec compute(number(), number(), number(), number()) :: number() | :na
@spec compute(number(), ZScore.l(), ZScore.m(), ZScore.s()) :: number() | :na | nil
@doc """
Compute the centile for a given measurement (`y`) and the Box-Cox values: power (`l`), median (`m`), and
coefficient of variation (`s`).
@ -36,6 +36,10 @@ defmodule Growth.Calc.Centile do
19.0
"""
def compute(nil, _, _, _) do
nil
end
def compute(y, l, m, s) do
zscore = ZScore.raw(y, l, m, s)

View File

@ -2,9 +2,9 @@ defmodule Growth.Calc.ZScore do
@moduledoc """
Calculate z-score for a given measurement and the fitted values of Box-Cox by age/height:
* power
* median
* coefficientof variation
* **power** `t:l/0`
* **median** `t:m/0`
* **coefficientof variation** `t:s/0`
This calculation is described in the [instructions provided by the World Health Organization](https://cdn.who.int/media/docs/default-source/child-growth/growth-reference-5-19-years/computation.pdf).
@ -21,7 +21,20 @@ defmodule Growth.Calc.ZScore do
"""
@spec compute(number(), number(), number(), number()) :: number()
@typedoc """
The **power** value in Box-Cox transformation.
"""
@type l :: number()
@typedoc """
The **median** value in Box-Cox transformation.
"""
@type m :: number()
@typedoc """
The **coefficient of variation** in Box-Cox transformation.
"""
@type s :: number()
@spec compute(number(), l(), m(), s()) :: Growth.measure()
@doc """
Compute the adjusted z-score for a given measurement (`y`) and the Box-Cox values: power (`l`), median (`m`), and
coefficient of variation (`s`).
@ -36,13 +49,18 @@ defmodule Growth.Calc.ZScore do
1.4698319520484722
"""
def compute(nil, _, _, _) do
nil
end
def compute(y, l, m, s) do
y
|> raw(l, m, s)
|> adjust(y, l, m, s)
end
@spec raw(number(), number(), number(), number()) :: number()
@spec raw(number(), l(), m(), s()) :: number()
@doc """
Compute the raw z-score for a given measurement (`y`) and the Box-Cox values, power (`l`), median (`m`), and
coefficient of variation (`s`).
@ -61,7 +79,7 @@ defmodule Growth.Calc.ZScore do
(:math.pow(y / m, l) - 1) / (s * l)
end
@spec adjust(number(), number(), number(), number(), number()) :: number()
@spec adjust(number(), number(), l(), m(), s()) :: number()
@doc """
Adjust the raw z-score considering that extreme values, beyond -3 and 3 standard deviation, must be handled differently.
"""