packages feed

statistics-linreg (empty) → 0.1

raw patch · 4 files changed

+118/−0 lines, 4 filesdep +basedep +statisticsdep +vectorsetup-changed

Dependencies added: base, statistics, vector

Files

+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2010 Alp Mestanogullari++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ Statistics/LinearRegression.hs view
@@ -0,0 +1,33 @@+module Statistics.LinearRegression (linearRegression) where++import qualified Data.Vector.Unboxed as U+import Statistics.Sample++--- * Simple linear regression++-- | Covariance+covar :: Sample -> Sample -> (Double, Double, Double)+covar xs ys = (U.sum (U.zipWith (*) (U.map f1 xs) (U.map f2 ys)) / (n-1), m1, m2)+    where+          n = fromIntegral $ U.length xs+          m1 = mean xs+          m2 = mean ys+          f1 = \x -> (x - m1)+          f2 = \x -> (x - m2)++-- | Pearson's product-moment correlation coefficient+correl :: Sample -> Sample -> (Double, Double, Double, Double, Double)+correl xs ys = let (c, m1, m2) = covar xs ys+                   sx = stdDev xs+                   sy = stdDev ys+               in (c / (stdDev xs * stdDev ys), m1, m2, sx, sy)++-- | Simple linear regression between 2 samples.+--   Takes two vectors Y={yi} and X={xi} and returns+--   (alpha, beta) such that Y = alpha + betaX+linearRegression :: Sample -> Sample -> (Double, Double)+linearRegression xs ys = (alpha, beta)+    where +          (r, m1, m2, sx, sy) = correl xs ys+          beta                = r * sy / sx+          alpha               = m2 - beta * m1
+ statistics-linreg.cabal view
@@ -0,0 +1,63 @@+-- linreg.cabal auto-generated by cabal init. For additional options,+-- see+-- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.+-- The name of the package.+Name:                statistics-linreg++-- The package version. See the Haskell package versioning policy+-- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for+-- standards guiding when and how versions should be incremented.+Version:             0.1++-- A short (one-line) description of the package.+Synopsis:            Linear regression between two samples, based on the 'statistics' package++-- A longer description of the package.+Description:         Provides a function to perform a linear regression between 2 samples, see the documentation of the linearRegression function. This library is based on the 'statistics' package.++-- URL for the project homepage or repository.+Homepage:            http://code.haskell.org/~alpmestan/linreg/+-- The license under which the package is released.+License:             MIT++-- The file containing the license text.+License-file:        LICENSE++-- The package author(s).+Author:              Alp Mestanogullari <alpmestan@gmail.com>++-- An email address to which users can send suggestions, bug reports,+-- and patches.+Maintainer:          Alp Mestanogullari <alpmestan@gmail.com>++-- A copyright notice.+Copyright:           2010 Alp Mestanogullari++-- Stability of the pakcage (experimental, provisional, stable...)+Stability:           Experimental++Category:            Math, Statistics++Build-type:          Simple++-- Extra files to be distributed with the package, such as examples or+-- a README.+-- Extra-source-files:  ++-- Constraint on the version of Cabal needed to build this package.+Cabal-version:       >=1.4+++Library+  -- Modules exported by the library.+  Exposed-modules: Statistics.LinearRegression+  +  -- Packages needed in order to build this package.+  Build-depends: statistics >= 0.5, vector >= 0.5, base >= 4 && < 5+  +  -- Modules not exported by this package.+  -- Other-modules:       +  +  -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.+  -- Build-tools:         +