statistics

Import it with @use:statistics, then call its constructs under that name.

Pack
A blue standard normal curve with the area between a = −1 and b = 1 shaded and labelled 0.683, a teal line at the mean labelled μ, an orange point on the curve at x = 2 labelled z = 2, and a purple t density with 3 degrees of freedom beneath it with heavier tails.A blue standard normal curve with the area between a = −1 and b = 1 shaded and labelled 0.683, a teal line at the mean labelled μ, an orange point on the curve at x = 2 labelled z = 2, and a purple t density with 3 degrees of freedom beneath it with heavier tails.
@use:statistics

#Constructs

statistics.normal
The normal density N(μ,σ2)N(\mu, \sigma^2), drawn across four standard deviations either side of the mean.
A blue bell curve centred on 0, labelled N(0, 1²), and a purple bell curve twice as wide centred on 2.A blue bell curve centred on 0, labelled N(0, 1²), and a purple bell curve twice as wide centred on 2.
mu
The distribution's mean μ\mu.
Default0
sigma
The distribution's standard deviation σ\sigma.
Default1
colour
The curve's colour.
paint
Defaultblue
statistics.standard-normal
The standard normal N(0,1)N(0, 1) — the density every other normal is a shift and a stretch of. It is normal with its parameters fixed, called the way you would call it yourself: inside the pack its own constructs are named without the pack prefix.
The standard normal bell curve in blue, centred on 0 and spanning four standard deviations either side.The standard normal bell curve in blue, centred on 0 and spanning four standard deviations either side.
colour
The curve's colour.
paint
Defaultblue
statistics.normal-area
A normal density with the probability between two points shaded, and the bounds marked on the axis. The curve it shades is named inside the template, so two uses in one graph never collide (D36) and the caller supplies no id.
A blue standard normal curve with the area between a = −1 and b = 1 shaded and labelled 0.683.A blue standard normal curve with the area between a = −1 and b = 1 shaded and labelled 0.683.
mu
The distribution's mean μ\mu.
Default0
sigma
The distribution's standard deviation σ\sigma.
Default1
fromRequired
The shaded region's lower bound.
toRequired
The shaded region's upper bound.
show-value
Print the area on the shading itself, as a textbook diagram does. Off by default: the number is always available to prose through the call's id, and a figure that states it as well is a choice about that figure.
bool
Defaultfalse
colour
The curve, the shaded region and the two bound labels' colour.
paint
Defaultblue
statistics.mean-marker
A vertical line at the mean, labelled μ\mu.
A blue bell curve centred on 2 with a teal vertical line at its peak, labelled μ on the x axis.A blue bell curve centred on 2 with a teal vertical line at its peak, labelled μ on the x axis.
mu
The mean the line is drawn at.
Default0
colour
The line's colour.
paint
Defaultteal
statistics.deviation-markers
Vertical lines one standard deviation either side of the mean.
A blue standard normal curve with grey vertical lines at −1 and 1, labelled μ − σ and μ + σ on the x axis.A blue standard normal curve with grey vertical lines at −1 and 1, labelled μ − σ and μ + σ on the x axis.
mu
The distribution's mean.
Default0
sigma
The distribution's standard deviation, one either side of the mean.
Default1
colour
Both lines' colour.
paint
Defaultgrey
statistics.z-point
A point sitting on a normal curve, labelled with its z-score. x and z are both supplied because a template cannot compute one from the other: substitution splices text and the value folds parse literals rather than evaluating arithmetic. Writing zz out is the honest form until the language grows expression abstraction.
A blue standard normal curve with an orange point sitting on it at x = 1, labelled z = 1.A blue standard normal curve with an orange point sitting on it at x = 1, labelled z = 1.
xRequired
The point's position along the axis.
zRequired
The point's z-score, written out since a template cannot compute it from x and mu.
mu
The curve's mean, for the height the point sits at.
Default0
sigma
The curve's standard deviation, for the height the point sits at.
Default1
colour
The point's colour.
paint
Defaultorange
statistics.uniform
The continuous uniform density on [a,b][a, b].
A teal flat line at height 0.5 between 0 and 2, the uniform density labelled U(0, 2).A teal flat line at height 0.5 between 0 and 2, the uniform density labelled U(0, 2).
a
The support's lower bound.
Default0
b
The support's upper bound.
Default1
colour
The curve's colour.
paint
Defaultteal
statistics.exponential
The exponential density with rate λ\lambda.
An orange curve falling from 1 at x = 0 towards zero by x = 6, the exponential density with rate 1.An orange curve falling from 1 at x = 0 towards zero by x = 6, the exponential density with rate 1.
lambda
The distribution's rate λ\lambda.
Default1
to
Where the curve stops being drawn.
Also written: domain-max
Default6
colour
The curve's colour.
paint
Defaultorange
statistics.laplace
The Laplace density with location μ\mu and scale bb.
A purple peaked curve with a sharp point at 0, falling away symmetrically either side, the Laplace density.A purple peaked curve with a sharp point at 0, falling away symmetrically either side, the Laplace density.
mu
The distribution's location μ\mu.
Default0
b
The distribution's scale bb.
Default1
colour
The curve's colour.
paint
Defaultpurple
statistics.logistic
The logistic density with location μ\mu and scale ss.
A green bell-shaped curve centred on 0 with heavier tails than a normal, the logistic density.A green bell-shaped curve centred on 0 with heavier tails than a normal, the logistic density.
mu
The distribution's location μ\mu.
Default0
s
The distribution's scale ss.
Default1
colour
The curve's colour.
paint
Defaultgreen
statistics.cauchy
The Cauchy density with location x0x_0 and scale γ\gamma — heavy enough in the tails that it has no mean, which is why it is drawn ten scales wide.
A red Cauchy density centred on 0 beside a grey standard normal, the Cauchy lower at the peak and far heavier in the tails.A red Cauchy density centred on 0 beside a grey standard normal, the Cauchy lower at the peak and far heavier in the tails.
centre
The distribution's location x0x_0.
Also written: x0
Default0
gamma
The distribution's scale γ\gamma.
Default1
colour
The curve's colour.
paint
Defaultred
statistics.t
Student's tt with ν\nu degrees of freedom — the normal's heavier-tailed cousin, which is what a small sample's mean actually follows.
A purple t density with 3 degrees of freedom against a grey standard normal, the t lower at the peak and heavier in the tails.A purple t density with 3 degrees of freedom against a grey standard normal, the t lower at the peak and heavier in the tails.
nu
The degrees of freedom ν\nu.
Also written: df
Default5
to
How far either side of zero the curve is drawn.
Default4
colour
The curve's colour.
paint
Defaultpurple
statistics.chi-squared
The chi-squared density with kk degrees of freedom. Drawn from just above zero: at x=0x = 0 the density is infinite for k=1k = 1 and the curve would have nowhere to start.
Two right-skewed chi-squared densities on the positive axis: a green one with 3 degrees of freedom and a teal one with 6, flatter and further right.Two right-skewed chi-squared densities on the positive axis: a green one with 3 degrees of freedom and a teal one with 6, flatter and further right.
k
The degrees of freedom kk.
Also written: df
Default3
from
Where the curve starts being drawn, just above zero.
Default0.05
to
Where the curve stops being drawn.
Default15
colour
The curve's colour.
paint
Defaultgreen
statistics.f-distribution
The FF density with d1d_1 and d2d_2 degrees of freedom — the ratio of two scaled chi-squareds, and so what a variance ratio follows.
An orange right-skewed F density with 5 and 10 degrees of freedom, rising to a peak below 1 and trailing off towards 5.An orange right-skewed F density with 5 and 10 degrees of freedom, rising to a peak below 1 and trailing off towards 5.
d1
The numerator's degrees of freedom d1d_1.
Default5
d2
The denominator's degrees of freedom d2d_2.
Default10
from
Where the curve starts being drawn, just above zero.
Default0.05
to
Where the curve stops being drawn.
Default5
colour
The curve's colour.
paint
Defaultorange
statistics.gamma
The gamma density with shape α\alpha and rate β\beta, βαxα−1e−βx/Γ(α)\beta^\alpha x^{\alpha - 1} e^{-\beta x} / \Gamma(\alpha) — the exponential is shape 11, and the chi-squared shape k/2k/2 at rate 12\tfrac{1}{2}. Drawn from just above zero, as chi-squared is: below shape 11 the density is infinite at x=0x = 0.
Two right-skewed gamma densities on the positive axis: a teal one with shape 2 and rate 1 peaking at 1, and a blue one with shape 5 and rate 2 peaking at 2.Two right-skewed gamma densities on the positive axis: a teal one with shape 2 and rate 1 peaking at 1, and a blue one with shape 5 and rate 2 peaking at 2.
shape
The distribution's shape α\alpha.
Also written: alpha
Default2
rate
The distribution's rate β\beta, the reciprocal of its scale.
Default1
from
Where the curve starts being drawn, just above zero.
Default0.01
to
Where the curve stops being drawn.
Default10
colour
The curve's colour.
paint
Defaultteal
statistics.beta
The beta density on [0,1][0, 1], xa−1(1−x)b−1 Γ(a+b)/(Γ(a)Γ(b))x^{a - 1} (1 - x)^{b - 1} \, \Gamma(a + b) / (\Gamma(a) \Gamma(b)) — the conjugate prior for a probability, and the posterior it updates to. Drawn from just inside each end: below a=1a = 1 or b=1b = 1 the density is infinite there.
On the interval 0 to 1, a broad grey Beta(2, 5) prior peaking at 0.2 and a taller, narrower purple Beta(12, 10) posterior peaking at 0.55.On the interval 0 to 1, a broad grey Beta(2, 5) prior peaking at 0.2 and a taller, narrower purple Beta(12, 10) posterior peaking at 0.55.
a
The first shape parameter aa — the prior's successes, plus one.
Default2
b
The second shape parameter bb — the prior's failures, plus one.
Default5
colour
The curve's colour.
paint
Defaultpurple
statistics.weibull
The Weibull distribution with shape kk and scale λ\lambda, as its density, its hazard h(x)=(k/λ)(x/λ)k−1h(x) = (k/\lambda)(x/\lambda)^{k - 1} or its survival function S(x)=e−(x/λ)kS(x) = e^{-(x/\lambda)^k}. The shape decides the hazard's direction: falling below 11, constant at 11 (the exponential), rising above it. Drawn from just above zero: below shape 11 the density and the hazard are infinite at x=0x = 0.
Three Weibull hazards with scale 1: a blue one with shape 0.5 falling from a high start, a flat grey one at 1 with shape 1, and an orange straight line rising from 0 with shape 2.Three Weibull hazards with scale 1: a blue one with shape 0.5 falling from a high start, a flat grey one at 1 with shape 1, and an orange straight line rising from 0 with shape 2.
shape
The distribution's shape kk.
Also written: k
Default1.5
scale
The distribution's scale λ\lambda.
Also written: lambda
Default1
show
Which function of the distribution is drawn.
enum
Defaultdensity
from
Where the curve starts being drawn, just above zero.
Default0.01
to
Where the curve stops being drawn.
Default3
colour
The curve's colour.
paint
Defaultorange
statistics.gompertz
The Gompertz law of mortality, a hazard growing exponentially with age, h(x)=Bcxh(x) = B c^x: drawn as its density, its hazard or its survival function S(x)=exp⁡(−B(cx−1)/ln⁡c)S(x) = \exp(-B (c^x - 1) / \ln c). The defaults are a human lifetime in years.
Across ages 0 to 110, a blue survival curve still near 0.9 at 50 and falling through 0.5 near 75, and a red hazard flat near 0 that climbs steeply after 80.Across ages 0 to 110, a blue survival curve still near 0.9 at 50 and falling through 0.5 near 75, and a red hazard flat near 0 that climbs steeply after 80.
b
The hazard at age zero, BB.
Default0.0003
c
The factor the hazard grows by each unit of age, cc, above 11.
Default1.07
show
Which function of the distribution is drawn.
enum
Defaultdensity
to
Where the curve stops being drawn.
Default110
colour
The curve's colour.
paint
Defaultred
statistics.normal-cdf
The normal's cumulative distribution — the probability of landing at or below xx, which is the shaded area of normal read off as a height.
A blue S-shaped curve rising from 0 to 1 across −4 to 4, passing 0.5 at 0: the normal cumulative distribution.A blue S-shaped curve rising from 0 to 1 across −4 to 4, passing 0.5 at 0: the normal cumulative distribution.
mu
The underlying normal's mean μ\mu.
Default0
sigma
The underlying normal's standard deviation σ\sigma.
Default1
colour
The curve's colour.
paint
Defaultblue
statistics.exponential-cdf
The exponential's cumulative distribution, 1−e−λx1 - e^{-\lambda x}.
An orange curve rising steeply from 0 at x = 0 and levelling towards 1, the exponential cumulative distribution with rate 1.An orange curve rising steeply from 0 at x = 0 and levelling towards 1, the exponential cumulative distribution with rate 1.
lambda
The underlying exponential's rate λ\lambda.
Default1
to
Where the curve stops being drawn.
Default6
colour
The curve's colour.
paint
Defaultorange
statistics.uniform-cdf
The uniform's cumulative distribution — the straight line every other CDF is measured against.
A teal straight ramp rising from 0 at x = 0 to 1 at x = 2, the uniform cumulative distribution.A teal straight ramp rising from 0 at x = 0 to 1 at x = 2, the uniform cumulative distribution.
a
The underlying uniform's lower bound.
Default0
b
The underlying uniform's upper bound.
Default1
colour
The curve's colour.
paint
Defaultteal
statistics.logistic-cdf
The logistic's cumulative distribution — the sigmoid, which is this and nothing more.
A green S-shaped curve rising from 0 to 1 and passing 0.5 at x = 0, the logistic cumulative distribution.A green S-shaped curve rising from 0 to 1 and passing 0.5 at x = 0, the logistic cumulative distribution.
mu
The underlying logistic's location μ\mu.
Default0
s
The underlying logistic's scale ss.
Default1
colour
The curve's colour.
paint
Defaultgreen
statistics.cauchy-cdf
The Cauchy's cumulative distribution, in terms of arctan⁡\arctan.
A red S-shaped curve passing 0.5 at x = 0 and approaching 0 and 1 only slowly at the edges, the Cauchy cumulative distribution.A red S-shaped curve passing 0.5 at x = 0 and approaching 0 and 1 only slowly at the edges, the Cauchy cumulative distribution.
centre
The underlying Cauchy's location x0x_0.
Also written: x0
Default0
gamma
The underlying Cauchy's scale γ\gamma.
Default1
colour
The curve's colour.
paint
Defaultred
statistics.normal-tail
One tail of a normal beyond a critical value — the rejection region of a one-sided test, shaded and marked. side says which: upper shades above the critical value, lower below it.
A red standard normal curve with the upper tail beyond 1.645 shaded and labelled 0.05, a guide line rising from 1.645.A red standard normal curve with the upper tail beyond 1.645 shaded and labelled 0.05, a guide line rising from 1.645.
atRequired
The critical value the tail is shaded beyond.
side
Which tail is shaded: above the critical value, or below it.
enum
Defaultupper
mu
The distribution's mean μ\mu.
Default0
sigma
The distribution's standard deviation σ\sigma.
Default1
label
The critical value's axis label.
inline
Default$c$
colour
The curve, the shaded tail and the axis label's colour.
paint
Defaultred
show-value
Print the area on the shading itself, as a textbook diagram does. Off by default: the number is always available to prose through the call's id, and a figure that states it as well is a choice about that figure.
bool
Defaultfalse
statistics.bernoulli
The Bernoulli mass function — one trial, drawn as the two outcomes it has. Like every discrete construct here it is a lollipop rather than bars: a bar chart stands on a categorical axis, and the support of a distribution is a run of numbers, so the mass sits on a numeric axis like everything else on the plane. A stem claims nothing but the value it stands at, which is what P(X=k)P(X = k) says.
Two blue stems, at 0 with height 0.7 and at 1 with height 0.3: one Bernoulli trial with success probability 0.3.Two blue stems, at 0 with height 0.7 and at 1 with height 0.3: one Bernoulli trial with success probability 0.3.
p
The probability of success.
Default0.5
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultblue
statistics.binomial
The binomial mass function (nk)pk(1−p)n−k\binom{n}{k} p^k (1-p)^{n-k} — one stem for each kk from 00 to nn, generated from the parameters rather than written out. One lollipop per kk rather than one holding every kk: a series is text the compiler reads in one piece, and @for generates ELEMENTS, so there is no way to fold a loop into an attribute. Each mass is written once either way, which is the part that matters. A stem in highlight and one outside it are two @ifs, one colour each.
Eleven stems from 0 to 10 rising symmetrically to a peak at 5, the binomial mass function for ten trials at probability 0.5: blue up to 7, and red from 8 up, the upper tail a test at that cut-off would reject.Eleven stems from 0 to 10 rising symmetrically to a peak at 5, the binomial mass function for ten trials at probability 0.5: blue up to 7, and red from 8 up, the upper tail a test at that cut-off would reject.
n
The number of trials.
Default10
p
The probability of success on each trial.
Default0.5
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultblue
highlight
The values of kk drawn in highlight-colour — a tail, or a test's rejection region: ..2 for P(X≤2)P(X \le 2), 8.. for P(X≥8)P(X \ge 8). The default holds no kk.
Default..<0
highlight-colour
The highlighted stems' colour.
list
Defaultred
statistics.poisson
The Poisson mass function e−λλk/k!e^{-\lambda} \lambda^k / k!. The support is infinite, so to says where to stop drawing — far enough out that the tail is invisible, not so far that the stems vanish.
Teal stems from 0 to 12, highest at 2 and 3 and dwindling to nothing by 12, the Poisson mass function with mean 3.Teal stems from 0 to 12, highest at 2 and 3 and dwindling to nothing by 12, the Poisson mass function with mean 3.
lambda
The distribution's rate λ\lambda.
Default3
to
The highest kk a stem is drawn for, far enough out that the tail is invisible.
Default12
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultteal
highlight
The values of kk drawn in highlight-colour, as binomial takes them.
Default..<0
highlight-colour
The highlighted stems' colour.
list
Defaultred
statistics.geometric
The geometric mass function p(1−p)k−1p(1-p)^{k-1} — the trial on which the first success arrives, counted from 11.
Purple stems from 1 to 12, tallest at 1 and each shorter than the last, the geometric mass function with success probability 0.35.Purple stems from 1 to 12, tallest at 1 and each shorter than the last, the geometric mass function with success probability 0.35.
p
The probability of success on each trial.
Default0.35
to
The highest kk a stem is drawn for.
Default12
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultpurple
highlight
The values of kk drawn in highlight-colour, as binomial takes them.
Default..<0
highlight-colour
The highlighted stems' colour.
list
Defaultred
statistics.hypergeometric
The hypergeometric mass function (Kk)(N−Kn−k)/(Nn)\binom{K}{k} \binom{N - K}{n - k} / \binom{N}{n} — the successes in nn draws without replacement from NN items, KK of them successes. A stem for every kk from 00 to nn: choose is 00 outside its range, so a kk the population cannot supply stands at zero rather than needing bounds the template could not compute.
Green stems from 0 to 8, tallest at 3 near 0.36, almost nothing at 0 and 7, and zero at 8, the hypergeometric mass function for 8 draws from 20 items with 7 successes.Green stems from 0 to 8, tallest at 3 near 0.36, almost nothing at 0 and 7, and zero at 8, the hypergeometric mass function for 8 draws from 20 items with 7 successes.
population
The population's size NN.
Default20
successes
The successes in the population, KK.
Default7
draws
The draws taken, nn.
Default8
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultgreen
highlight
The values of kk drawn in highlight-colour, as binomial takes them.
Default..<0
highlight-colour
The highlighted stems' colour.
list
Defaultred
statistics.negative-binomial
The negative binomial mass function (k−1r−1)pr(1−p)k−r\binom{k - 1}{r - 1} p^r (1-p)^{k-r} — the trial on which the rrth success arrives, counted as geometric counts it. The geometric is r=1r = 1.
Orange stems from 3 to 20, rising to a peak around 5 and 6 near 0.14 and then trailing off, the trial on which the third success arrives at probability 0.4.Orange stems from 3 to 20, rising to a peak around 5 and 6 near 0.14 and then trailing off, the trial on which the third success arrives at probability 0.4.
r
The successes waited for, rr.
Default3
p
The probability of success on each trial.
Default0.4
to
The highest kk a stem is drawn for.
Default20
w
The stems' line width.
list
Also written: width
Default2
size
The stems' dot size.
list
Default6
colour
The stems' colour.
list
Defaultorange
highlight
The values of kk drawn in highlight-colour, as binomial takes them.
Default..<0
highlight-colour
The highlighted stems' colour.
list
Defaultred
statistics.effect-strip
A strip of effects by group: one dot per comparison, a row per outcome, each row swarmed so a dense row reads as dense, and every dot coloured by which side of the baseline it fell on. The baseline is ruled across the plot and each side is named in a band behind the dots. The picture of a set of paired studies — organic against conventional, treatment against control — where what matters is how many land on each side and how far. values and groups are two columns of one long-format dataset: a row per comparison, its effect in one column and what it measured in the other. The groups go up the y axis as names, so the graph needs no y format: line.
Three rows of markers — emissions, land use and runoff — either side of a line at no difference, purple markers in a band labelled first is better on the left and pink markers in a band labelled second is better on the right, a grey box over each row.Three rows of markers — emissions, land use and runoff — either side of a line at no difference, purple markers in a band labelled first is better on the left and pink markers in a band labelled second is better on the right, a grey box over each row.
valuesRequired
The effect of each comparison, one per row — a dataset column bound whole.
groupsRequired
What each comparison measured, one name per row, in the same order as values.
baseline
No difference: where the plot is ruled and where the colours change sides.
Default0
fromRequired
The low end of the band behind the readings below the baseline.
toRequired
The high end of the band behind the readings at or above the baseline.
band
The share of each row's room the swarm and its box take — one band for both, so a column of tied readings shrinks to stay inside the box.
Default0.6
below-label
What a reading below the baseline means, written in its band.
inline
Default
above-label
What a reading at or above the baseline means, written in its band.
inline
Default
baseline-label
The baseline's own name, written on the axis where it is ruled.
inline
Default
below
The dots below the baseline, and the band below it.
paint
Defaultpurple
above
The dots at or above the baseline, and the band above it.
paint
Defaultpink
box-colour
The boxes' colour, when boxes draws them.
list
Defaultgrey
boxes
Draw each row's box over its swarm. The box shares the swarm's place, so it lands on the dots it summarises and leaves its outliers to them.
bool
Defaultfalse

Last updated