monoid-statistics-0.3.1: Monoids for calculation of statistics of sample

Data.Monoid.Statistics.Numeric

Contents

Synopsis

Mean and variance

newtype Count a Source

Simplest statistics. Number of elements in the sample

Constructors

Count 

Fields

calcCountI :: a
 

Instances

Typeable1 Count 
Eq a => Eq (Count a) 
Ord a => Ord (Count a) 
Show a => Show (Count a) 
Integral a => Monoid (Count a) 
CalcCount (Count Int) 
Integral a => StatMonoid (Count a) b 

asCount :: Count a -> Count aSource

Fix type of monoid

data Mean Source

Mean of sample. Samples of Double,Float and bui;t-in integral types are supported

Numeric stability of mappend is not proven.

Constructors

Mean !Int !Double 

asMean :: Mean -> MeanSource

Fix type of monoid

data Variance Source

Intermediate quantities to calculate the standard deviation.

Constructors

Variance !Int !Double !Double 

Instances

Eq Variance 
Show Variance 
Typeable Variance 
Monoid Variance

Using parallel algorithm from:

Chan, Tony F.; Golub, Gene H.; LeVeque, Randall J. (1979), Updating Formulae and a Pairwise Algorithm for Computing Sample Variances., Technical Report STAN-CS-79-773, Department of Computer Science, Stanford University. Page 4.

ftp://reports.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf

CalcVariance Variance 
CalcMean Variance 
CalcCount Variance 
Real a => StatMonoid Variance a 

asVariance :: Variance -> VarianceSource

Fix type of monoid

Ad-hoc accessors

Monoids Count, Mean and Variance form some kind of tower. Every successive monoid can calculate every statistics previous monoids can. So to avoid replicating accessors for each statistics a set of ad-hoc type classes was added.

This approach have deficiency. It becomes to infer type of monoidal accumulator from accessor function so following expression will be rejected:

 calcCount $ evalStatistics xs

Indeed type of accumulator is:

 forall a . (StatMonoid a, CalcMean a) => a

Therefore it must be fixed by adding explicit type annotation. For example:

 calcMean (evalStatistics xs :: Mean)

class CalcCount m whereSource

Statistics which could count number of elements in the sample

Methods

calcCount :: m -> IntSource

Number of elements in sample

class CalcMean m whereSource

Statistics which could estimate mean of sample

Methods

calcMean :: m -> DoubleSource

Calculate esimate of mean of a sample

class CalcVariance m whereSource

Statistics which could estimate variance of sample

Methods

calcVariance :: m -> DoubleSource

Calculate biased estimate of variance

calcVarianceUnbiased :: m -> DoubleSource

Calculate unbiased estimate of the variance, where the denominator is $n-1$.

calcStddev :: CalcVariance m => m -> DoubleSource

Calculate sample standard deviation (biased estimator, $s$, where the denominator is $n-1$).

calcStddevUnbiased :: CalcVariance m => m -> DoubleSource

Calculate standard deviation of the sample (unbiased estimator, $sigma$, where the denominator is $n$).

Maximum and minimum

newtype Max Source

Calculate maximum of sample. For empty sample returns NaN. Any NaN encountedred will be ignored.

Constructors

Max 

Fields

calcMax :: Double
 

newtype Min Source

Calculate minimum of sample. For empty sample returns NaN. Any NaN encountedred will be ignored.

Constructors

Min 

Fields

calcMin :: Double