{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
module Statistics.Distribution.FDistribution (
FDistribution
, fDistribution
, fDistributionE
, fDistributionReal
, fDistributionRealE
, fDistributionNDF1
, fDistributionNDF2
) where
import Control.Applicative
import Data.Aeson (FromJSON(..), ToJSON, Value(..), (.:))
import Data.Binary (Binary(..))
import Data.Data (Data, Typeable)
import GHC.Generics (Generic)
import Numeric.SpecFunctions (
logBeta, incompleteBeta, invIncompleteBeta, digamma)
import Numeric.MathFunctions.Constants (m_neg_inf)
import qualified Statistics.Distribution as D
import Statistics.Function (square)
import Statistics.Internal
data FDistribution = F { FDistribution -> Double
fDistributionNDF1 :: {-# UNPACK #-} !Double
, FDistribution -> Double
fDistributionNDF2 :: {-# UNPACK #-} !Double
, FDistribution -> Double
_pdfFactor :: {-# UNPACK #-} !Double
}
deriving (FDistribution -> FDistribution -> Bool
(FDistribution -> FDistribution -> Bool)
-> (FDistribution -> FDistribution -> Bool) -> Eq FDistribution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FDistribution -> FDistribution -> Bool
$c/= :: FDistribution -> FDistribution -> Bool
== :: FDistribution -> FDistribution -> Bool
$c== :: FDistribution -> FDistribution -> Bool
Eq, Typeable, Typeable FDistribution
DataType
Constr
Typeable FDistribution
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FDistribution -> c FDistribution)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FDistribution)
-> (FDistribution -> Constr)
-> (FDistribution -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FDistribution))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FDistribution))
-> ((forall b. Data b => b -> b) -> FDistribution -> FDistribution)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r)
-> (forall u. (forall d. Data d => d -> u) -> FDistribution -> [u])
-> (forall u.
Int -> (forall d. Data d => d -> u) -> FDistribution -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution)
-> Data FDistribution
FDistribution -> DataType
FDistribution -> Constr
(forall b. Data b => b -> b) -> FDistribution -> FDistribution
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FDistribution -> c FDistribution
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FDistribution
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) -> FDistribution -> u
forall u. (forall d. Data d => d -> u) -> FDistribution -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FDistribution
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FDistribution -> c FDistribution
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FDistribution)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FDistribution)
$cF :: Constr
$tFDistribution :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
gmapMp :: (forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
gmapM :: (forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> FDistribution -> m FDistribution
gmapQi :: Int -> (forall d. Data d => d -> u) -> FDistribution -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> FDistribution -> u
gmapQ :: (forall d. Data d => d -> u) -> FDistribution -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> FDistribution -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> FDistribution -> r
gmapT :: (forall b. Data b => b -> b) -> FDistribution -> FDistribution
$cgmapT :: (forall b. Data b => b -> b) -> FDistribution -> FDistribution
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FDistribution)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c FDistribution)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c FDistribution)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c FDistribution)
dataTypeOf :: FDistribution -> DataType
$cdataTypeOf :: FDistribution -> DataType
toConstr :: FDistribution -> Constr
$ctoConstr :: FDistribution -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FDistribution
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c FDistribution
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FDistribution -> c FDistribution
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> FDistribution -> c FDistribution
$cp1Data :: Typeable FDistribution
Data, (forall x. FDistribution -> Rep FDistribution x)
-> (forall x. Rep FDistribution x -> FDistribution)
-> Generic FDistribution
forall x. Rep FDistribution x -> FDistribution
forall x. FDistribution -> Rep FDistribution x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FDistribution x -> FDistribution
$cfrom :: forall x. FDistribution -> Rep FDistribution x
Generic)
instance Show FDistribution where
showsPrec :: Int -> FDistribution -> ShowS
showsPrec Int
i (F Double
n Double
m Double
_) = String -> Double -> Double -> Int -> ShowS
forall a b. (Show a, Show b) => String -> a -> b -> Int -> ShowS
defaultShow2 String
"fDistributionReal" Double
n Double
m Int
i
instance Read FDistribution where
readPrec :: ReadPrec FDistribution
readPrec = String
-> (Double -> Double -> Maybe FDistribution)
-> ReadPrec FDistribution
forall a b r.
(Read a, Read b) =>
String -> (a -> b -> Maybe r) -> ReadPrec r
defaultReadPrecM2 String
"fDistributionReal" Double -> Double -> Maybe FDistribution
fDistributionRealE
instance ToJSON FDistribution
instance FromJSON FDistribution where
parseJSON :: Value -> Parser FDistribution
parseJSON (Object Object
v) = do
Double
n <- Object
v Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fDistributionNDF1"
Double
m <- Object
v Object -> Key -> Parser Double
forall a. FromJSON a => Object -> Key -> Parser a
.: Key
"fDistributionNDF2"
Parser FDistribution
-> (FDistribution -> Parser FDistribution)
-> Maybe FDistribution
-> Parser FDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Parser FDistribution
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser FDistribution) -> String -> Parser FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> String
errMsgR Double
n Double
m) FDistribution -> Parser FDistribution
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe FDistribution -> Parser FDistribution)
-> Maybe FDistribution -> Parser FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe FDistribution
fDistributionRealE Double
n Double
m
parseJSON Value
_ = Parser FDistribution
forall (f :: * -> *) a. Alternative f => f a
empty
instance Binary FDistribution where
put :: FDistribution -> Put
put (F Double
n Double
m Double
_) = Double -> Put
forall t. Binary t => t -> Put
put Double
n Put -> Put -> Put
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Double -> Put
forall t. Binary t => t -> Put
put Double
m
get :: Get FDistribution
get = do
Double
n <- Get Double
forall t. Binary t => Get t
get
Double
m <- Get Double
forall t. Binary t => Get t
get
Get FDistribution
-> (FDistribution -> Get FDistribution)
-> Maybe FDistribution
-> Get FDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> Get FDistribution
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Get FDistribution) -> String -> Get FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> String
errMsgR Double
n Double
m) FDistribution -> Get FDistribution
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe FDistribution -> Get FDistribution)
-> Maybe FDistribution -> Get FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe FDistribution
fDistributionRealE Double
n Double
m
fDistribution :: Int -> Int -> FDistribution
fDistribution :: Int -> Int -> FDistribution
fDistribution Int
n Int
m = FDistribution
-> (FDistribution -> FDistribution)
-> Maybe FDistribution
-> FDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> FDistribution
forall a. HasCallStack => String -> a
error (String -> FDistribution) -> String -> FDistribution
forall a b. (a -> b) -> a -> b
$ Int -> Int -> String
errMsg Int
n Int
m) FDistribution -> FDistribution
forall a. a -> a
id (Maybe FDistribution -> FDistribution)
-> Maybe FDistribution -> FDistribution
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Maybe FDistribution
fDistributionE Int
n Int
m
fDistributionReal :: Double -> Double -> FDistribution
fDistributionReal :: Double -> Double -> FDistribution
fDistributionReal Double
n Double
m = FDistribution
-> (FDistribution -> FDistribution)
-> Maybe FDistribution
-> FDistribution
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (String -> FDistribution
forall a. HasCallStack => String -> a
error (String -> FDistribution) -> String -> FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> String
errMsgR Double
n Double
m) FDistribution -> FDistribution
forall a. a -> a
id (Maybe FDistribution -> FDistribution)
-> Maybe FDistribution -> FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Maybe FDistribution
fDistributionRealE Double
n Double
m
fDistributionE :: Int -> Int -> Maybe FDistribution
fDistributionE :: Int -> Int -> Maybe FDistribution
fDistributionE Int
n Int
m
| Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
0 =
let n' :: Double
n' = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n
m' :: Double
m' = Int -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
m
f' :: Double
f' = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double -> Double
forall a. Floating a => a -> a
log Double
m' Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m' Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
log Double
n' Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n') Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double -> Double
logBeta (Double
0.5Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
n') (Double
0.5Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
m')
in FDistribution -> Maybe FDistribution
forall a. a -> Maybe a
Just (FDistribution -> Maybe FDistribution)
-> FDistribution -> Maybe FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> FDistribution
F Double
n' Double
m' Double
f'
| Bool
otherwise = Maybe FDistribution
forall a. Maybe a
Nothing
fDistributionRealE :: Double -> Double -> Maybe FDistribution
fDistributionRealE :: Double -> Double -> Maybe FDistribution
fDistributionRealE Double
n Double
m
| Double
n Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0 Bool -> Bool -> Bool
&& Double
m Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0 =
let f' :: Double
f' = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double -> Double
forall a. Floating a => a -> a
log Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
log Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double -> Double
logBeta (Double
0.5Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
n) (Double
0.5Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
m)
in FDistribution -> Maybe FDistribution
forall a. a -> Maybe a
Just (FDistribution -> Maybe FDistribution)
-> FDistribution -> Maybe FDistribution
forall a b. (a -> b) -> a -> b
$ Double -> Double -> Double -> FDistribution
F Double
n Double
m Double
f'
| Bool
otherwise = Maybe FDistribution
forall a. Maybe a
Nothing
errMsg :: Int -> Int -> String
errMsg :: Int -> Int -> String
errMsg Int
_ Int
_ = String
"Statistics.Distribution.FDistribution.fDistribution: non-positive number of degrees of freedom"
errMsgR :: Double -> Double -> String
errMsgR :: Double -> Double -> String
errMsgR Double
_ Double
_ = String
"Statistics.Distribution.FDistribution.fDistribution: non-positive number of degrees of freedom"
instance D.Distribution FDistribution where
cumulative :: FDistribution -> Double -> Double
cumulative = FDistribution -> Double -> Double
cumulative
complCumulative :: FDistribution -> Double -> Double
complCumulative = FDistribution -> Double -> Double
complCumulative
instance D.ContDistr FDistribution where
density :: FDistribution -> Double -> Double
density FDistribution
d Double
x
| Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0 = Double
0
| Bool
otherwise = Double -> Double
forall a. Floating a => a -> a
exp (Double -> Double) -> Double -> Double
forall a b. (a -> b) -> a -> b
$ FDistribution -> Double -> Double
logDensity FDistribution
d Double
x
logDensity :: FDistribution -> Double -> Double
logDensity FDistribution
d Double
x
| Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0 = Double
m_neg_inf
| Bool
otherwise = FDistribution -> Double -> Double
logDensity FDistribution
d Double
x
quantile :: FDistribution -> Double -> Double
quantile = FDistribution -> Double -> Double
quantile
cumulative :: FDistribution -> Double -> Double
cumulative :: FDistribution -> Double -> Double
cumulative (F Double
n Double
m Double
_) Double
x
| Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0 = Double
0
| Double -> Bool
forall a. RealFloat a => a -> Bool
isInfinite Double
x = Double
1
| Double
n Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= (Double
nDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
m)Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
bx = Double -> Double -> Double -> Double
incompleteBeta (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m) Double
bx
| Bool
otherwise = Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double -> Double -> Double
incompleteBeta (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m) (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) Double
bx1
where
y :: Double
y = Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
x
bx :: Double
bx = Double
y Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y)
bx1 :: Double
bx1 = Double
m Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y)
complCumulative :: FDistribution -> Double -> Double
complCumulative :: FDistribution -> Double -> Double
complCumulative (F Double
n Double
m Double
_) Double
x
| Double
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
0 = Double
1
| Double -> Bool
forall a. RealFloat a => a -> Bool
isInfinite Double
x = Double
0
| Double
m Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= (Double
nDouble -> Double -> Double
forall a. Num a => a -> a -> a
+Double
m)Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
bx = Double -> Double -> Double -> Double
incompleteBeta (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m) (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) Double
bx
| Bool
otherwise = Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double -> Double -> Double
incompleteBeta (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m) Double
bx1
where
y :: Double
y = Double
nDouble -> Double -> Double
forall a. Num a => a -> a -> a
*Double
x
bx :: Double
bx = Double
m Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y)
bx1 :: Double
bx1 = Double
y Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
y)
logDensity :: FDistribution -> Double -> Double
logDensity :: FDistribution -> Double -> Double
logDensity (F Double
n Double
m Double
fac) Double
x
= Double
fac Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double
forall a. Floating a => a -> a
log Double
x Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
1) Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double -> Double
forall a. Floating a => a -> a
log(Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
nDouble -> Double -> Double
forall a. Num a => a -> a -> a
*Double
x) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
m)
quantile :: FDistribution -> Double -> Double
quantile :: FDistribution -> Double -> Double
quantile (F Double
n Double
m Double
_) Double
p
| Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= Double
0 Bool -> Bool -> Bool
&& Double
p Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
<= Double
1 =
let x :: Double
x = Double -> Double -> Double -> Double
invIncompleteBeta (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n) (Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m) Double
p
in Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
x))
| Bool
otherwise =
String -> Double
forall a. HasCallStack => String -> a
error (String -> Double) -> String -> Double
forall a b. (a -> b) -> a -> b
$ String
"Statistics.Distribution.Uniform.quantile: p must be in [0,1] range. Got: "String -> ShowS
forall a. [a] -> [a] -> [a]
++Double -> String
forall a. Show a => a -> String
show Double
p
instance D.MaybeMean FDistribution where
maybeMean :: FDistribution -> Maybe Double
maybeMean (F Double
_ Double
m Double
_) | Double
m Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
2 = Double -> Maybe Double
forall a. a -> Maybe a
Just (Double -> Maybe Double) -> Double -> Maybe Double
forall a b. (a -> b) -> a -> b
$ Double
m Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
2)
| Bool
otherwise = Maybe Double
forall a. Maybe a
Nothing
instance D.MaybeVariance FDistribution where
maybeStdDev :: FDistribution -> Maybe Double
maybeStdDev (F Double
n Double
m Double
_)
| Double
m Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
4 = Double -> Maybe Double
forall a. a -> Maybe a
Just (Double -> Maybe Double) -> Double -> Maybe Double
forall a b. (a -> b) -> a -> b
$ Double
2 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double
square Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
2) Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ (Double
n Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double
square (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
2) Double -> Double -> Double
forall a. Num a => a -> a -> a
* (Double
m Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
4))
| Bool
otherwise = Maybe Double
forall a. Maybe a
Nothing
instance D.Entropy FDistribution where
entropy :: FDistribution -> Double
entropy (F Double
n Double
m Double
_) =
let nHalf :: Double
nHalf = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
n
mHalf :: Double
mHalf = Double
0.5 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
m in
Double -> Double
forall a. Floating a => a -> a
log (Double
nDouble -> Double -> Double
forall a. Fractional a => a -> a -> a
/Double
m)
Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double -> Double -> Double
logBeta Double
nHalf Double
mHalf
Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
- Double
nHalf) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double
digamma Double
nHalf
Double -> Double -> Double
forall a. Num a => a -> a -> a
- (Double
1 Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
mHalf) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double
digamma Double
mHalf
Double -> Double -> Double
forall a. Num a => a -> a -> a
+ (Double
nHalf Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
mHalf) Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double -> Double
digamma (Double
nHalf Double -> Double -> Double
forall a. Num a => a -> a -> a
+ Double
mHalf)
instance D.MaybeEntropy FDistribution where
maybeEntropy :: FDistribution -> Maybe Double
maybeEntropy = Double -> Maybe Double
forall a. a -> Maybe a
Just (Double -> Maybe Double)
-> (FDistribution -> Double) -> FDistribution -> Maybe Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FDistribution -> Double
forall d. Entropy d => d -> Double
D.entropy
instance D.ContGen FDistribution where
genContVar :: FDistribution -> g -> m Double
genContVar = FDistribution -> g -> m Double
forall d g (m :: * -> *).
(ContDistr d, StatefulGen g m) =>
d -> g -> m Double
D.genContinuous