MeanDeviation¶
Status: Stable
documented, exercised by the test suite and/or worked examples, with no known limitations recorded.
Description¶
MeanDeviation[data]
gives the mean absolute deviation from the mean of the elements in data.
Examples (6)¶
Every input below was run against the current Mathilda build and its output recorded.
Basic examples (2)¶
Applications (4)¶
The exact mean absolute deviation of an integer sample
Exact rationals stay exact
A machine-real sample gives a machine-real deviation
On a matrix the deviation is computed per column
Algorithm¶
meandeviation.c -- MeanDeviation[].
MeanDeviation[data] = Mean[Abs[data - Mean[data]]], composed through the evaluator so exact input stays exact (the src/stats exactness discipline -- see mean.c's overflow note). Matrix input recurses columnwise; NDArray input is materialised via pack_unpack (correctness-first, no kernel yet). See stats.h and stats_common.h for the subsystem layout.
Implementation notes¶
Algorithm. MeanDeviation[data] is the mean absolute deviation from the mean,
Mean[Abs[data − Mean[data]]]. builtin_meandeviation builds exactly that one
tree and hands it to the evaluator, so the src/stats exactness discipline holds:
exact input gives exact output. The steps:
- materialise a visible
NDArray/ packed argument viapack_unpack(correctness-first, no kernel yet); - require
datato be a non-emptyList; - matrix input (first element a
List) recurses columnwise viastats_apply_columnwise("MeanDeviation", data); - validate every element — it must be real-numeric and finite
(
has_nonfiniterejectsInfinity,ComplexInfinity,Indeterminate, which areNumericQand free of the imaginary unit and so would pass the element gate but then leave the composedMeantree half-evaluated);MeanDeviation::rectnotherwise; - build and evaluate
Mean[Abs[data − Mean[data]]]— the innerMean, theListablePlus/Abs, and the outerMeanall reduce because the data was just verified all-numeric.
Data structures. A single composed Expr tree; no auxiliary buffers. The
matrix recursion reuses stats_apply_columnwise
(Map[MeanDeviation, Transpose[matrix]]).
Complexity / limits. O(n) to build, then the evaluator's two Mean
reductions over the vector. No packed buffer kernel and no Compile[] lowering —
a visible NDArray is unpacked to the exact List path first.
Protected.- Exact input gives exact output:
MeanDeviation[{1, 2, 3, 4}]is1. - For
MatrixQdata the deviation is computed per column. - Requires numeric data (
MeanDeviation::rectnotherwise).
Attributes: Protected.
References¶
See also: MatrixQ
- Source:
src/stats/meandeviation.c - Specification:
docs/spec/builtins/statistics.md - Tests:
tests/test_quantile_family.c
Notes & additional examples¶
Notes¶
MeanDeviation[data] = Mean[Abs[data − Mean[data]]], the mean absolute deviation
about the mean. It is composed through the evaluator, so exact input gives exact
output. Non-finite entries (Infinity, ComplexInfinity, Indeterminate) are
rejected even though they are NumericQ and free of the imaginary unit — they
would otherwise leave the composed Mean half-evaluated — and non-numeric data
triggers MeanDeviation::rectn.
Matrix input is reduced per column; a visible NDArray is materialised to the
exact List path.