HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulestatistics-0.16.3.0Haskell2010

Statistics.Regression

Functions for regression analysis.

  • 4 values
valueolsRegress
  1. :: [Vector]

    Non-empty list of predictor vectors. Must all have the same length. These will become the columns of the matrix A solved by ols.

  2. -> Vector

    Responder vector. Must have the same length as the predictor vectors.

  3. -> (Vector, Double)
#

Perform an ordinary least-squares regression on a set of predictors, and calculate the goodness-of-fit of the regression.

The returned pair consists of:

  • A vector of regression coefficients. This vector has one more element than the list of predictors; the last element is the y-intercept value.

  • R², the coefficient of determination (see rSquare for details).

Example2 expressions
import qualified Data.Vector.Unboxed as VU:{ olsRegress [ VU.fromList [0,1,2,3]            ] (VU.fromList [1000, 1001, 1002, 1003]):}([1.0000000000000218,999.9999999999999],1.0)
valueols
  1. :: Matrix

    A has at least as many rows as columns.

  2. -> Vector

    b has the same length as columns in A.

  3. -> Vector
#

Compute the ordinary least-squares solution to overdetermined linear system Ax = b. In other words it finds

\operatorname{argmin}|Ax-b|^2 .

All columns of A must be linearly independent. It's not checked function will return nonsensical result if resulting linear system is poorly conditioned.

Example2 expressions
import qualified Data.Vector.Unboxed as VU:{ ols (fromColumns [ VU.fromList [0,1,2,3]                  , VU.fromList [1,1,1,1]                  ]) (VU.fromList [1000, 1001, 1002, 1003]):}[1.0000000000000218,999.9999999999999]
Example1 expression
:{ ols (fromColumns [ VU.fromList [0,1,2,3]                  , VU.fromList [4,2,1,1]                  , VU.fromList [1,1,1,1]                  ]) (VU.fromList [1000, 1001, 1002, 1003]):}[1.0000000000005393,4.2290644612446807e-13,999.9999999999983]
valuerSquare
  1. :: Matrix

    Predictors (regressors).

  2. -> Vector

    Responders.

  3. -> Vector

    Regression coefficients.

  4. -> Double
#

Compute R², the coefficient of determination that indicates goodness-of-fit of a regression.

This value will be 1 if the predictors fit perfectly, dropping to 0 if they have no explanatory power.