median-absolute-deviation.asciidoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. [discrete]
  2. [[esql-agg-median-absolute-deviation]]
  3. === `MEDIAN_ABSOLUTE_DEVIATION`
  4. *Syntax*
  5. [source,esql]
  6. ----
  7. MEDIAN_ABSOLUTE_DEVIATION(expression)
  8. ----
  9. *Parameters*
  10. `expression`::
  11. Expression from which to return the median absolute deviation.
  12. *Description*
  13. Returns the median absolute deviation, a measure of variability. It is a robust
  14. statistic, meaning that it is useful for describing data that may have outliers,
  15. or may not be normally distributed. For such data it can be more descriptive
  16. than standard deviation.
  17. It is calculated as the median of each data point's deviation from the median of
  18. the entire sample. That is, for a random variable `X`, the median absolute
  19. deviation is `median(|median(X) - X|)`.
  20. NOTE: Like <<esql-agg-percentile>>, `MEDIAN_ABSOLUTE_DEVIATION` is
  21. <<esql-agg-percentile-approximate,usually approximate>>.
  22. [WARNING]
  23. ====
  24. `MEDIAN_ABSOLUTE_DEVIATION` is also {wikipedia}/Nondeterministic_algorithm[non-deterministic].
  25. This means you can get slightly different results using the same data.
  26. ====
  27. *Example*
  28. [source.merge.styled,esql]
  29. ----
  30. include::{esql-specs}/stats_percentile.csv-spec[tag=median-absolute-deviation]
  31. ----
  32. [%header.monospaced.styled,format=dsv,separator=|]
  33. |===
  34. include::{esql-specs}/stats_percentile.csv-spec[tag=median-absolute-deviation-result]
  35. |===
  36. The expression can use inline functions. For example, to calculate the the
  37. median absolute deviation of the maximum values of a multivalued column, first
  38. use `MV_MAX` to get the maximum value per row, and use the result with the
  39. `MEDIAN_ABSOLUTE_DEVIATION` function:
  40. [source.merge.styled,esql]
  41. ----
  42. include::{esql-specs}/stats_percentile.csv-spec[tag=docsStatsMADNestedExpression]
  43. ----
  44. [%header.monospaced.styled,format=dsv,separator=|]
  45. |===
  46. include::{esql-specs}/stats_percentile.csv-spec[tag=docsStatsMADNestedExpression-result]
  47. |===