Skip to main content

Module stats

Module stats 

Source
Expand description

The arithmetic of the economics subsystem, and nothing else: the reduction formula, order statistics, a seeded bootstrap (over independent values, or over clusters when the values are repetitions of the same task), and the two ways a number is printed. Every surface that shows a number gets it from here through super::summarize; nothing downstream recomputes one, and nothing downstream formats a percentage its own way.

Two rules are enforced by the types rather than by care:

  • A reduction against a zero control is None, never zero and never infinity: there is nothing to reduce, so there is no ratio.
  • A negative reduction is kept. Treatment costing more than control is a result.
use majordomus_cli::economics::stats::{reduction, distribution, percent_text};
assert_eq!(reduction(100, 50), Some(0.5));
assert_eq!(reduction(100, 120), Some(-0.2));
assert_eq!(reduction(0, 10), None);
let d = distribution(&[0.1, 0.3, 0.2]).unwrap();
assert_eq!(d.median, 0.2);
assert_eq!(percent_text(reduction(100, 120).unwrap()), "-20.0%");

Constants§

CLUSTER_METHOD
What bootstrap_median_clustered writes into EconomicsInterval::method.
INDEPENDENT_METHOD
What bootstrap_median writes into EconomicsInterval::method.

Functions§

bootstrap_median
A percentile bootstrap interval of the median: resample the values with replacement resamples times, take each resample’s median, and report the quantiles of those medians at the requested confidence. The values are sorted first, so the interval depends on the set of values and the seed, never on the order they were listed in. None below min_n values: an interval over two pairs would be precision nobody has.
bootstrap_median_clustered
A percentile bootstrap interval of the median over clustered values: each resample draws as many clusters as there are, with replacement, pools every value of each drawn cluster, and takes the median of the pool.
distribution
The distribution of a set of values: order statistics, mean and sample standard deviation. Independent of the order the values arrive in. None for no values.
level_text
A confidence level in basis points as a person reads it: 9500 is 95%, 9750 is 97.5%. Whole percentages carry no decimals and a fraction carries only the digits it needs, so a level is never rounded into one the methodology did not declare.
percent_text
A ratio as a signed percentage with one decimal: 0.2 is +20.0%, -0.05 is -5.0%. Anything that rounds to zero at one decimal prints 0.0% with no sign, so a surface never shows -0.0% for a result that is, to the precision shown, no change. A value that is not a number prints n/a rather than a figure.
quantile
The q quantile of sorted values, linear between the two nearest ranks (Hyndman and Fan’s type 7, the default of R and NumPy). None for no values.
reduction
1 - treatment / control: the share of the control’s quantity the treatment did not spend. Negative when the treatment spent more; None when the control spent nothing, because a ratio against zero is not a number anyone should be shown.