{-# LANGUAGE DeriveDataTypeable, PatternGuards #-}moduleData.Pass.L.Estimator(Estimator(..),Estimate(..),estimateBy)whereimportData.RatioimportData.BinaryimportData.DataimportqualifiedData.IntMapasIMimportData.IntMap(IntMap)importData.Pass.Util(clamp)importData.HashableimportData.Pass.Util.Beta(Beta(Beta))importqualifiedData.Pass.Util.BetaasBeta-- | Techniques used to smooth the nearest values when calculating quantile functions. R2 is used by default, and the numbering convention follows the -- use in the R programming language, as far as it goes.dataEstimator=R1-- ^ Inverse of the empirical distribution function|R2-- ^ .. with averaging at discontinuities (default)|R3-- ^ The observation numbered closest to Np. NB: does not yield a proper median|R4-- ^ Linear interpolation of the empirical distribution function. NB: does not yield a proper median.|R5-- ^ .. with knots midway through the steps as used in hydrology. This is the simplest continuous estimator that yields a correct median|R6-- ^ Linear interpolation of the expectations of the order statistics for the uniform distribution on [0,1]|R7-- ^ Linear interpolation of the modes for the order statistics for the uniform distribution on [0,1]|R8-- ^ Linear interpolation of the approximate medans for order statistics.|R9-- ^ The resulting quantile estimates are approximately unbiased for the expected order statistics if x is normally distributed.|R10-- ^ When rounding h, this yields the order statistic with the least expected square deviation relative to p.|HD-- ^ The Harrell-Davis quantile estimator based on bootstrapped order statisticsderiving(Eq,Ord,Enum,Bounded,Data,Typeable,Show,Read)instanceBinaryEstimatorwherepute=put(fromIntegral(fromEnume)::Word8)get=doi<-get::GetWord8return$toEnum(fromIntegrali)instanceHashableEstimatorwherehashWithSaltne=n`hashWithSalt`fromEnumedataEstimater=Estimate{-# UNPACK #-}!Rational(IntMapr)derivingShowcontinuousEstimator::Fractionalr=>(Rational->(Rational,Rational))->(Rational->Rational->Rational)->Rational->Int->EstimatercontinuousEstimatorbdsfpn=Estimateh$ifp<lothenIM.singleton01elseifp>=hithenIM.singleton(n-1)1elsecaseproperFractionhof(w,frac)|frac'<-fromRationalfrac->IM.fromList[(w-1,frac'),(w,1-frac')]wherer=fromIntegralnh=fpr(lo,hi)=bdsrestimateBy::Fractionalr=>Estimator->Rational->Int->EstimaterestimateByHD=\qn->Estimate(1%2)$letn'=fromIntegralnnp1=n'+1q'=fromRationalqd=Beta(q'*np1)(np1*(1-q'))inifq==0thenIM.singleton01elseifq==1thenIM.singleton(n-1)1elseIM.fromListWith(+)[(i,realToFrac$Beta.cumulatived((fromIntegrali+1)/n')-Beta.cumulatived(fromIntegrali/n'))|i<-[0..n-1]]estimateByR1=\pn->letnp=fromIntegraln*pinEstimate(np+1%2)$IM.singleton(clampn(ceilingnp-1))1estimateByR2=\pn->letnp=fromIntegraln*pinEstimate(np+1%2)$ifp==0thenIM.singleton01elseifp==1thenIM.singleton(n-1)1elseIM.fromListWith(+)[(clampn(ceilingnp-1),0.5),(clampn(floornp),0.5)]estimateByR3=\pn->letnp=fromIntegraln*pinEstimatenp$IM.singleton(clampn(roundnp-1))1estimateByR4=continuousEstimator(\n->(recipn,1))(*)estimateByR5=continuousEstimator(\n->lettn=2*nin(reciptn,(tn-1)/tn))$\pn->p*n+0.5estimateByR6=continuousEstimator(\n->(recip(n+1),n/(n+1)))$\pn->p*(n+1)estimateByR7=continuousEstimator(\_->(0,1))$\pn->p*(n-1)+1estimateByR8=continuousEstimator(\n->(2/3/(n+1/3),(n-1/3)/(n+1/3)))$\pn->p*(n+1/3)+1/3estimateByR9=continuousEstimator(\n->(0.625/(n+0.25),(n-0.375)/(n+0.25)))$\pn->p*(n+0.25)+0.375estimateByR10=continuousEstimator(\n->(1.5/(n+2),(n+0.5)/(n+2)))$\pn->p*(n+2)-0.5