{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
-- |
-- Module    : Statistics.Types
-- Copyright : (c) 2009 Bryan O'Sullivan
-- License   : BSD3
--
-- Maintainer  : bos@serpentine.com
-- Stability   : experimental
-- Portability : portable
--
-- Data types common used in statistics
module Statistics.Types
    ( -- * Confidence level
      CL
      -- ** Accessors
    , confidenceLevel
    , significanceLevel
      -- ** Constructors
    , mkCL
    , mkCLE
    , mkCLFromSignificance
    , mkCLFromSignificanceE
      -- ** Constants and conversion to nσ
    , cl90
    , cl95
    , cl99
      -- *** Normal approximation
    , nSigma
    , nSigma1
    , getNSigma
    , getNSigma1
      -- * p-value
    , PValue
      -- ** Accessors
    , pValue
      -- ** Constructors
    , mkPValue
    , mkPValueE
      -- * Estimates and upper/lower limits
    , Estimate(..)
    , NormalErr(..)
    , ConfInt(..)
    , UpperLimit(..)
    , LowerLimit(..)
      -- ** Constructors
    , estimateNormErr
    , (±)
    , estimateFromInterval
    , estimateFromErr
      -- ** Accessors
    , confidenceInterval
    , asymErrors
    , Scale(..)
      -- * Other
    , Sample
    , WeightedSample
    , Weights
    ) where

import Control.Monad                ((<=<), liftM2, liftM3)
import Control.DeepSeq              (NFData(..))
import Data.Aeson                   (FromJSON(..), ToJSON)
import Data.Binary                  (Binary(..))
import Data.Data                    (Data,Typeable)
import Data.Maybe                   (fromMaybe)
import Data.Vector.Unboxed          (Unbox)
import Data.Vector.Unboxed.Deriving (derivingUnbox)
import GHC.Generics                 (Generic)
import Statistics.Internal
import Statistics.Types.Internal
import Statistics.Distribution
import Statistics.Distribution.Normal


----------------------------------------------------------------
-- Data type for confidence level
----------------------------------------------------------------

-- |
-- 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@.
newtype CL a = CL a
               deriving (CL a -> CL a -> Bool
(CL a -> CL a -> Bool) -> (CL a -> CL a -> Bool) -> Eq (CL a)
forall a. Eq a => CL a -> CL a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CL a -> CL a -> Bool
$c/= :: forall a. Eq a => CL a -> CL a -> Bool
== :: CL a -> CL a -> Bool
$c== :: forall a. Eq a => CL a -> CL a -> Bool
Eq, Typeable, Typeable (CL a)
DataType
Constr
Typeable (CL a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> CL a -> c (CL a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (CL a))
-> (CL a -> Constr)
-> (CL a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (CL a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a)))
-> ((forall b. Data b => b -> b) -> CL a -> CL a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r)
-> (forall u. (forall d. Data d => d -> u) -> CL a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> CL a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> CL a -> m (CL a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CL a -> m (CL a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> CL a -> m (CL a))
-> Data (CL a)
CL a -> DataType
CL a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (CL a))
(forall b. Data b => b -> b) -> CL a -> CL a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CL a -> c (CL a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CL a)
forall a. Data a => Typeable (CL a)
forall a. Data a => CL a -> DataType
forall a. Data a => CL a -> Constr
forall a. Data a => (forall b. Data b => b -> b) -> CL a -> CL a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> CL a -> u
forall a u. Data a => (forall d. Data d => d -> u) -> CL a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CL a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CL a -> c (CL a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CL a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> CL a -> u
forall u. (forall d. Data d => d -> u) -> CL a -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CL a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CL a -> c (CL a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (CL a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a))
$cCL :: Constr
$tCL :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> CL a -> m (CL a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
gmapMp :: (forall d. Data d => d -> m d) -> CL a -> m (CL a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
gmapM :: (forall d. Data d => d -> m d) -> CL a -> m (CL a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> CL a -> m (CL a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> CL a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> CL a -> u
gmapQ :: (forall d. Data d => d -> u) -> CL a -> [u]
$cgmapQ :: forall a u. Data a => (forall d. Data d => d -> u) -> CL a -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> CL a -> r
gmapT :: (forall b. Data b => b -> b) -> CL a -> CL a
$cgmapT :: forall a. Data a => (forall b. Data b => b -> b) -> CL a -> CL a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (CL a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (CL a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (CL a))
dataTypeOf :: CL a -> DataType
$cdataTypeOf :: forall a. Data a => CL a -> DataType
toConstr :: CL a -> Constr
$ctoConstr :: forall a. Data a => CL a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CL a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (CL a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CL a -> c (CL a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> CL a -> c (CL a)
$cp1Data :: forall a. Data a => Typeable (CL a)
Data, (forall x. CL a -> Rep (CL a) x)
-> (forall x. Rep (CL a) x -> CL a) -> Generic (CL a)
forall x. Rep (CL a) x -> CL a
forall x. CL a -> Rep (CL a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (CL a) x -> CL a
forall a x. CL a -> Rep (CL a) x
$cto :: forall a x. Rep (CL a) x -> CL a
$cfrom :: forall a x. CL a -> Rep (CL a) x
Generic)

instance Show a => Show (CL a) where
  showsPrec :: Int -> CL a -> ShowS
showsPrec Int
n (CL a
p) = String -> a -> Int -> ShowS
forall a. Show a => String -> a -> Int -> ShowS
defaultShow1 String
"mkCLFromSignificance" a
p Int
n
instance (Num a, Ord a, Read a) => Read (CL a) where
  readPrec :: ReadPrec (CL a)
readPrec = String -> (a -> Maybe (CL a)) -> ReadPrec (CL a)
forall a r. Read a => String -> (a -> Maybe r) -> ReadPrec r
defaultReadPrecM1 String
"mkCLFromSignificance" a -> Maybe (CL a)
forall a. (Ord a, Num a) => a -> Maybe (CL a)
mkCLFromSignificanceE

instance (Binary a, Num a, Ord a) => Binary (CL a) where
  put :: CL a -> Put
put (CL a
p) = a -> Put
forall t. Binary t => t -> Put
put a
p
  get :: Get (CL a)
get        = Get (CL a) -> (CL a -> Get (CL a)) -> Maybe (CL a) -> Get (CL a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Get (CL a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
errMkCL) CL a -> Get (CL a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (CL a) -> Get (CL a))
-> (a -> Maybe (CL a)) -> a -> Get (CL a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (CL a)
forall a. (Ord a, Num a) => a -> Maybe (CL a)
mkCLFromSignificanceE (a -> Get (CL a)) -> Get a -> Get (CL a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get a
forall t. Binary t => Get t
get

instance (ToJSON a)                 => ToJSON   (CL a)
instance (FromJSON a, Num a, Ord a) => FromJSON (CL a) where
  parseJSON :: Value -> Parser (CL a)
parseJSON = Parser (CL a)
-> (CL a -> Parser (CL a)) -> Maybe (CL a) -> Parser (CL a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (CL a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
errMkCL) CL a -> Parser (CL a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (CL a) -> Parser (CL a))
-> (a -> Maybe (CL a)) -> a -> Parser (CL a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (CL a)
forall a. (Ord a, Num a) => a -> Maybe (CL a)
mkCLFromSignificanceE (a -> Parser (CL a))
-> (Value -> Parser a) -> Value -> Parser (CL a)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON

instance NFData   a => NFData   (CL a) where
  rnf :: CL a -> ()
rnf (CL a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a

-- |
-- >>> cl95 > cl90
-- True
instance Ord a => Ord (CL a) where
  CL a
a < :: CL a -> CL a -> Bool
<  CL a
b = a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>  a
b
  CL a
a <= :: CL a -> CL a -> Bool
<= CL a
b = a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
b
  CL a
a > :: CL a -> CL a -> Bool
>  CL a
b = a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<  a
b
  CL a
a >= :: CL a -> CL a -> Bool
>= CL a
b = a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
b
  max :: CL a -> CL a -> CL a
max (CL a
a) (CL a
b) = a -> CL a
forall a. a -> CL a
CL (a -> a -> a
forall a. Ord a => a -> a -> a
min a
a a
b)
  min :: CL a -> CL a -> CL a
min (CL a
a) (CL a
b) = a -> CL a
forall a. a -> CL a
CL (a -> a -> a
forall a. Ord a => a -> a -> a
max a
a a
b)


-- | 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
mkCL :: (Ord a, Num a) => a -> CL a
mkCL :: a -> CL a
mkCL
  = CL a -> Maybe (CL a) -> CL a
forall a. a -> Maybe a -> a
fromMaybe (String -> CL a
forall a. HasCallStack => String -> a
error String
"Statistics.Types.mkCL: probability is out if [0,1] range")
  (Maybe (CL a) -> CL a) -> (a -> Maybe (CL a)) -> a -> CL a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (CL a)
forall a. (Ord a, Num a) => a -> Maybe (CL a)
mkCLE

-- | 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)
mkCLE :: (Ord a, Num a) => a -> Maybe (CL a)
mkCLE :: a -> Maybe (CL a)
mkCLE a
p
  | a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0 Bool -> Bool -> Bool
&& a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 = CL a -> Maybe (CL a)
forall a. a -> Maybe a
Just (CL a -> Maybe (CL a)) -> CL a -> Maybe (CL a)
forall a b. (a -> b) -> a -> b
$ a -> CL a
forall a. a -> CL a
CL (a
1 a -> a -> a
forall a. Num a => a -> a -> a
- a
p)
  | Bool
otherwise        = Maybe (CL a)
forall a. Maybe a
Nothing

-- | 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
mkCLFromSignificance :: (Ord a, Num a) => a -> CL a
mkCLFromSignificance :: a -> CL a
mkCLFromSignificance = CL a -> Maybe (CL a) -> CL a
forall a. a -> Maybe a -> a
fromMaybe (String -> CL a
forall a. HasCallStack => String -> a
error String
errMkCL) (Maybe (CL a) -> CL a) -> (a -> Maybe (CL a)) -> a -> CL a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (CL a)
forall a. (Ord a, Num a) => a -> Maybe (CL a)
mkCLFromSignificanceE

-- | 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)
mkCLFromSignificanceE :: (Ord a, Num a) => a -> Maybe (CL a)
mkCLFromSignificanceE :: a -> Maybe (CL a)
mkCLFromSignificanceE a
p
  | a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0 Bool -> Bool -> Bool
&& a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 = CL a -> Maybe (CL a)
forall a. a -> Maybe a
Just (CL a -> Maybe (CL a)) -> CL a -> Maybe (CL a)
forall a b. (a -> b) -> a -> b
$ a -> CL a
forall a. a -> CL a
CL a
p
  | Bool
otherwise        = Maybe (CL a)
forall a. Maybe a
Nothing

errMkCL :: String
errMkCL :: String
errMkCL = String
"Statistics.Types.mkPValCL: probability is out if [0,1] range"


-- | Get confidence level. This function is subject to rounding
--   errors. If @1 - CL@ is needed use 'significanceLevel' instead
confidenceLevel :: (Num a) => CL a -> a
confidenceLevel :: CL a -> a
confidenceLevel (CL a
p) = a
1 a -> a -> a
forall a. Num a => a -> a -> a
- a
p

-- | Get significance level.
significanceLevel :: CL a -> a
significanceLevel :: CL a -> a
significanceLevel (CL a
p) = a
p



-- | 90% confidence level
cl90 :: Fractional a => CL a
cl90 :: CL a
cl90 = a -> CL a
forall a. a -> CL a
CL a
0.10

-- | 95% confidence level
cl95 :: Fractional a => CL a
cl95 :: CL a
cl95 = a -> CL a
forall a. a -> CL a
CL a
0.05

-- | 99% confidence level
cl99 :: Fractional a => CL a
cl99 :: CL a
cl99 = a -> CL a
forall a. a -> CL a
CL a
0.01



----------------------------------------------------------------
-- Data type for p-value
----------------------------------------------------------------

-- | Newtype wrapper for p-value.
newtype PValue a = PValue a
               deriving (PValue a -> PValue a -> Bool
(PValue a -> PValue a -> Bool)
-> (PValue a -> PValue a -> Bool) -> Eq (PValue a)
forall a. Eq a => PValue a -> PValue a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PValue a -> PValue a -> Bool
$c/= :: forall a. Eq a => PValue a -> PValue a -> Bool
== :: PValue a -> PValue a -> Bool
$c== :: forall a. Eq a => PValue a -> PValue a -> Bool
Eq,Eq (PValue a)
Eq (PValue a)
-> (PValue a -> PValue a -> Ordering)
-> (PValue a -> PValue a -> Bool)
-> (PValue a -> PValue a -> Bool)
-> (PValue a -> PValue a -> Bool)
-> (PValue a -> PValue a -> Bool)
-> (PValue a -> PValue a -> PValue a)
-> (PValue a -> PValue a -> PValue a)
-> Ord (PValue a)
PValue a -> PValue a -> Bool
PValue a -> PValue a -> Ordering
PValue a -> PValue a -> PValue a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (PValue a)
forall a. Ord a => PValue a -> PValue a -> Bool
forall a. Ord a => PValue a -> PValue a -> Ordering
forall a. Ord a => PValue a -> PValue a -> PValue a
min :: PValue a -> PValue a -> PValue a
$cmin :: forall a. Ord a => PValue a -> PValue a -> PValue a
max :: PValue a -> PValue a -> PValue a
$cmax :: forall a. Ord a => PValue a -> PValue a -> PValue a
>= :: PValue a -> PValue a -> Bool
$c>= :: forall a. Ord a => PValue a -> PValue a -> Bool
> :: PValue a -> PValue a -> Bool
$c> :: forall a. Ord a => PValue a -> PValue a -> Bool
<= :: PValue a -> PValue a -> Bool
$c<= :: forall a. Ord a => PValue a -> PValue a -> Bool
< :: PValue a -> PValue a -> Bool
$c< :: forall a. Ord a => PValue a -> PValue a -> Bool
compare :: PValue a -> PValue a -> Ordering
$ccompare :: forall a. Ord a => PValue a -> PValue a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (PValue a)
Ord, Typeable, Typeable (PValue a)
DataType
Constr
Typeable (PValue a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PValue a -> c (PValue a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PValue a))
-> (PValue a -> Constr)
-> (PValue a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PValue a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PValue a)))
-> ((forall b. Data b => b -> b) -> PValue a -> PValue a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PValue a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PValue a -> r)
-> (forall u. (forall d. Data d => d -> u) -> PValue a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> PValue a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PValue a -> m (PValue a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PValue a -> m (PValue a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PValue a -> m (PValue a))
-> Data (PValue a)
PValue a -> DataType
PValue a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (PValue a))
(forall b. Data b => b -> b) -> PValue a -> PValue a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PValue a -> c (PValue a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PValue a)
forall a. Data a => Typeable (PValue a)
forall a. Data a => PValue a -> DataType
forall a. Data a => PValue a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> PValue a -> PValue a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> PValue a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> PValue a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PValue a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PValue a -> c (PValue a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PValue a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PValue a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PValue a -> u
forall u. (forall d. Data d => d -> u) -> PValue a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PValue a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PValue a -> c (PValue a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PValue a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PValue a))
$cPValue :: Constr
$tPValue :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
gmapMp :: (forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
gmapM :: (forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> PValue a -> m (PValue a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> PValue a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> PValue a -> u
gmapQ :: (forall d. Data d => d -> u) -> PValue a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> PValue a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PValue a -> r
gmapT :: (forall b. Data b => b -> b) -> PValue a -> PValue a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> PValue a -> PValue a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PValue a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (PValue a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (PValue a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PValue a))
dataTypeOf :: PValue a -> DataType
$cdataTypeOf :: forall a. Data a => PValue a -> DataType
toConstr :: PValue a -> Constr
$ctoConstr :: forall a. Data a => PValue a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PValue a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PValue a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PValue a -> c (PValue a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PValue a -> c (PValue a)
$cp1Data :: forall a. Data a => Typeable (PValue a)
Data, (forall x. PValue a -> Rep (PValue a) x)
-> (forall x. Rep (PValue a) x -> PValue a) -> Generic (PValue a)
forall x. Rep (PValue a) x -> PValue a
forall x. PValue a -> Rep (PValue a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (PValue a) x -> PValue a
forall a x. PValue a -> Rep (PValue a) x
$cto :: forall a x. Rep (PValue a) x -> PValue a
$cfrom :: forall a x. PValue a -> Rep (PValue a) x
Generic)

instance Show a => Show (PValue a) where
  showsPrec :: Int -> PValue a -> ShowS
showsPrec Int
n (PValue a
p) = String -> a -> Int -> ShowS
forall a. Show a => String -> a -> Int -> ShowS
defaultShow1 String
"mkPValue" a
p Int
n
instance (Num a, Ord a, Read a) => Read (PValue a) where
  readPrec :: ReadPrec (PValue a)
readPrec = String -> (a -> Maybe (PValue a)) -> ReadPrec (PValue a)
forall a r. Read a => String -> (a -> Maybe r) -> ReadPrec r
defaultReadPrecM1 String
"mkPValue" a -> Maybe (PValue a)
forall a. (Ord a, Num a) => a -> Maybe (PValue a)
mkPValueE

instance (Binary a, Num a, Ord a) => Binary (PValue a) where
  put :: PValue a -> Put
put (PValue a
p) = a -> Put
forall t. Binary t => t -> Put
put a
p
  get :: Get (PValue a)
get            = Get (PValue a)
-> (PValue a -> Get (PValue a))
-> Maybe (PValue a)
-> Get (PValue a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Get (PValue a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
errMkPValue) PValue a -> Get (PValue a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (PValue a) -> Get (PValue a))
-> (a -> Maybe (PValue a)) -> a -> Get (PValue a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (PValue a)
forall a. (Ord a, Num a) => a -> Maybe (PValue a)
mkPValueE (a -> Get (PValue a)) -> Get a -> Get (PValue a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Get a
forall t. Binary t => Get t
get

instance (ToJSON a)                 => ToJSON   (PValue a)
instance (FromJSON a, Num a, Ord a) => FromJSON (PValue a) where
  parseJSON :: Value -> Parser (PValue a)
parseJSON = Parser (PValue a)
-> (PValue a -> Parser (PValue a))
-> Maybe (PValue a)
-> Parser (PValue a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser (PValue a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
errMkPValue) PValue a -> Parser (PValue a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (PValue a) -> Parser (PValue a))
-> (a -> Maybe (PValue a)) -> a -> Parser (PValue a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (PValue a)
forall a. (Ord a, Num a) => a -> Maybe (PValue a)
mkPValueE (a -> Parser (PValue a))
-> (Value -> Parser a) -> Value -> Parser (PValue a)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Value -> Parser a
forall a. FromJSON a => Value -> Parser a
parseJSON

instance NFData a => NFData (PValue a) where
  rnf :: PValue a -> ()
rnf (PValue a
a) = a -> ()
forall a. NFData a => a -> ()
rnf a
a


-- | Construct PValue. Throws error if argument is out of [0,1] range.
--
mkPValue :: (Ord a, Num a) => a -> PValue a
mkPValue :: a -> PValue a
mkPValue = PValue a -> Maybe (PValue a) -> PValue a
forall a. a -> Maybe a -> a
fromMaybe (String -> PValue a
forall a. HasCallStack => String -> a
error String
errMkPValue) (Maybe (PValue a) -> PValue a)
-> (a -> Maybe (PValue a)) -> a -> PValue a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe (PValue a)
forall a. (Ord a, Num a) => a -> Maybe (PValue a)
mkPValueE

-- | Construct PValue. Returns @Nothing@ if argument is out of [0,1] range.
mkPValueE :: (Ord a, Num a) => a -> Maybe (PValue a)
mkPValueE :: a -> Maybe (PValue a)
mkPValueE a
p
  | a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0 Bool -> Bool -> Bool
&& a
p a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
1 = PValue a -> Maybe (PValue a)
forall a. a -> Maybe a
Just (PValue a -> Maybe (PValue a)) -> PValue a -> Maybe (PValue a)
forall a b. (a -> b) -> a -> b
$ a -> PValue a
forall a. a -> PValue a
PValue a
p
  | Bool
otherwise        = Maybe (PValue a)
forall a. Maybe a
Nothing

-- | Get p-value
pValue :: PValue a -> a
pValue :: PValue a -> a
pValue (PValue a
p) = a
p


-- | 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).
nSigma :: Double -> PValue Double
nSigma :: Double -> PValue Double
nSigma Double
n
  | Double
n Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0     = Double -> PValue Double
forall a. a -> PValue a
PValue (Double -> PValue Double) -> Double -> PValue Double
forall a b. (a -> b) -> a -> b
$ Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
* NormalDistribution -> Double -> Double
forall d. Distribution d => d -> Double -> Double
cumulative NormalDistribution
standard (-Double
n)
  | Bool
otherwise = String -> PValue Double
forall a. HasCallStack => String -> a
error String
"Statistics.Extra.Error.nSigma: non-positive number of sigma"

-- | P-value expressed in sigma for one-tail hypothesis. This correspond to
--   probability of obtaining value less than @N·σ@.
nSigma1 :: Double -> PValue Double
nSigma1 :: Double -> PValue Double
nSigma1 Double
n
  | Double
n Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0     = Double -> PValue Double
forall a. a -> PValue a
PValue (Double -> PValue Double) -> Double -> PValue Double
forall a b. (a -> b) -> a -> b
$ NormalDistribution -> Double -> Double
forall d. Distribution d => d -> Double -> Double
cumulative NormalDistribution
standard (-Double
n)
  | Bool
otherwise = String -> PValue Double
forall a. HasCallStack => String -> a
error String
"Statistics.Extra.Error.nSigma1: non-positive number of sigma"

-- | Express confidence level in sigmas
getNSigma :: PValue Double -> Double
getNSigma :: PValue Double -> Double
getNSigma (PValue Double
p) = Double -> Double
forall a. Num a => a -> a
negate (Double -> Double) -> Double -> Double
forall a b. (a -> b) -> a -> b
$ NormalDistribution -> Double -> Double
forall d. ContDistr d => d -> Double -> Double
quantile NormalDistribution
standard (Double
p Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Double
2)

-- | Express confidence level in sigmas for one-tailed hypothesis.
getNSigma1 :: PValue Double -> Double
getNSigma1 :: PValue Double -> Double
getNSigma1 (PValue Double
p) = Double -> Double
forall a. Num a => a -> a
negate (Double -> Double) -> Double -> Double
forall a b. (a -> b) -> a -> b
$ NormalDistribution -> Double -> Double
forall d. ContDistr d => d -> Double -> Double
quantile NormalDistribution
standard Double
p



errMkPValue :: String
errMkPValue :: String
errMkPValue = String
"Statistics.Types.mkPValue: probability is out if [0,1] range"



----------------------------------------------------------------
-- Point estimates
----------------------------------------------------------------

-- |
-- 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.
data Estimate e a = Estimate
    { Estimate e a -> a
estPoint           :: !a
      -- ^ Point estimate.
    , Estimate e a -> e a
estError           :: !(e a)
      -- ^ Confidence interval for estimate.
    } deriving (Estimate e a -> Estimate e a -> Bool
(Estimate e a -> Estimate e a -> Bool)
-> (Estimate e a -> Estimate e a -> Bool) -> Eq (Estimate e a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (e :: * -> *) a.
(Eq a, Eq (e a)) =>
Estimate e a -> Estimate e a -> Bool
/= :: Estimate e a -> Estimate e a -> Bool
$c/= :: forall (e :: * -> *) a.
(Eq a, Eq (e a)) =>
Estimate e a -> Estimate e a -> Bool
== :: Estimate e a -> Estimate e a -> Bool
$c== :: forall (e :: * -> *) a.
(Eq a, Eq (e a)) =>
Estimate e a -> Estimate e a -> Bool
Eq, ReadPrec [Estimate e a]
ReadPrec (Estimate e a)
Int -> ReadS (Estimate e a)
ReadS [Estimate e a]
(Int -> ReadS (Estimate e a))
-> ReadS [Estimate e a]
-> ReadPrec (Estimate e a)
-> ReadPrec [Estimate e a]
-> Read (Estimate e a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadPrec [Estimate e a]
forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadPrec (Estimate e a)
forall (e :: * -> *) a.
(Read a, Read (e a)) =>
Int -> ReadS (Estimate e a)
forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadS [Estimate e a]
readListPrec :: ReadPrec [Estimate e a]
$creadListPrec :: forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadPrec [Estimate e a]
readPrec :: ReadPrec (Estimate e a)
$creadPrec :: forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadPrec (Estimate e a)
readList :: ReadS [Estimate e a]
$creadList :: forall (e :: * -> *) a.
(Read a, Read (e a)) =>
ReadS [Estimate e a]
readsPrec :: Int -> ReadS (Estimate e a)
$creadsPrec :: forall (e :: * -> *) a.
(Read a, Read (e a)) =>
Int -> ReadS (Estimate e a)
Read, Int -> Estimate e a -> ShowS
[Estimate e a] -> ShowS
Estimate e a -> String
(Int -> Estimate e a -> ShowS)
-> (Estimate e a -> String)
-> ([Estimate e a] -> ShowS)
-> Show (Estimate e a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (e :: * -> *) a.
(Show a, Show (e a)) =>
Int -> Estimate e a -> ShowS
forall (e :: * -> *) a.
(Show a, Show (e a)) =>
[Estimate e a] -> ShowS
forall (e :: * -> *) a.
(Show a, Show (e a)) =>
Estimate e a -> String
showList :: [Estimate e a] -> ShowS
$cshowList :: forall (e :: * -> *) a.
(Show a, Show (e a)) =>
[Estimate e a] -> ShowS
show :: Estimate e a -> String
$cshow :: forall (e :: * -> *) a.
(Show a, Show (e a)) =>
Estimate e a -> String
showsPrec :: Int -> Estimate e a -> ShowS
$cshowsPrec :: forall (e :: * -> *) a.
(Show a, Show (e a)) =>
Int -> Estimate e a -> ShowS
Show, (forall x. Estimate e a -> Rep (Estimate e a) x)
-> (forall x. Rep (Estimate e a) x -> Estimate e a)
-> Generic (Estimate e a)
forall x. Rep (Estimate e a) x -> Estimate e a
forall x. Estimate e a -> Rep (Estimate e a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (e :: * -> *) a x. Rep (Estimate e a) x -> Estimate e a
forall (e :: * -> *) a x. Estimate e a -> Rep (Estimate e a) x
$cto :: forall (e :: * -> *) a x. Rep (Estimate e a) x -> Estimate e a
$cfrom :: forall (e :: * -> *) a x. Estimate e a -> Rep (Estimate e a) x
Generic
               , Typeable, Typeable (Estimate e a)
DataType
Constr
Typeable (Estimate e a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (Estimate e a))
-> (Estimate e a -> Constr)
-> (Estimate e a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (Estimate e a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Estimate e a)))
-> ((forall b. Data b => b -> b) -> Estimate e a -> Estimate e a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Estimate e a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Estimate e a -> r)
-> (forall u. (forall d. Data d => d -> u) -> Estimate e a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Estimate e a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a))
-> Data (Estimate e a)
Estimate e a -> DataType
Estimate e a -> Constr
(forall b. Data b => b -> b) -> Estimate e a -> Estimate e a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Estimate e a)
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Estimate e a -> u
forall u. (forall d. Data d => d -> u) -> Estimate e a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Estimate e a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a)
forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Typeable (Estimate e a)
forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Estimate e a -> DataType
forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Estimate e a -> Constr
forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
(forall b. Data b => b -> b) -> Estimate e a -> Estimate e a
forall (e :: * -> *) a u.
(Typeable e, Data a, Data (e a)) =>
Int -> (forall d. Data d => d -> u) -> Estimate e a -> u
forall (e :: * -> *) a u.
(Typeable e, Data a, Data (e a)) =>
(forall d. Data d => d -> u) -> Estimate e a -> [u]
forall (e :: * -> *) a r r'.
(Typeable e, Data a, Data (e a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
forall (e :: * -> *) a r r'.
(Typeable e, Data a, Data (e a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
forall (e :: * -> *) a (m :: * -> *).
(Typeable e, Data a, Data (e a), Monad m) =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
forall (e :: * -> *) a (m :: * -> *).
(Typeable e, Data a, Data (e a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
forall (e :: * -> *) a (c :: * -> *).
(Typeable e, Data a, Data (e a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Estimate e a)
forall (e :: * -> *) a (c :: * -> *).
(Typeable e, Data a, Data (e a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a)
forall (e :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable e, Data a, Data (e a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Estimate e a))
forall (e :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable e, Data a, Data (e a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Estimate e a))
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (Estimate e a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Estimate e a))
$cEstimate :: Constr
$tEstimate :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
$cgmapMo :: forall (e :: * -> *) a (m :: * -> *).
(Typeable e, Data a, Data (e a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
gmapMp :: (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
$cgmapMp :: forall (e :: * -> *) a (m :: * -> *).
(Typeable e, Data a, Data (e a), MonadPlus m) =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
gmapM :: (forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
$cgmapM :: forall (e :: * -> *) a (m :: * -> *).
(Typeable e, Data a, Data (e a), Monad m) =>
(forall d. Data d => d -> m d) -> Estimate e a -> m (Estimate e a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> Estimate e a -> u
$cgmapQi :: forall (e :: * -> *) a u.
(Typeable e, Data a, Data (e a)) =>
Int -> (forall d. Data d => d -> u) -> Estimate e a -> u
gmapQ :: (forall d. Data d => d -> u) -> Estimate e a -> [u]
$cgmapQ :: forall (e :: * -> *) a u.
(Typeable e, Data a, Data (e a)) =>
(forall d. Data d => d -> u) -> Estimate e a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
$cgmapQr :: forall (e :: * -> *) a r r'.
(Typeable e, Data a, Data (e a)) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
$cgmapQl :: forall (e :: * -> *) a r r'.
(Typeable e, Data a, Data (e a)) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Estimate e a -> r
gmapT :: (forall b. Data b => b -> b) -> Estimate e a -> Estimate e a
$cgmapT :: forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
(forall b. Data b => b -> b) -> Estimate e a -> Estimate e a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Estimate e a))
$cdataCast2 :: forall (e :: * -> *) a (t :: * -> * -> *) (c :: * -> *).
(Typeable e, Data a, Data (e a), Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Estimate e a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (Estimate e a))
$cdataCast1 :: forall (e :: * -> *) a (t :: * -> *) (c :: * -> *).
(Typeable e, Data a, Data (e a), Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (Estimate e a))
dataTypeOf :: Estimate e a -> DataType
$cdataTypeOf :: forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Estimate e a -> DataType
toConstr :: Estimate e a -> Constr
$ctoConstr :: forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Estimate e a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Estimate e a)
$cgunfold :: forall (e :: * -> *) a (c :: * -> *).
(Typeable e, Data a, Data (e a)) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Estimate e a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a)
$cgfoldl :: forall (e :: * -> *) a (c :: * -> *).
(Typeable e, Data a, Data (e a)) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Estimate e a -> c (Estimate e a)
$cp1Data :: forall (e :: * -> *) a.
(Typeable e, Data a, Data (e a)) =>
Typeable (Estimate e a)
Data
               )

instance (Binary   (e a), Binary   a) => Binary   (Estimate e a) where
  get :: Get (Estimate e a)
get = (a -> e a -> Estimate e a)
-> Get a -> Get (e a) -> Get (Estimate e a)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> e a -> Estimate e a
forall (e :: * -> *) a. a -> e a -> Estimate e a
Estimate Get a
forall t. Binary t => Get t
get Get (e a)
forall t. Binary t => Get t
get
  put :: Estimate e a -> Put
put (Estimate a
ep e a
ee) = a -> Put
forall t. Binary t => t -> Put
put a
ep Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> e a -> Put
forall t. Binary t => t -> Put
put e a
ee
instance (FromJSON (e a), FromJSON a) => FromJSON (Estimate e a)
instance (ToJSON   (e a), ToJSON   a) => ToJSON   (Estimate e a)
instance (NFData   (e a), NFData   a) => NFData   (Estimate e a) where
    rnf :: Estimate e a -> ()
rnf (Estimate a
x e a
dx) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` e a -> ()
forall a. NFData a => a -> ()
rnf e a
dx



-- |
-- 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.
newtype NormalErr a = NormalErr
  { NormalErr a -> a
normalError :: a
  }
  deriving (NormalErr a -> NormalErr a -> Bool
(NormalErr a -> NormalErr a -> Bool)
-> (NormalErr a -> NormalErr a -> Bool) -> Eq (NormalErr a)
forall a. Eq a => NormalErr a -> NormalErr a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NormalErr a -> NormalErr a -> Bool
$c/= :: forall a. Eq a => NormalErr a -> NormalErr a -> Bool
== :: NormalErr a -> NormalErr a -> Bool
$c== :: forall a. Eq a => NormalErr a -> NormalErr a -> Bool
Eq, ReadPrec [NormalErr a]
ReadPrec (NormalErr a)
Int -> ReadS (NormalErr a)
ReadS [NormalErr a]
(Int -> ReadS (NormalErr a))
-> ReadS [NormalErr a]
-> ReadPrec (NormalErr a)
-> ReadPrec [NormalErr a]
-> Read (NormalErr a)
forall a. Read a => ReadPrec [NormalErr a]
forall a. Read a => ReadPrec (NormalErr a)
forall a. Read a => Int -> ReadS (NormalErr a)
forall a. Read a => ReadS [NormalErr a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [NormalErr a]
$creadListPrec :: forall a. Read a => ReadPrec [NormalErr a]
readPrec :: ReadPrec (NormalErr a)
$creadPrec :: forall a. Read a => ReadPrec (NormalErr a)
readList :: ReadS [NormalErr a]
$creadList :: forall a. Read a => ReadS [NormalErr a]
readsPrec :: Int -> ReadS (NormalErr a)
$creadsPrec :: forall a. Read a => Int -> ReadS (NormalErr a)
Read, Int -> NormalErr a -> ShowS
[NormalErr a] -> ShowS
NormalErr a -> String
(Int -> NormalErr a -> ShowS)
-> (NormalErr a -> String)
-> ([NormalErr a] -> ShowS)
-> Show (NormalErr a)
forall a. Show a => Int -> NormalErr a -> ShowS
forall a. Show a => [NormalErr a] -> ShowS
forall a. Show a => NormalErr a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NormalErr a] -> ShowS
$cshowList :: forall a. Show a => [NormalErr a] -> ShowS
show :: NormalErr a -> String
$cshow :: forall a. Show a => NormalErr a -> String
showsPrec :: Int -> NormalErr a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> NormalErr a -> ShowS
Show, Typeable, Typeable (NormalErr a)
DataType
Constr
Typeable (NormalErr a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (NormalErr a))
-> (NormalErr a -> Constr)
-> (NormalErr a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (NormalErr a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (NormalErr a)))
-> ((forall b. Data b => b -> b) -> NormalErr a -> NormalErr a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NormalErr a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NormalErr a -> r)
-> (forall u. (forall d. Data d => d -> u) -> NormalErr a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NormalErr a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a))
-> Data (NormalErr a)
NormalErr a -> DataType
NormalErr a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (NormalErr a))
(forall b. Data b => b -> b) -> NormalErr a -> NormalErr a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NormalErr a)
forall a. Data a => Typeable (NormalErr a)
forall a. Data a => NormalErr a -> DataType
forall a. Data a => NormalErr a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> NormalErr a -> NormalErr a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NormalErr a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> NormalErr a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NormalErr a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NormalErr a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NormalErr a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NormalErr a -> u
forall u. (forall d. Data d => d -> u) -> NormalErr a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NormalErr a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (NormalErr a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NormalErr a))
$cNormalErr :: Constr
$tNormalErr :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
gmapMp :: (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
gmapM :: (forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> NormalErr a -> m (NormalErr a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> NormalErr a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NormalErr a -> u
gmapQ :: (forall d. Data d => d -> u) -> NormalErr a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> NormalErr a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NormalErr a -> r
gmapT :: (forall b. Data b => b -> b) -> NormalErr a -> NormalErr a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> NormalErr a -> NormalErr a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NormalErr a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NormalErr a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (NormalErr a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NormalErr a))
dataTypeOf :: NormalErr a -> DataType
$cdataTypeOf :: forall a. Data a => NormalErr a -> DataType
toConstr :: NormalErr a -> Constr
$ctoConstr :: forall a. Data a => NormalErr a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NormalErr a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NormalErr a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NormalErr a -> c (NormalErr a)
$cp1Data :: forall a. Data a => Typeable (NormalErr a)
Data, (forall x. NormalErr a -> Rep (NormalErr a) x)
-> (forall x. Rep (NormalErr a) x -> NormalErr a)
-> Generic (NormalErr a)
forall x. Rep (NormalErr a) x -> NormalErr a
forall x. NormalErr a -> Rep (NormalErr a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (NormalErr a) x -> NormalErr a
forall a x. NormalErr a -> Rep (NormalErr a) x
$cto :: forall a x. Rep (NormalErr a) x -> NormalErr a
$cfrom :: forall a x. NormalErr a -> Rep (NormalErr a) x
Generic)

instance Binary   a => Binary   (NormalErr a) where
  get :: Get (NormalErr a)
get = (a -> NormalErr a) -> Get a -> Get (NormalErr a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> NormalErr a
forall a. a -> NormalErr a
NormalErr Get a
forall t. Binary t => Get t
get
  put :: NormalErr a -> Put
put = a -> Put
forall t. Binary t => t -> Put
put (a -> Put) -> (NormalErr a -> a) -> NormalErr a -> Put
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NormalErr a -> a
forall a. NormalErr a -> a
normalError
instance FromJSON a => FromJSON (NormalErr a)
instance ToJSON   a => ToJSON   (NormalErr a)
instance NFData   a => NFData   (NormalErr a) where
    rnf :: NormalErr a -> ()
rnf (NormalErr a
x) = a -> ()
forall a. NFData a => a -> ()
rnf a
x


-- | Confidence interval. It assumes that confidence interval forms
--   single interval and isn't set of disjoint intervals.
data ConfInt a = ConfInt
  { ConfInt a -> a
confIntLDX :: !a
    -- ^ Lower error estimate, or distance between point estimate and
    --   lower bound of confidence interval.
  , ConfInt a -> a
confIntUDX :: !a
    -- ^ Upper error estimate, or distance between point estimate and
    --   upper bound of confidence interval.
  , ConfInt a -> CL Double
confIntCL  :: !(CL Double)
    -- ^ Confidence level corresponding to given confidence interval.
  }
  deriving (ReadPrec [ConfInt a]
ReadPrec (ConfInt a)
Int -> ReadS (ConfInt a)
ReadS [ConfInt a]
(Int -> ReadS (ConfInt a))
-> ReadS [ConfInt a]
-> ReadPrec (ConfInt a)
-> ReadPrec [ConfInt a]
-> Read (ConfInt a)
forall a. Read a => ReadPrec [ConfInt a]
forall a. Read a => ReadPrec (ConfInt a)
forall a. Read a => Int -> ReadS (ConfInt a)
forall a. Read a => ReadS [ConfInt a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ConfInt a]
$creadListPrec :: forall a. Read a => ReadPrec [ConfInt a]
readPrec :: ReadPrec (ConfInt a)
$creadPrec :: forall a. Read a => ReadPrec (ConfInt a)
readList :: ReadS [ConfInt a]
$creadList :: forall a. Read a => ReadS [ConfInt a]
readsPrec :: Int -> ReadS (ConfInt a)
$creadsPrec :: forall a. Read a => Int -> ReadS (ConfInt a)
Read,Int -> ConfInt a -> ShowS
[ConfInt a] -> ShowS
ConfInt a -> String
(Int -> ConfInt a -> ShowS)
-> (ConfInt a -> String)
-> ([ConfInt a] -> ShowS)
-> Show (ConfInt a)
forall a. Show a => Int -> ConfInt a -> ShowS
forall a. Show a => [ConfInt a] -> ShowS
forall a. Show a => ConfInt a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfInt a] -> ShowS
$cshowList :: forall a. Show a => [ConfInt a] -> ShowS
show :: ConfInt a -> String
$cshow :: forall a. Show a => ConfInt a -> String
showsPrec :: Int -> ConfInt a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ConfInt a -> ShowS
Show,ConfInt a -> ConfInt a -> Bool
(ConfInt a -> ConfInt a -> Bool)
-> (ConfInt a -> ConfInt a -> Bool) -> Eq (ConfInt a)
forall a. Eq a => ConfInt a -> ConfInt a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfInt a -> ConfInt a -> Bool
$c/= :: forall a. Eq a => ConfInt a -> ConfInt a -> Bool
== :: ConfInt a -> ConfInt a -> Bool
$c== :: forall a. Eq a => ConfInt a -> ConfInt a -> Bool
Eq,Typeable,Typeable (ConfInt a)
DataType
Constr
Typeable (ConfInt a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (ConfInt a))
-> (ConfInt a -> Constr)
-> (ConfInt a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (ConfInt a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (ConfInt a)))
-> ((forall b. Data b => b -> b) -> ConfInt a -> ConfInt a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfInt a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ConfInt a -> r)
-> (forall u. (forall d. Data d => d -> u) -> ConfInt a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ConfInt a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a))
-> Data (ConfInt a)
ConfInt a -> DataType
ConfInt a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (ConfInt a))
(forall b. Data b => b -> b) -> ConfInt a -> ConfInt a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConfInt a)
forall a. Data a => Typeable (ConfInt a)
forall a. Data a => ConfInt a -> DataType
forall a. Data a => ConfInt a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> ConfInt a -> ConfInt a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> ConfInt a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> ConfInt a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConfInt a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ConfInt a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConfInt a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ConfInt a -> u
forall u. (forall d. Data d => d -> u) -> ConfInt a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConfInt a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ConfInt a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConfInt a))
$cConfInt :: Constr
$tConfInt :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
gmapMp :: (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
gmapM :: (forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> ConfInt a -> m (ConfInt a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> ConfInt a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> ConfInt a -> u
gmapQ :: (forall d. Data d => d -> u) -> ConfInt a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> ConfInt a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ConfInt a -> r
gmapT :: (forall b. Data b => b -> b) -> ConfInt a -> ConfInt a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> ConfInt a -> ConfInt a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConfInt a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ConfInt a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (ConfInt a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ConfInt a))
dataTypeOf :: ConfInt a -> DataType
$cdataTypeOf :: forall a. Data a => ConfInt a -> DataType
toConstr :: ConfInt a -> Constr
$ctoConstr :: forall a. Data a => ConfInt a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConfInt a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ConfInt a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ConfInt a -> c (ConfInt a)
$cp1Data :: forall a. Data a => Typeable (ConfInt a)
Data,(forall x. ConfInt a -> Rep (ConfInt a) x)
-> (forall x. Rep (ConfInt a) x -> ConfInt a)
-> Generic (ConfInt a)
forall x. Rep (ConfInt a) x -> ConfInt a
forall x. ConfInt a -> Rep (ConfInt a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (ConfInt a) x -> ConfInt a
forall a x. ConfInt a -> Rep (ConfInt a) x
$cto :: forall a x. Rep (ConfInt a) x -> ConfInt a
$cfrom :: forall a x. ConfInt a -> Rep (ConfInt a) x
Generic)

instance Binary   a => Binary   (ConfInt a) where
  get :: Get (ConfInt a)
get = (a -> a -> CL Double -> ConfInt a)
-> Get a -> Get a -> Get (CL Double) -> Get (ConfInt a)
forall (m :: * -> *) a1 a2 a3 r.
Monad m =>
(a1 -> a2 -> a3 -> r) -> m a1 -> m a2 -> m a3 -> m r
liftM3 a -> a -> CL Double -> ConfInt a
forall a. a -> a -> CL Double -> ConfInt a
ConfInt Get a
forall t. Binary t => Get t
get Get a
forall t. Binary t => Get t
get Get (CL Double)
forall t. Binary t => Get t
get
  put :: ConfInt a -> Put
put (ConfInt a
l a
u CL Double
cl) = a -> Put
forall t. Binary t => t -> Put
put a
l Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> a -> Put
forall t. Binary t => t -> Put
put a
u Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CL Double -> Put
forall t. Binary t => t -> Put
put CL Double
cl 
instance FromJSON a => FromJSON (ConfInt a)
instance ToJSON   a => ToJSON   (ConfInt a)
instance NFData   a => NFData   (ConfInt a) where
    rnf :: ConfInt a -> ()
rnf (ConfInt a
x a
y CL Double
_) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` a -> ()
forall a. NFData a => a -> ()
rnf a
y



----------------------------------------
-- Constructors

-- | Create estimate with normal errors
estimateNormErr :: a            -- ^ Point estimate
                -> a            -- ^ 1σ error
                -> Estimate NormalErr a
estimateNormErr :: a -> a -> Estimate NormalErr a
estimateNormErr a
x a
dx = a -> NormalErr a -> Estimate NormalErr a
forall (e :: * -> *) a. a -> e a -> Estimate e a
Estimate a
x (a -> NormalErr a
forall a. a -> NormalErr a
NormalErr a
dx)

-- | Synonym for 'estimateNormErr'
(±) :: a      -- ^ Point estimate
    -> a      -- ^ 1σ error
    -> Estimate NormalErr a
± :: a -> a -> Estimate NormalErr a
(±) = a -> a -> Estimate NormalErr a
forall a. a -> a -> Estimate NormalErr a
estimateNormErr

-- | Create estimate with asymmetric error.
estimateFromErr
  :: 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
estimateFromErr :: a -> (a, a) -> CL Double -> Estimate ConfInt a
estimateFromErr a
x (a
ldx,a
udx) CL Double
cl = a -> ConfInt a -> Estimate ConfInt a
forall (e :: * -> *) a. a -> e a -> Estimate e a
Estimate a
x (a -> a -> CL Double -> ConfInt a
forall a. a -> a -> CL Double -> ConfInt a
ConfInt a
ldx a
udx CL Double
cl)

-- | Create estimate with asymmetric error.
estimateFromInterval
  :: 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
estimateFromInterval :: a -> (a, a) -> CL Double -> Estimate ConfInt a
estimateFromInterval a
x (a
lx,a
ux) CL Double
cl
  = a -> ConfInt a -> Estimate ConfInt a
forall (e :: * -> *) a. a -> e a -> Estimate e a
Estimate a
x (a -> a -> CL Double -> ConfInt a
forall a. a -> a -> CL Double -> ConfInt a
ConfInt (a
xa -> a -> a
forall a. Num a => a -> a -> a
-a
lx) (a
uxa -> a -> a
forall a. Num a => a -> a -> a
-a
x) CL Double
cl)


----------------------------------------
-- Accessors

-- | Get confidence interval
confidenceInterval :: Num a => Estimate ConfInt a -> (a,a)
confidenceInterval :: Estimate ConfInt a -> (a, a)
confidenceInterval (Estimate a
x (ConfInt a
ldx a
udx CL Double
_))
  = (a
x a -> a -> a
forall a. Num a => a -> a -> a
- a
ldx, a
x a -> a -> a
forall a. Num a => a -> a -> a
+ a
udx)

-- | Get asymmetric errors
asymErrors :: Estimate ConfInt a -> (a,a)
asymErrors :: Estimate ConfInt a -> (a, a)
asymErrors (Estimate a
_ (ConfInt a
ldx a
udx CL Double
_)) = (a
ldx,a
udx)



-- | Data types which could be multiplied by constant.
class Scale e where
  scale :: (Ord a, Num a) => a -> e a -> e a

instance Scale NormalErr where
  scale :: a -> NormalErr a -> NormalErr a
scale a
a (NormalErr a
e) = a -> NormalErr a
forall a. a -> NormalErr a
NormalErr (a -> a
forall a. Num a => a -> a
abs a
a a -> a -> a
forall a. Num a => a -> a -> a
* a
e)

instance Scale ConfInt where
  scale :: a -> ConfInt a -> ConfInt a
scale a
a (ConfInt a
l a
u CL Double
cl) | a
a a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
0    = a -> a -> CL Double -> ConfInt a
forall a. a -> a -> CL Double -> ConfInt a
ConfInt  (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
l)  (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
u) CL Double
cl
                           | Bool
otherwise = a -> a -> CL Double -> ConfInt a
forall a. a -> a -> CL Double -> ConfInt a
ConfInt (-a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
u) (-a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
l) CL Double
cl

instance Scale e => Scale (Estimate e) where
  scale :: a -> Estimate e a -> Estimate e a
scale a
a (Estimate a
x e a
dx) = a -> e a -> Estimate e a
forall (e :: * -> *) a. a -> e a -> Estimate e a
Estimate (a
aa -> a -> a
forall a. Num a => a -> a -> a
*a
x) (a -> e a -> e a
forall (e :: * -> *) a. (Scale e, Ord a, Num a) => a -> e a -> e a
scale a
a e a
dx)



----------------------------------------------------------------
-- Upper/lower limit
----------------------------------------------------------------

-- | Upper limit. They are usually given for small non-negative values
--   when it's not possible detect difference from zero.
data UpperLimit a = UpperLimit
    { UpperLimit a -> a
upperLimit        :: !a
      -- ^ Upper limit
    , UpperLimit a -> CL Double
ulConfidenceLevel :: !(CL Double)
      -- ^ Confidence level for which limit was calculated
    } deriving (UpperLimit a -> UpperLimit a -> Bool
(UpperLimit a -> UpperLimit a -> Bool)
-> (UpperLimit a -> UpperLimit a -> Bool) -> Eq (UpperLimit a)
forall a. Eq a => UpperLimit a -> UpperLimit a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpperLimit a -> UpperLimit a -> Bool
$c/= :: forall a. Eq a => UpperLimit a -> UpperLimit a -> Bool
== :: UpperLimit a -> UpperLimit a -> Bool
$c== :: forall a. Eq a => UpperLimit a -> UpperLimit a -> Bool
Eq, ReadPrec [UpperLimit a]
ReadPrec (UpperLimit a)
Int -> ReadS (UpperLimit a)
ReadS [UpperLimit a]
(Int -> ReadS (UpperLimit a))
-> ReadS [UpperLimit a]
-> ReadPrec (UpperLimit a)
-> ReadPrec [UpperLimit a]
-> Read (UpperLimit a)
forall a. Read a => ReadPrec [UpperLimit a]
forall a. Read a => ReadPrec (UpperLimit a)
forall a. Read a => Int -> ReadS (UpperLimit a)
forall a. Read a => ReadS [UpperLimit a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpperLimit a]
$creadListPrec :: forall a. Read a => ReadPrec [UpperLimit a]
readPrec :: ReadPrec (UpperLimit a)
$creadPrec :: forall a. Read a => ReadPrec (UpperLimit a)
readList :: ReadS [UpperLimit a]
$creadList :: forall a. Read a => ReadS [UpperLimit a]
readsPrec :: Int -> ReadS (UpperLimit a)
$creadsPrec :: forall a. Read a => Int -> ReadS (UpperLimit a)
Read, Int -> UpperLimit a -> ShowS
[UpperLimit a] -> ShowS
UpperLimit a -> String
(Int -> UpperLimit a -> ShowS)
-> (UpperLimit a -> String)
-> ([UpperLimit a] -> ShowS)
-> Show (UpperLimit a)
forall a. Show a => Int -> UpperLimit a -> ShowS
forall a. Show a => [UpperLimit a] -> ShowS
forall a. Show a => UpperLimit a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpperLimit a] -> ShowS
$cshowList :: forall a. Show a => [UpperLimit a] -> ShowS
show :: UpperLimit a -> String
$cshow :: forall a. Show a => UpperLimit a -> String
showsPrec :: Int -> UpperLimit a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> UpperLimit a -> ShowS
Show, Typeable, Typeable (UpperLimit a)
DataType
Constr
Typeable (UpperLimit a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UpperLimit a))
-> (UpperLimit a -> Constr)
-> (UpperLimit a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UpperLimit a)))
-> ((forall b. Data b => b -> b) -> UpperLimit a -> UpperLimit a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r)
-> (forall u. (forall d. Data d => d -> u) -> UpperLimit a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> UpperLimit a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a))
-> Data (UpperLimit a)
UpperLimit a -> DataType
UpperLimit a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a))
(forall b. Data b => b -> b) -> UpperLimit a -> UpperLimit a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpperLimit a)
forall a. Data a => Typeable (UpperLimit a)
forall a. Data a => UpperLimit a -> DataType
forall a. Data a => UpperLimit a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> UpperLimit a -> UpperLimit a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> UpperLimit a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> UpperLimit a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpperLimit a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpperLimit a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> UpperLimit a -> u
forall u. (forall d. Data d => d -> u) -> UpperLimit a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpperLimit a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpperLimit a))
$cUpperLimit :: Constr
$tUpperLimit :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
gmapMp :: (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
gmapM :: (forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> UpperLimit a -> m (UpperLimit a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> UpperLimit a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> UpperLimit a -> u
gmapQ :: (forall d. Data d => d -> u) -> UpperLimit a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> UpperLimit a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpperLimit a -> r
gmapT :: (forall b. Data b => b -> b) -> UpperLimit a -> UpperLimit a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> UpperLimit a -> UpperLimit a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpperLimit a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpperLimit a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (UpperLimit a))
dataTypeOf :: UpperLimit a -> DataType
$cdataTypeOf :: forall a. Data a => UpperLimit a -> DataType
toConstr :: UpperLimit a -> Constr
$ctoConstr :: forall a. Data a => UpperLimit a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpperLimit a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpperLimit a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpperLimit a -> c (UpperLimit a)
$cp1Data :: forall a. Data a => Typeable (UpperLimit a)
Data, (forall x. UpperLimit a -> Rep (UpperLimit a) x)
-> (forall x. Rep (UpperLimit a) x -> UpperLimit a)
-> Generic (UpperLimit a)
forall x. Rep (UpperLimit a) x -> UpperLimit a
forall x. UpperLimit a -> Rep (UpperLimit a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (UpperLimit a) x -> UpperLimit a
forall a x. UpperLimit a -> Rep (UpperLimit a) x
$cto :: forall a x. Rep (UpperLimit a) x -> UpperLimit a
$cfrom :: forall a x. UpperLimit a -> Rep (UpperLimit a) x
Generic)


instance Binary   a => Binary   (UpperLimit a) where
  get :: Get (UpperLimit a)
get = (a -> CL Double -> UpperLimit a)
-> Get a -> Get (CL Double) -> Get (UpperLimit a)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> CL Double -> UpperLimit a
forall a. a -> CL Double -> UpperLimit a
UpperLimit Get a
forall t. Binary t => Get t
get Get (CL Double)
forall t. Binary t => Get t
get
  put :: UpperLimit a -> Put
put (UpperLimit a
l CL Double
cl) = a -> Put
forall t. Binary t => t -> Put
put a
l Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CL Double -> Put
forall t. Binary t => t -> Put
put CL Double
cl
instance FromJSON a => FromJSON (UpperLimit a)
instance ToJSON   a => ToJSON   (UpperLimit a)
instance NFData   a => NFData   (UpperLimit a) where
    rnf :: UpperLimit a -> ()
rnf (UpperLimit a
x CL Double
cl) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` CL Double -> ()
forall a. NFData a => a -> ()
rnf CL Double
cl



-- | Lower limit. They are usually given for large quantities when
--   it's not possible to measure them. For example: proton half-life
data LowerLimit a = LowerLimit {
    LowerLimit a -> a
lowerLimit        :: !a
    -- ^ Lower limit
  , LowerLimit a -> CL Double
llConfidenceLevel :: !(CL Double)
    -- ^ Confidence level for which limit was calculated
  } deriving (LowerLimit a -> LowerLimit a -> Bool
(LowerLimit a -> LowerLimit a -> Bool)
-> (LowerLimit a -> LowerLimit a -> Bool) -> Eq (LowerLimit a)
forall a. Eq a => LowerLimit a -> LowerLimit a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LowerLimit a -> LowerLimit a -> Bool
$c/= :: forall a. Eq a => LowerLimit a -> LowerLimit a -> Bool
== :: LowerLimit a -> LowerLimit a -> Bool
$c== :: forall a. Eq a => LowerLimit a -> LowerLimit a -> Bool
Eq, ReadPrec [LowerLimit a]
ReadPrec (LowerLimit a)
Int -> ReadS (LowerLimit a)
ReadS [LowerLimit a]
(Int -> ReadS (LowerLimit a))
-> ReadS [LowerLimit a]
-> ReadPrec (LowerLimit a)
-> ReadPrec [LowerLimit a]
-> Read (LowerLimit a)
forall a. Read a => ReadPrec [LowerLimit a]
forall a. Read a => ReadPrec (LowerLimit a)
forall a. Read a => Int -> ReadS (LowerLimit a)
forall a. Read a => ReadS [LowerLimit a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LowerLimit a]
$creadListPrec :: forall a. Read a => ReadPrec [LowerLimit a]
readPrec :: ReadPrec (LowerLimit a)
$creadPrec :: forall a. Read a => ReadPrec (LowerLimit a)
readList :: ReadS [LowerLimit a]
$creadList :: forall a. Read a => ReadS [LowerLimit a]
readsPrec :: Int -> ReadS (LowerLimit a)
$creadsPrec :: forall a. Read a => Int -> ReadS (LowerLimit a)
Read, Int -> LowerLimit a -> ShowS
[LowerLimit a] -> ShowS
LowerLimit a -> String
(Int -> LowerLimit a -> ShowS)
-> (LowerLimit a -> String)
-> ([LowerLimit a] -> ShowS)
-> Show (LowerLimit a)
forall a. Show a => Int -> LowerLimit a -> ShowS
forall a. Show a => [LowerLimit a] -> ShowS
forall a. Show a => LowerLimit a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LowerLimit a] -> ShowS
$cshowList :: forall a. Show a => [LowerLimit a] -> ShowS
show :: LowerLimit a -> String
$cshow :: forall a. Show a => LowerLimit a -> String
showsPrec :: Int -> LowerLimit a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> LowerLimit a -> ShowS
Show, Typeable, Typeable (LowerLimit a)
DataType
Constr
Typeable (LowerLimit a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (LowerLimit a))
-> (LowerLimit a -> Constr)
-> (LowerLimit a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (LowerLimit a)))
-> ((forall b. Data b => b -> b) -> LowerLimit a -> LowerLimit a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r)
-> (forall u. (forall d. Data d => d -> u) -> LowerLimit a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> LowerLimit a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a))
-> Data (LowerLimit a)
LowerLimit a -> DataType
LowerLimit a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a))
(forall b. Data b => b -> b) -> LowerLimit a -> LowerLimit a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LowerLimit a)
forall a. Data a => Typeable (LowerLimit a)
forall a. Data a => LowerLimit a -> DataType
forall a. Data a => LowerLimit a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> LowerLimit a -> LowerLimit a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> LowerLimit a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> LowerLimit a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LowerLimit a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LowerLimit a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> LowerLimit a -> u
forall u. (forall d. Data d => d -> u) -> LowerLimit a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LowerLimit a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LowerLimit a))
$cLowerLimit :: Constr
$tLowerLimit :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
gmapMp :: (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
gmapM :: (forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> LowerLimit a -> m (LowerLimit a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> LowerLimit a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> LowerLimit a -> u
gmapQ :: (forall d. Data d => d -> u) -> LowerLimit a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> LowerLimit a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LowerLimit a -> r
gmapT :: (forall b. Data b => b -> b) -> LowerLimit a -> LowerLimit a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> LowerLimit a -> LowerLimit a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LowerLimit a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LowerLimit a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (LowerLimit a))
dataTypeOf :: LowerLimit a -> DataType
$cdataTypeOf :: forall a. Data a => LowerLimit a -> DataType
toConstr :: LowerLimit a -> Constr
$ctoConstr :: forall a. Data a => LowerLimit a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LowerLimit a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LowerLimit a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LowerLimit a -> c (LowerLimit a)
$cp1Data :: forall a. Data a => Typeable (LowerLimit a)
Data, (forall x. LowerLimit a -> Rep (LowerLimit a) x)
-> (forall x. Rep (LowerLimit a) x -> LowerLimit a)
-> Generic (LowerLimit a)
forall x. Rep (LowerLimit a) x -> LowerLimit a
forall x. LowerLimit a -> Rep (LowerLimit a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (LowerLimit a) x -> LowerLimit a
forall a x. LowerLimit a -> Rep (LowerLimit a) x
$cto :: forall a x. Rep (LowerLimit a) x -> LowerLimit a
$cfrom :: forall a x. LowerLimit a -> Rep (LowerLimit a) x
Generic)

instance Binary   a => Binary   (LowerLimit a) where
  get :: Get (LowerLimit a)
get = (a -> CL Double -> LowerLimit a)
-> Get a -> Get (CL Double) -> Get (LowerLimit a)
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 a -> CL Double -> LowerLimit a
forall a. a -> CL Double -> LowerLimit a
LowerLimit Get a
forall t. Binary t => Get t
get Get (CL Double)
forall t. Binary t => Get t
get
  put :: LowerLimit a -> Put
put (LowerLimit a
l CL Double
cl) = a -> Put
forall t. Binary t => t -> Put
put a
l Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CL Double -> Put
forall t. Binary t => t -> Put
put CL Double
cl
instance FromJSON a => FromJSON (LowerLimit a)
instance ToJSON   a => ToJSON   (LowerLimit a)
instance NFData   a => NFData   (LowerLimit a) where
    rnf :: LowerLimit a -> ()
rnf (LowerLimit a
x CL Double
cl) = a -> ()
forall a. NFData a => a -> ()
rnf a
x () -> () -> ()
`seq` CL Double -> ()
forall a. NFData a => a -> ()
rnf CL Double
cl


----------------------------------------------------------------
-- Deriving unbox instances
----------------------------------------------------------------

derivingUnbox "CL"
  [t| forall a. Unbox a => CL a -> a |]
  [| \(CL a) -> a |]
  [| CL           |]

derivingUnbox "PValue"
  [t| forall a. Unbox a => PValue a -> a |]
  [| \(PValue a) -> a |]
  [| PValue           |]

derivingUnbox "Estimate"
  [t| forall a e. (Unbox a, Unbox (e a)) => Estimate e a -> (a, e a) |]
  [| \(Estimate x dx) -> (x,dx) |]
  [| \(x,dx) -> (Estimate x dx) |]

derivingUnbox "NormalErr"
  [t| forall a. Unbox a => NormalErr a -> a |]
  [| \(NormalErr a) -> a |]
  [| NormalErr           |]

derivingUnbox "ConfInt"
  [t| forall a. Unbox a => ConfInt a -> (a, a, CL Double) |]
  [| \(ConfInt a b c) -> (a,b,c) |]
  [| \(a,b,c) -> ConfInt a b c   |]

derivingUnbox "UpperLimit"
  [t| forall a. Unbox a => UpperLimit a -> (a, CL Double) |]
  [| \(UpperLimit a b) -> (a,b) |]
  [| \(a,b) -> UpperLimit a b   |]

derivingUnbox "LowerLimit"
  [t| forall a. Unbox a => LowerLimit a -> (a, CL Double) |]
  [| \(LowerLimit a b) -> (a,b) |]
  [| \(a,b) -> LowerLimit a b   |]