HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestatistics-0.16.3.0Haskell2010

Statistics.Sample

Commonly used sample statistics, also known as descriptive statistics.

  • 2 types
  • 26 values

Types

2 declarations

Descriptive functions

1 declaration

Statistics of location

6 declarations
valueexpectation :: Vector v a => (a -> Double) -> v a -> Double
#

O(n) Compute expectation of function over for sample. This is simply mean . map f but won't create intermediate vector.

valuemean :: Vector v Double => v Double -> Double
#

O(n) Arithmetic mean. This uses Kahan-Babuška-Neumaier summation, so is more accurate than welfordMean unless the input values are very large. This function is not subject to stream fusion.

valuewelfordMean :: Vector v Double => v Double -> Double
#

O(n) Arithmetic mean. This uses Welford's algorithm to provide numerical stability, using a single pass over the sample data.

Compared to mean, this loses a surprising amount of precision unless the inputs are very large.

Statistics of dispersion

0 declarations

The variance — and hence the standard deviation — of a sample of fewer than two elements are both defined to be zero.

Functions over central moments

valuecentralMoment :: Vector v Double => Int -> v Double -> Double
#

Compute the kth central moment of a sample. The central moment is also known as the moment about the mean.

This function performs two passes over the sample, so is not subject to stream fusion.

For samples containing many values very close to the mean, this function is subject to inaccuracy due to catastrophic cancellation.

valuecentralMoments
  1. :: Vector v Double
  2. => Int
  3. -> Int
  4. -> v Double
  5. -> (Double, Double)
#

Compute the kth and jth central moments of a sample.

This function performs two passes over the sample, so is not subject to stream fusion.

For samples containing many values very close to the mean, this function is subject to inaccuracy due to catastrophic cancellation.

valueskewness :: Vector v Double => v Double -> Double
#

Compute the skewness of a sample. This is a measure of the asymmetry of its distribution.

A sample with negative skew is said to be left-skewed. Most of its mass is on the right of the distribution, with the tail on the left.

skewness $ U.to [1,100,101,102,103]
==> -1.497681449918257

A sample with positive skew is said to be right-skewed.

skewness $ U.to [1,2,3,4,100]
==> 1.4975367033335198

A sample's skewness is not defined if its variance is zero.

This function performs two passes over the sample, so is not subject to stream fusion.

For samples containing many values very close to the mean, this function is subject to inaccuracy due to catastrophic cancellation.

valuekurtosis :: Vector v Double => v Double -> Double
#

Compute the excess kurtosis of a sample. This is a measure of the "peakedness" of its distribution. A high kurtosis indicates that more of the sample's variance is due to infrequent severe deviations, rather than more frequent modest deviations.

A sample's excess kurtosis is not defined if its variance is zero.

This function performs two passes over the sample, so is not subject to stream fusion.

For samples containing many values very close to the mean, this function is subject to inaccuracy due to catastrophic cancellation.

Two-pass functions (numerically robust)

These functions use the compensated summation algorithm of Chan et al. for numerical robustness, but require two passes over the sample data as a result.

Because of the need for two passes, these functions are not subject to stream fusion.

valuevariance :: Vector v Double => v Double -> Double
#

Maximum likelihood estimate of a sample's variance. Also known as the population variance, where the denominator is n.

valuemeanVariance :: Vector v Double => v Double -> (Double, Double)
#

Calculate mean and maximum likelihood estimate of variance. This function should be used if both mean and variance are required since it will calculate mean only once.

valuemeanVarianceUnb :: Vector v Double => v Double -> (Double, Double)
#

Calculate mean and unbiased estimate of variance. This function should be used if both mean and variance are required since it will calculate mean only once.

Single-pass functions (faster, less safe)

The functions prefixed with the name fast below perform a single pass over the sample data using Knuth's algorithm. They usually work well, but see below for caveats. These functions are subject to array fusion.

Note: in cases where most sample data is close to the sample's mean, Knuth's algorithm gives inaccurate results due to catastrophic cancellation.

Joint distributions

5 declarations
valuecorrelation2 :: Vector v Double => v Double -> v Double -> Double
#

Correlation coefficient for two samples. Both vector must have same length Also known as Pearson's correlation. For empty sample it's set to zero.

valuepair :: (Vector v a, Vector v b, Vector v (a, b)) => v a -> v b -> v (a, b)
#

Pair two samples. It's like zip but requires that both samples have equal size.

References

0 declarations