Bland.Stats (Elixir Technical Drawing v0.4.0)

Copy Markdown View Source

Small stats helpers used by the box-plot, Q-Q, and histogram routines. Intentionally narrow — this is not a general stats library.

Summary

Functions

Computes a box-plot summary — quartiles plus Tukey fences for whisker endpoints. Outliers are observations beyond 1.5·IQR (default).

Inverse standard-normal CDF (probit). Uses the Beasley-Springer / Moro approximation — accurate to about 1e-9 across the usual range.

Linearly-interpolated quantile (type-7, R's default). p is in [0, 1].

Functions

boxplot_stats(values, whisker_iqr \\ 1.5)

@spec boxplot_stats([number()], number()) :: map()

Computes a box-plot summary — quartiles plus Tukey fences for whisker endpoints. Outliers are observations beyond 1.5·IQR (default).

Returns %{min, q1, median, q3, max, outliers} where min/max are the whisker endpoints (not the raw extrema — those are captured in :outliers).

iex> s = Bland.Stats.boxplot_stats([1, 2, 3, 4, 5, 6, 7, 100])
iex> {s.median, length(s.outliers)}
{4.5, 1}

normal_quantile(p)

@spec normal_quantile(number()) :: float()

Inverse standard-normal CDF (probit). Uses the Beasley-Springer / Moro approximation — accurate to about 1e-9 across the usual range.

iex> abs(Bland.Stats.normal_quantile(0.5)) < 1.0e-9
true

iex> Float.round(Bland.Stats.normal_quantile(0.975), 4)
1.96

quantile(values, p)

@spec quantile([number()], number()) :: float()

Linearly-interpolated quantile (type-7, R's default). p is in [0, 1].

iex> Bland.Stats.quantile([1, 2, 3, 4, 5], 0.5)
3.0