statistics-linreg 0.2.3 → 0.2.4
raw patch · 2 files changed
+35/−4 lines, 2 files
Files
Statistics/LinearRegression.hs view
@@ -5,9 +5,12 @@ linearRegression, linearRegressionRSqr, linearRegressionTLS,- -- * related functions+ -- * Related functions correl, covar,+ -- * Estimated errors and distribution parameters+ linearRegressionMSE,+ linearRegressionDistributions, -- * Robust linear regression robustFit, nonRandomRobustFit,@@ -39,6 +42,9 @@ import Data.List (minimumBy, sortBy) import Data.Maybe (fromMaybe) import qualified Statistics.Sample as S+import qualified Statistics.Distribution as D+import qualified Statistics.Distribution.Transform as T+import qualified Statistics.Distribution.StudentT as ST --- * Simple linear regression @@ -91,6 +97,28 @@ (alpha, beta, _) = linearRegressionRSqr xs ys {-# INLINE linearRegression #-} +-- | The error (or residual) mean square of a sample w.r.t. an estimated regression line.+-- This serves as an estimate for the variance of the sampled data.+-- Accepts the regression parameters (alpha,beta) and the sample vectors X and Y.+linearRegressionMSE :: (Double,Double) -> S.Sample -> S.Sample -> Double+linearRegressionMSE ab xs ys = (U.sum . U.map (linearRegressionError ab) . U.zip xs $ ys)/(n-2)+ where+ !n = fromIntegral $ U.length xs++-- | The estimated distributions of the regression parameters (alpha and beta) assuming normal, identical distributions of Y, the sampled data.+-- These can serve to get confidence intervals for the regression parameters.+-- Accepts the regression parameters (alpha,beta) and the sample vectors X and Y.+-- The distributions are StudnetT distributions centered at the estimated (alpha,beta) respectively, with parameter numbers n-2 (where n is the initial sample size) and with standard deviations that are extracted from the sampled data based on its MSE. See chapter 2 of reference [3] for details.+linearRegressionDistributions :: (Double,Double) -> S.Sample -> S.Sample -> (T.LinearTransform ST.StudentT,T.LinearTransform ST.StudentT)+linearRegressionDistributions (alpha,beta) xs ys = (ST.studentTUnstandardized (n-2) alpha va,ST.studentTUnstandardized (n-2) beta vb)+ where+ !n = fromIntegral $ U.length xs+ !mse = linearRegressionMSE (alpha,beta) xs ys+ !vb = mse/(xv)+ !mx = S.mean xs+ !va = mse*(1/n+mx^2/xv)+ !xv = U.sum . U.map (\x -> (x-mx)^2) $ xs+ -- | Total Least Squares (TLS) linear regression. -- Assumes x-axis values (and not just y-axis values) are random variables and that both variables have similar distributions. -- interface is the same as 'linearRegression'.@@ -291,4 +319,5 @@ -- * Two Dimensional Euclidean Regression (Stein) <http://www.dspcsp.com/pubs/euclreg.pdf> -- -- * Computing LTS Regression For Large Data Sets (Rousseeuw and Driessen) <http://agoras.ua.ac.be/abstract/Comlts99.htm>-+--+-- * Applied linear statistical models (Kutner et al.)
statistics-linreg.cabal view
@@ -1,8 +1,10 @@ Name: statistics-linreg-Version: 0.2.3+Version: 0.2.4 Synopsis: Linear regression between two samples, based on the 'statistics' package. Description: Provides functions to perform a linear regression between 2 samples, see the documentation of the linearRegression functions. This library is based on the 'statistics' package. .+ * 0.2.4: added distribution estimations for standard regression parameters.+ . * 0.2.3: added robust-fit support. . * 0.2.2: added the Total-Least-Squares version and made some refactoring to eliminate code duplication@@ -31,7 +33,7 @@ License-file: LICENSE Author: Alp Mestanogullari <alpmestan@gmail.com>, Uri Barenholz <uri.barenholz@weizmann.ac.il> Maintainer: Alp Mestanogullari <alpmestan@gmail.com>-Copyright: 2010-2012 Alp Mestanogullari+Copyright: 2010-2013 Alp Mestanogullari Stability: Experimental Category: Math, Statistics Build-type: Simple