summarise

Look up a summary helper by name, or invoke a user-supplied callable.

String names use the kebab form ("mean-se", "mean-cl-normal", "mean-cl-boot", "mean-sd", "median-hilow", "mean", "median", "quantile", "quantiles"). When name is a function, it is called as name(values, ..fun-args) and must return a dict (y, ymin, ymax); custom callables can take a sink (..args) to ignore extras. Unknown string names panic.

Usage

summarise(
  name,
  values,
  fun-args: (:),
  weights: none,
)

Parameters

Parameter Default Description
name Summary helper name, or a callable returning (y, ymin, ymax).
values Array of numbers; non-numeric entries are dropped.
fun-args (:) Keyword arguments forwarded to the helper or callable.
weights none Optional array of non-negative weights aligned with values (none for unit weights). Forwarded to helpers that honour weights (mean, mean-se, mean-sd, mean-cl-normal); helpers without a weighted formulation ignore the parameter.

Returns

Dict (y, ymin, ymax).

Examples

Dispatch by name; equivalent to calling mean-se directly.

#let s = summarise("mean-se", (2, 3, 4, 5, 6))

Pass keyword arguments via fun-args to forward helper-specific parameters.

#let s = summarise(
  "median-hilow",
  (1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
  fun-args: (conf: 0.9),
)

Pass a callable to compute an arbitrary summary.

#let s = summarise(
  (xs, ..args) => (y: xs.sum() / xs.len(), ymin: xs.first(), ymax: xs.last()),
  (1, 2, 3, 4, 5),
)
Back to top