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_clusteredwrites intoEconomicsInterval::method. - INDEPENDENT_
METHOD - What
bootstrap_medianwrites intoEconomicsInterval::method.
Functions§
- bootstrap_
median - A percentile bootstrap interval of the median: resample the values with replacement
resamplestimes, 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.Nonebelowmin_nvalues: 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.
Nonefor no values. - level_
text - A confidence level in basis points as a person reads it:
9500is95%,9750is97.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.2is+20.0%,-0.05is-5.0%. Anything that rounds to zero at one decimal prints0.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 printsn/arather than a figure. - quantile
- The
qquantile of sorted values, linear between the two nearest ranks (Hyndman and Fan’s type 7, the default of R and NumPy).Nonefor no values. - reduction
1 - treatment / control: the share of the control’s quantity the treatment did not spend. Negative when the treatment spent more;Nonewhen the control spent nothing, because a ratio against zero is not a number anyone should be shown.