module Statistics.Test.Types (
Test(..)
, isSignificant
, TestResult(..)
, significant
, PositionTest(..)
) where
import Control.DeepSeq (NFData(..))
import Control.Monad (liftM3)
import Data.Aeson (FromJSON, ToJSON)
import Data.Binary (Binary (..))
import Data.Data (Typeable, Data)
import GHC.Generics
import Statistics.Types (PValue)
data TestResult = Significant
| NotSignificant
deriving (Eq,Ord,Show,Typeable,Data,Generic)
instance Binary TestResult where
get = do
sig <- get
if sig then return Significant else return NotSignificant
put = put . (== Significant)
instance FromJSON TestResult
instance ToJSON TestResult
instance NFData TestResult
data Test distr = Test
{ testSignificance :: !(PValue Double)
, testStatistics :: !Double
, testDistribution :: distr
}
deriving (Eq,Ord,Show,Typeable,Data,Generic,Functor)
instance (Binary d) => Binary (Test d) where
get = liftM3 Test get get get
put (Test sign stat distr) = put sign >> put stat >> put distr
instance (FromJSON d) => FromJSON (Test d)
instance (ToJSON d) => ToJSON (Test d)
instance (NFData d) => NFData (Test d) where
rnf (Test _ _ a) = rnf a
isSignificant :: PValue Double -> Test d -> TestResult
isSignificant p t
= significant $ p >= testSignificance t
data PositionTest
= SamplesDiffer
| AGreater
| BGreater
deriving (Eq,Ord,Show,Typeable,Data,Generic)
instance Binary PositionTest where
get = do
i <- get
case (i :: Int) of
0 -> return SamplesDiffer
1 -> return AGreater
2 -> return BGreater
_ -> fail "Invalid PositionTest"
put SamplesDiffer = put (0 :: Int)
put AGreater = put (1 :: Int)
put BGreater = put (2 :: Int)
instance FromJSON PositionTest
instance ToJSON PositionTest
instance NFData PositionTest
significant :: Bool -> TestResult
significant True = Significant
significant False = NotSignificant