9.9 Descriptive statistics and type-7 quantiles
The shared core statistics helpers define mean, sample variance, median, MAD, Pearson correlation and linearly interpolated quantiles. These small definitions matter because reporting and binning can change at boundaries.
Finite-value policy
Median and quantile summaries sort only finite values; an empty finite set produces NaN. Mean and variance operate on the provided slice, so callers are responsible for filtering when required. Do not assume every helper has the same missing/non-finite policy.
Sample variance uses denominator n-1 and returns zero for fewer than two values. MAD is median absolute deviation multiplied by 1.4826 for normal-consistent scale.
Type-7 quantile
For sorted values of length \(n\), position is
The result linearly interpolates between floor and ceiling positions. This matches R's default type 7. For values 1 through 8, the 25th percentile is 2.75, as retained in Chapter 9 evidence.
Several command modules also contain domain-specific statistics helpers. Verify their documented definitions rather than assuming every command imports core::stats directly.
Pearson behavior
Pearson correlation uses the shorter length of the two slices, returns zero for fewer than three pairs and returns zero when either variance sum is nonpositive. A zero can therefore mean “undefined/degenerate” rather than evidence of no association.
Common mistakes
- Comparing quantiles without matching definitions.
- Treating returned zero correlation as always estimable.
- Assuming non-finite filtering is universal.
Checklist
- State quantile type and variance denominator.
- Document finite/missing-value preprocessing.
- Test small samples and tied values.
Further reading
See distribution functions, Chapter 6's missing values and the future output-reference chapter.