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

Copyright | (c) 2009 2010 Bryan O'Sullivan
License | BSD3
Maintainer | bos@serpentine.com
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Statistics.Resampling

Contents

- Data types
- Resampling
- Jackknife
- Helper functions

Description

Resampling statistics.

Synopsis

- newtype Resample = Resample {
  - fromResample :: Vector Double
  }
- data Bootstrap v a = Bootstrap {
  - fullSample :: !a
  - resamples :: v a
  }
- data Estimator
  - = Mean
  - | Variance
  - | VarianceUnbiased
  - | StdDev
  - | Function (Sample -> Double)
- estimate :: Estimator -> Sample -> Double
- resampleST :: PrimMonad m => Gen (PrimState m) -> [Estimator] -> Int -> Vector Double -> m [Bootstrap Vector Double]
- resample :: GenIO -> [Estimator] -> Int -> Vector Double -> IO [(Estimator, Bootstrap Vector Double)]
- resampleVector :: (PrimMonad m, Vector v a) => Gen (PrimState m) -> v a -> m (v a)
- jackknife :: Estimator -> Sample -> Vector Double
- jackknifeMean :: Sample -> Vector Double
- jackknifeVariance :: Sample -> Vector Double
- jackknifeVarianceUnb :: Sample -> Vector Double
- jackknifeStdDev :: Sample -> Vector Double
- splitGen :: Int -> GenIO -> IO [GenIO]

# Data types

newtype Resample Source #

A resample drawn randomly, with replacement, from a set of data points. Distinct from a normal array to make it harder for your humble author's brain to go wrong.

Constructors

Resample |

Fields

- fromResample :: Vector Double

#### Instances

Instances details

FromJSON Resample Source # |
Instance details Defined in Statistics.Resampling Methods parseJSON :: Value -> Parser Resample Source # parseJSONList :: Value -> Parser [Resample] Source #
ToJSON Resample Source # |
Instance details Defined in Statistics.Resampling Methods toJSON :: Resample -> Value Source # toEncoding :: Resample -> Encoding Source # toJSONList :: [Resample] -> Value Source # toEncodingList :: [Resample] -> Encoding Source #
Data Resample Source # |

Instance details

Defined in Statistics.Resampling

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Resample -> c Resample Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Resample Source #

toConstr :: Resample -> Constr Source #

dataTypeOf :: Resample -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Resample) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Resample) Source #

gmapT :: (forall b. Data b => b -> b) -> Resample -> Resample Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Resample -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Resample -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Resample -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Resample -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Resample -> m Resample Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Resample -> m Resample Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Resample -> m Resample Source #

Generic Resample Source # |
Instance details Defined in Statistics.Resampling Associated Types type Rep Resample :: Type -> Type Source # Methods from :: Resample -> Rep Resample x Source # to :: Rep Resample x -> Resample Source #
Read Resample Source # |
Instance details Defined in Statistics.Resampling Methods readsPrec :: Int -> ReadS Resample Source # readList :: ReadS [Resample] Source # readPrec :: ReadPrec Resample Source # readListPrec :: ReadPrec [Resample] Source #
Show Resample Source # |
Instance details Defined in Statistics.Resampling Methods showsPrec :: Int -> Resample -> ShowS Source # show :: Resample -> String Source # showList :: [Resample] -> ShowS Source #
Binary Resample Source # |
Instance details Defined in Statistics.Resampling Methods put :: Resample -> Put Source # get :: Get Resample Source # putList :: [Resample] -> Put Source #
Eq Resample Source # |
Instance details Defined in Statistics.Resampling Methods (==) :: Resample -> Resample -> Bool Source # (/=) :: Resample -> Resample -> Bool Source #
type Rep Resample Source # |
Instance details Defined in Statistics.Resampling type Rep Resample = D1 ('MetaData "Resample" "Statistics.Resampling" "statistics-0.16.2.1-An1XEEv5tKOFj5G6JDoeTv" 'True) (C1 ('MetaCons "Resample" 'PrefixI 'True) (S1 ('MetaSel ('Just "fromResample") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Vector Double))))

data Bootstrap v a Source #

Constructors

Bootstrap |

Fields

- fullSample :: !a
- resamples :: v a

#### Instances

Instances details

Foldable v => Foldable (Bootstrap v) Source # |

Instance details

Defined in Statistics.Resampling

Methods

fold :: Monoid m => Bootstrap v m -> m Source #

foldMap :: Monoid m => (a -> m) -> Bootstrap v a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Bootstrap v a -> m Source #

foldr :: (a -> b -> b) -> b -> Bootstrap v a -> b Source #

foldr' :: (a -> b -> b) -> b -> Bootstrap v a -> b Source #

foldl :: (b -> a -> b) -> b -> Bootstrap v a -> b Source #

foldl' :: (b -> a -> b) -> b -> Bootstrap v a -> b Source #

foldr1 :: (a -> a -> a) -> Bootstrap v a -> a Source #

foldl1 :: (a -> a -> a) -> Bootstrap v a -> a Source #

toList :: Bootstrap v a -> [a] Source #

null :: Bootstrap v a -> Bool Source #

length :: Bootstrap v a -> Int Source #

elem :: Eq a => a -> Bootstrap v a -> Bool Source #

maximum :: Ord a => Bootstrap v a -> a Source #

minimum :: Ord a => Bootstrap v a -> a Source #

sum :: Num a => Bootstrap v a -> a Source #

product :: Num a => Bootstrap v a -> a Source #

Traversable v => Traversable (Bootstrap v) Source # |
Instance details Defined in Statistics.Resampling Methods traverse :: Applicative f => (a -> f b) -> Bootstrap v a -> f (Bootstrap v b) Source # sequenceA :: Applicative f => Bootstrap v (f a) -> f (Bootstrap v a) Source # mapM :: Monad m => (a -> m b) -> Bootstrap v a -> m (Bootstrap v b) Source # sequence :: Monad m => Bootstrap v (m a) -> m (Bootstrap v a) Source #
Functor v => Functor (Bootstrap v) Source # |
Instance details Defined in Statistics.Resampling Methods fmap :: (a -> b) -> Bootstrap v a -> Bootstrap v b Source # (<$) :: a -> Bootstrap v b -> Bootstrap v a Source #
(FromJSON a, FromJSON (v a)) => FromJSON (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods parseJSON :: Value -> Parser (Bootstrap v a) Source # parseJSONList :: Value -> Parser [Bootstrap v a] Source #
(ToJSON a, ToJSON (v a)) => ToJSON (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods toJSON :: Bootstrap v a -> Value Source # toEncoding :: Bootstrap v a -> Encoding Source # toJSONList :: [Bootstrap v a] -> Value Source # toEncodingList :: [Bootstrap v a] -> Encoding Source #
(Typeable v, Data a, Data (v a)) => Data (Bootstrap v a) Source # |

Instance details

Defined in Statistics.Resampling

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Bootstrap v a -> c (Bootstrap v a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Bootstrap v a) Source #

toConstr :: Bootstrap v a -> Constr Source #

dataTypeOf :: Bootstrap v a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Bootstrap v a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Bootstrap v a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Bootstrap v a -> Bootstrap v a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bootstrap v a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bootstrap v a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Bootstrap v a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Bootstrap v a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Bootstrap v a -> m (Bootstrap v a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Bootstrap v a -> m (Bootstrap v a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Bootstrap v a -> m (Bootstrap v a) Source #

Generic (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Associated Types type Rep (Bootstrap v a) :: Type -> Type Source # Methods from :: Bootstrap v a -> Rep (Bootstrap v a) x Source # to :: Rep (Bootstrap v a) x -> Bootstrap v a Source #
(Read a, Read (v a)) => Read (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods readsPrec :: Int -> ReadS (Bootstrap v a) Source # readList :: ReadS [Bootstrap v a] Source # readPrec :: ReadPrec (Bootstrap v a) Source # readListPrec :: ReadPrec [Bootstrap v a] Source #
(Show a, Show (v a)) => Show (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods showsPrec :: Int -> Bootstrap v a -> ShowS Source # show :: Bootstrap v a -> String Source # showList :: [Bootstrap v a] -> ShowS Source #
(Binary a, Binary (v a)) => Binary (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods put :: Bootstrap v a -> Put Source # get :: Get (Bootstrap v a) Source # putList :: [Bootstrap v a] -> Put Source #
(Eq a, Eq (v a)) => Eq (Bootstrap v a) Source # |
Instance details Defined in Statistics.Resampling Methods (==) :: Bootstrap v a -> Bootstrap v a -> Bool Source # (/=) :: Bootstrap v a -> Bootstrap v a -> Bool Source #
type Rep (Bootstrap v a) Source # |

Instance details

Defined in Statistics.Resampling

type Rep (Bootstrap v a) = D1 ('MetaData "Bootstrap" "Statistics.Resampling" "statistics-0.16.2.1-An1XEEv5tKOFj5G6JDoeTv" 'False) (C1 ('MetaCons "Bootstrap" 'PrefixI 'True) (S1 ('MetaSel ('Just "fullSample") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Just "resamples") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (v a))))

data Estimator Source #

An estimator of a property of a sample, such as its `mean`.

The use of an algebraic data type here allows functions such as `jackknife` and `bootstrapBCA` to use more efficient algorithms when possible.

Constructors

Mean |
Variance |
VarianceUnbiased |
StdDev |
Function (Sample -> Double) |

estimate :: Estimator -> Sample -> Double Source #

Run an `Estimator` over a sample.

# Resampling

resampleST Source #

Arguments

:: PrimMonad m |
=> Gen (PrimState m) |
-> [Estimator] | Estimation functions.
-> Int | Number of resamples to compute.
-> Vector Double | Original sample.
-> m [Bootstrap Vector Double] |

Single threaded and deterministic version of resample.

resample Source #

Arguments

:: GenIO |
-> [Estimator] | Estimation functions.
-> Int | Number of resamples to compute.
-> Vector Double | Original sample.
-> IO [(Estimator, Bootstrap Vector Double)] |

O(e*r*s) Resample a data set repeatedly, with replacement, computing each estimate over the resampled data.

This function is expensive; it has to do work proportional to e*r*s, where e is the number of estimation functions, r is the number of resamples to compute, and s is the number of original samples.

To improve performance, this function will make use of all available CPUs. At least with GHC 7.0, parallel performance seems best if the parallel garbage collector is disabled (RTS option `-qg`).

resampleVector :: (PrimMonad m, Vector v a) => Gen (PrimState m) -> v a -> m (v a) Source #

Create vector using resamples

# Jackknife

jackknife :: Estimator -> Sample -> Vector Double Source #

O(n) or O(n^2) Compute a statistical estimate repeatedly over a sample, each time omitting a successive element.

jackknifeMean :: Sample -> Vector Double Source #

O(n) Compute the jackknife mean of a sample.

jackknifeVariance :: Sample -> Vector Double Source #

O(n) Compute the jackknife variance of a sample.

jackknifeVarianceUnb :: Sample -> Vector Double Source #

O(n) Compute the unbiased jackknife variance of a sample.

jackknifeStdDev :: Sample -> Vector Double Source #

O(n) Compute the jackknife standard deviation of a sample.

# Helper functions

splitGen :: Int -> GenIO -> IO [GenIO] Source #

Split a generator into several that can run independently.