module Statistics.Distribution.Exponential
(
ExponentialDistribution
, fromLambda
, fromSample
, edLambda
) where
import Data.Typeable (Typeable)
import qualified Statistics.Distribution as D
import qualified Statistics.Sample as S
import Statistics.Types (Sample)
newtype ExponentialDistribution = ED {
edLambda :: Double
} deriving (Eq, Read, Show, Typeable)
instance D.Distribution ExponentialDistribution where
density (ED l) x = l * exp (l * x)
cumulative (ED l) x = 1 exp (l * x)
quantile (ED l) p = log (1 p) / l
instance D.Variance ExponentialDistribution where
variance (ED l) = 1 / (l * l)
instance D.Mean ExponentialDistribution where
mean (ED l) = 1 / l
fromLambda :: Double
-> ExponentialDistribution
fromLambda = ED
fromSample :: Sample -> ExponentialDistribution
fromSample = ED . S.mean