statistics-0.15.0.0: A library of statistical types, data, and functions

Statistics.Types

Description

Data types common used in statistics

Synopsis

# Confidence level

data CL a #

Confidence level. In context of confidence intervals it's probability of said interval covering true value of measured value. In context of statistical tests it's 1-α where α is significance of test.

Since confidence level are usually close to 1 they are stored as 1-CL internally. There are two smart constructors for CL: mkCL and mkCLFromSignificance (and corresponding variant returning Maybe). First creates CL from confidence level and second from 1 - CL or significance level.

>>> cl95
mkCLFromSignificance 0.05


Prior to 0.14 confidence levels were passed to function as plain Doubles. Use mkCL to convert them to CL.

Instances
 Unbox a => Vector Vector (CL a) # Instance detailsDefined in Statistics.Types MethodsbasicUnsafeFreeze :: PrimMonad m => Mutable Vector (PrimState m) (CL a) -> m (Vector (CL a)) #basicUnsafeThaw :: PrimMonad m => Vector (CL a) -> m (Mutable Vector (PrimState m) (CL a)) #basicLength :: Vector (CL a) -> Int #basicUnsafeSlice :: Int -> Int -> Vector (CL a) -> Vector (CL a) #basicUnsafeIndexM :: Monad m => Vector (CL a) -> Int -> m (CL a) #basicUnsafeCopy :: PrimMonad m => Mutable Vector (PrimState m) (CL a) -> Vector (CL a) -> m () #elemseq :: Vector (CL a) -> CL a -> b -> b # Unbox a => MVector MVector (CL a) # Instance detailsDefined in Statistics.Types MethodsbasicLength :: MVector s (CL a) -> Int #basicUnsafeSlice :: Int -> Int -> MVector s (CL a) -> MVector s (CL a) #basicOverlaps :: MVector s (CL a) -> MVector s (CL a) -> Bool #basicUnsafeNew :: PrimMonad m => Int -> m (MVector (PrimState m) (CL a)) #basicInitialize :: PrimMonad m => MVector (PrimState m) (CL a) -> m () #basicUnsafeReplicate :: PrimMonad m => Int -> CL a -> m (MVector (PrimState m) (CL a)) #basicUnsafeRead :: PrimMonad m => MVector (PrimState m) (CL a) -> Int -> m (CL a) #basicUnsafeWrite :: PrimMonad m => MVector (PrimState m) (CL a) -> Int -> CL a -> m () #basicClear :: PrimMonad m => MVector (PrimState m) (CL a) -> m () #basicSet :: PrimMonad m => MVector (PrimState m) (CL a) -> CL a -> m () #basicUnsafeCopy :: PrimMonad m => MVector (PrimState m) (CL a) -> MVector (PrimState m) (CL a) -> m () #basicUnsafeMove :: PrimMonad m => MVector (PrimState m) (CL a) -> MVector (PrimState m) (CL a) -> m () #basicUnsafeGrow :: PrimMonad m => MVector (PrimState m) (CL a) -> Int -> m (MVector (PrimState m) (CL a)) # Eq a => Eq (CL a) # Instance detailsDefined in Statistics.Types Methods(==) :: CL a -> CL a -> Bool #(/=) :: CL a -> CL a -> Bool # Data a => Data (CL a) # Instance detailsDefined in Statistics.Types Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> CL a -> c (CL a) #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (CL a) #toConstr :: CL a -> Constr #dataTypeOf :: CL a -> DataType #dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (CL a)) #dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a)) #gmapT :: (forall b. Data b => b -> b) -> CL a -> CL a #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r #gmapQ :: (forall d. Data d => d -> u) -> CL a -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> CL a -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> CL a -> m (CL a) #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> CL a -> m (CL a) #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> CL a -> m (CL a) # Ord a => Ord (CL a) # >>> cl95 > cl90 True  Instance detailsDefined in Statistics.Types Methodscompare :: CL a -> CL a -> Ordering #(<) :: CL a -> CL a -> Bool #(<=) :: CL a -> CL a -> Bool #(>) :: CL a -> CL a -> Bool #(>=) :: CL a -> CL a -> Bool #max :: CL a -> CL a -> CL a #min :: CL a -> CL a -> CL a # (Num a, Ord a, Read a) => Read (CL a) # Instance detailsDefined in Statistics.Types MethodsreadsPrec :: Int -> ReadS (CL a) #readList :: ReadS [CL a] #readPrec :: ReadPrec (CL a) # Show a => Show (CL a) # Instance detailsDefined in Statistics.Types MethodsshowsPrec :: Int -> CL a -> ShowS #show :: CL a -> String #showList :: [CL a] -> ShowS # Generic (CL a) # Instance detailsDefined in Statistics.Types Associated Typestype Rep (CL a) :: Type -> Type # Methodsfrom :: CL a -> Rep (CL a) x #to :: Rep (CL a) x -> CL a # NFData a => NFData (CL a) # Instance detailsDefined in Statistics.Types Methodsrnf :: CL a -> () # ToJSON a => ToJSON (CL a) # Instance detailsDefined in Statistics.Types MethodstoJSON :: CL a -> Value #toEncoding :: CL a -> Encoding #toJSONList :: [CL a] -> Value #toEncodingList :: [CL a] -> Encoding # (FromJSON a, Num a, Ord a) => FromJSON (CL a) # Instance detailsDefined in Statistics.Types MethodsparseJSON :: Value -> Parser (CL a) #parseJSONList :: Value -> Parser [CL a] # (Binary a, Num a, Ord a) => Binary (CL a) # Instance detailsDefined in Statistics.Types Methodsput :: CL a -> Put #get :: Get (CL a) #putList :: [CL a] -> Put # Unbox a => Unbox (CL a) # Instance detailsDefined in Statistics.Types newtype MVector s (CL a) # Instance detailsDefined in Statistics.Types newtype MVector s (CL a) = MV_CL (MVector s a) type Rep (CL a) # Instance detailsDefined in Statistics.Types type Rep (CL a) = D1 (MetaData "CL" "Statistics.Types" "statistics-0.15.0.0-KYJLg9h4jsl1bBm8KLc3A8" True) (C1 (MetaCons "CL" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) newtype Vector (CL a) # Instance detailsDefined in Statistics.Types newtype Vector (CL a) = V_CL (Vector a)

## Accessors

confidenceLevel :: Num a => CL a -> a #

Get confidence level. This function is subject to rounding errors. If 1 - CL is needed use significanceLevel instead

significanceLevel :: CL a -> a #

Get significance level.

## Constructors

mkCL :: (Ord a, Num a) => a -> CL a #

Create confidence level from probability β or probability confidence interval contain true value of estimate. Will throw exception if parameter is out of [0,1] range

>>> mkCL 0.95    -- same as cl95
mkCLFromSignificance 0.05


mkCLE :: (Ord a, Num a) => a -> Maybe (CL a) #

Same as mkCL but returns Nothing instead of error if parameter is out of [0,1] range

>>> mkCLE 0.95    -- same as cl95
Just (mkCLFromSignificance 0.05)


mkCLFromSignificance :: (Ord a, Num a) => a -> CL a #

Create confidence level from probability α or probability that confidence interval does not contain true value of estimate. Will throw exception if parameter is out of [0,1] range

>>> mkCLFromSignificance 0.05    -- same as cl95
mkCLFromSignificance 0.05


mkCLFromSignificanceE :: (Ord a, Num a) => a -> Maybe (CL a) #

Same as mkCLFromSignificance but returns Nothing instead of error if parameter is out of [0,1] range

>>> mkCLFromSignificanceE 0.05    -- same as cl95
Just (mkCLFromSignificance 0.05)


## Constants and conversion to nσ

cl90 :: Fractional a => CL a #

90% confidence level

cl95 :: Fractional a => CL a #

95% confidence level

cl99 :: Fractional a => CL a #

99% confidence level

### Normal approximation

P-value expressed in sigma. This is convention widely used in experimental physics. N sigma confidence level corresponds to probability within N sigma of normal distribution.

Note that this correspondence is for normal distribution. Other distribution will have different dependency. Also experimental distribution usually only approximately normal (especially at extreme tails).

P-value expressed in sigma for one-tail hypothesis. This correspond to probability of obtaining value less than N·σ.

Express confidence level in sigmas

Express confidence level in sigmas for one-tailed hypothesis.

# p-value

data PValue a #

Newtype wrapper for p-value.

Instances

## Accessors

pValue :: PValue a -> a #

Get p-value

## Constructors

mkPValue :: (Ord a, Num a) => a -> PValue a #

Construct PValue. Throws error if argument is out of [0,1] range.

mkPValueE :: (Ord a, Num a) => a -> Maybe (PValue a) #

Construct PValue. Returns Nothing if argument is out of [0,1] range.

# Estimates and upper/lower limits

data Estimate e a #

A point estimate and its confidence interval. It's parametrized by both error type e and value type a. This module provides two types of error: NormalErr for normally distributed errors and ConfInt for error with normal distribution. See their documentation for more details.

For example 144 ± 5 (assuming normality) could be expressed as

Estimate { estPoint = 144
, estError = NormalErr 5
}

Or if we want to express 144 + 6 - 4 at CL95 we could write:

Estimate { estPoint = 144
, estError = ConfInt
{ confIntLDX = 4
, confIntUDX = 6
, confIntCL  = cl95
}

Prior to statistics 0.14 Estimate data type used following definition:

data Estimate = Estimate {
estPoint           :: {-# UNPACK #-} !Double
, estLowerBound      :: {-# UNPACK #-} !Double
, estUpperBound      :: {-# UNPACK #-} !Double
, estConfidenceLevel :: {-# UNPACK #-} !Double
}

Now type Estimate ConfInt Double should be used instead. Function estimateFromInterval allow to easily construct estimate from same inputs.

Constructors

 Estimate FieldsestPoint :: !aPoint estimate.estError :: !(e a)Confidence interval for estimate.
Instances

newtype NormalErr a #

Normal errors. They are stored as 1σ errors which corresponds to 68.8% CL. Since we can recalculate them to any confidence level if needed we don't store it.

Constructors

 NormalErr FieldsnormalError :: a
Instances

data ConfInt a #

Confidence interval. It assumes that confidence interval forms single interval and isn't set of disjoint intervals.

Constructors

 ConfInt FieldsconfIntLDX :: !aLower error estimate, or distance between point estimate and lower bound of confidence interval.confIntUDX :: !aUpper error estimate, or distance between point estimate and upper bound of confidence interval.confIntCL :: !(CL Double)Confidence level corresponding to given confidence interval.
Instances

data UpperLimit a #

Upper limit. They are usually given for small non-negative values when it's not possible detect difference from zero.

Constructors

 UpperLimit FieldsupperLimit :: !aUpper limitulConfidenceLevel :: !(CL Double)Confidence level for which limit was calculated
Instances

data LowerLimit a #

Lower limit. They are usually given for large quantities when it's not possible to measure them. For example: proton half-life

Constructors

 LowerLimit FieldslowerLimit :: !aLower limitllConfidenceLevel :: !(CL Double)Confidence level for which limit was calculated
Instances

## Constructors

Arguments

 :: a Point estimate -> a 1σ error -> Estimate NormalErr a

Create estimate with normal errors

Arguments

 :: a Point estimate -> a 1σ error -> Estimate NormalErr a

Synonym for estimateNormErr

Arguments

 :: Num a => a Point estimate. Should lie within interval but it's not checked. -> (a, a) Lower and upper bounds of interval -> CL Double Confidence level for interval -> Estimate ConfInt a

Create estimate with asymmetric error.

Arguments

 :: a Central estimate -> (a, a) Lower and upper errors. Both should be positive but it's not checked. -> CL Double Confidence level for interval -> Estimate ConfInt a

Create estimate with asymmetric error.

## Accessors

confidenceInterval :: Num a => Estimate ConfInt a -> (a, a) #

Get confidence interval

asymErrors :: Estimate ConfInt a -> (a, a) #

Get asymmetric errors

class Scale e where #

Data types which could be multiplied by constant.

Methods

scale :: (Ord a, Num a) => a -> e a -> e a #

Instances
 # Instance detailsDefined in Statistics.Types Methodsscale :: (Ord a, Num a) => a -> ConfInt a -> ConfInt a # # Instance detailsDefined in Statistics.Types Methodsscale :: (Ord a, Num a) => a -> NormalErr a -> NormalErr a # Scale e => Scale (Estimate e) # Instance detailsDefined in Statistics.Types Methodsscale :: (Ord a, Num a) => a -> Estimate e a -> Estimate e a #

# Other

type Sample = Vector Double #

Sample data.

Sample with weights. First element of sample is data, second is weight

type Weights = Vector Double #

Weights for affecting the importance of elements of a sample.