Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- linear :: (Foldable' xs x, IsDoublePair x) => xs -> V2
- linearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V2, V2)
- quadratic :: (Foldable' xs x, IsDoublePair x) => xs -> V3
- quadraticWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V3)
- quadraticAndLinear :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V2)
- quadraticAndLinearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> ((V3, V2), (V3, V2))
- class Add a where
- class Eye a where
- eye :: a
- class Eye a => Mult a b c | a b -> c where
- mult :: a -> b -> c
- class Eye a => Det a where
- class Det a => Inv a where
- inv :: a -> a
- zerosLin :: V2 -> Double
- zerosQuad :: V3 -> Either (Complex Double, Complex Double) (Double, Double)
- optimaQuad :: V3 -> Double
- data V2 = V2 !Double !Double
- data M22 = M22 !Double !Double !Double !Double
- data V3 = V3 !Double !Double !Double
- data M33 = M33 !Double !Double !Double !Double !Double !Double !Double !Double !Double
- class Foldable' xs x | xs -> x where
- foldl' :: (b -> x -> b) -> b -> xs -> b
- class IsDoublePair dp where
Regressions
linear :: (Foldable' xs x, IsDoublePair x) => xs -> V2 Source #
Linear regression.
The type is
linear
:: [(Double
,Double
)] ->V2
but overloaded to work with boxed and unboxed Vector
s.
>>>
let input1 = [(0, 1), (1, 3), (2, 5)]
>>>
PP $ linear input1
V2 2.0000 1.00000
>>>
let input2 = [(0.1, 1.2), (1.3, 3.1), (1.9, 4.9), (3.0, 7.1), (4.1, 9.0)]
>>>
PP $ linear input2
V2 2.0063 0.88685
linearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V2, V2) Source #
Like linear
but also return parameters' standard errors.
To get confidence intervals you should multiply the errors
by quantile (studentT (n - 2)) ci'
from statistics
package
or similar.
For big n
using value 1 gives 68% interval and using value 2 gives 95% confidence interval.
See https://en.wikipedia.org/wiki/Student%27s_t-distribution#Table_of_selected_values
(quantile
calculates one-sided values, you need two-sided, thus adjust ci
value).
The first input is perfect fit:
>>>
PP $ linearWithErrors input1
(V2 2.0000 1.00000, V2 0.00000 0.00000)
The second input is quite good:
>>>
PP $ linearWithErrors input2
(V2 2.0063 0.88685, V2 0.09550 0.23826)
But the third input isn't so much, standard error of a slope argument is 20%.
>>>
let input3 = [(0, 2), (1, 3), (2, 6), (3, 11)]
>>>
PP $ linearWithErrors input3
(V2 3.0000 1.00000, V2 0.63246 1.1832)
Since: 0.1.1
quadratic :: (Foldable' xs x, IsDoublePair x) => xs -> V3 Source #
Quadratic regression.
The type is
quadratic
:: [(Double
,Double
)] ->V3
but overloaded to work with boxed and unboxed Vector
s.
>>>
let input1 = [(0, 1), (1, 3), (2, 5)]
>>>
quadratic input1
V3 0.0 2.0 1.0
>>>
let input2 = [(0.1, 1.2), (1.3, 3.1), (1.9, 4.9), (3.0, 7.1), (4.1, 9.0)]
>>>
PP $ quadratic input2
V3 (-0.00589) 2.0313 0.87155
>>>
let input3 = [(0, 2), (1, 3), (2, 6), (3, 11)]
>>>
PP $ quadratic input3
V3 1.00000 0.00000 2.0000
quadraticWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V3) Source #
Like quadratic
but also return parameters' standard errors.
>>>
PP $ quadraticWithErrors input2
(V3 (-0.00589) 2.0313 0.87155, V3 0.09281 0.41070 0.37841)
>>>
PP $ quadraticWithErrors input3
(V3 1.00000 0.00000 2.0000, V3 0.00000 0.00000 0.00000)
Since: 0.1.1
quadraticAndLinear :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V2) Source #
Do both linear and quadratic regression in one data scan.
>>>
PP $ quadraticAndLinear input2
(V3 (-0.00589) 2.0313 0.87155, V2 2.0063 0.88685)
quadraticAndLinearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> ((V3, V2), (V3, V2)) Source #
Like quadraticAndLinear
but also return parameters' standard errors
>>>
PP $ quadraticAndLinearWithErrors input2
((V3 (-0.00589) 2.0313 0.87155, V2 2.0063 0.88685), (V3 0.09281 0.41070 0.37841, V2 0.09550 0.23826))
Since: 0.1.1
Operations
Addition
Identity
class Eye a => Mult a b c | a b -> c where Source #
Multiplication of different things.
Zeros
zerosQuad :: V3 -> Either (Complex Double, Complex Double) (Double, Double) Source #
Solve quadratic equation.
>>>
zerosQuad (V3 2 0 (-1))
Right (-0.7071067811865476,0.7071067811865476)
>>>
zerosQuad (V3 2 0 1)
Left ((-0.0) :+ (-0.7071067811865476),(-0.0) :+ 0.7071067811865476)
Double root is not treated separately:
>>>
zerosQuad (V3 1 0 0)
Right (-0.0,0.0)
>>>
zerosQuad (V3 1 (-2) 1)
Right (1.0,1.0)
optimaQuad :: V3 -> Double Source #
Find an optima point.
>>>
optimaQuad (V3 1 (-2) 0)
1.0
compare to
>>>
zerosQuad (V3 1 (-2) 0)
Right (0.0,2.0)
Two dimensions
2d vector. Strict pair of Double
s.
Also used to represent linear polynomial: V2 a b
\(= a x + b\).
2×2 matrix.
Three dimensions
3d vector. Strict triple of Double
s.
Also used to represent quadratic polynomial: V3 a b c
\(= a x^2 + b x + c\).
3×3 matrix.
Auxiliary classes
class Foldable' xs x | xs -> x where Source #
Like Foldable
but with element in the class definition.
Instances
Foldable' [a] a Source # | |
Defined in Math.Regression.Simple | |
Unbox a => Foldable' (Vector a) a Source # | |
Defined in Math.Regression.Simple | |
Foldable' (Vector a) a Source # | |
Defined in Math.Regression.Simple |
class IsDoublePair dp where Source #
Class witnessing that dp
has a pair of Double
s.
Instances
IsDoublePair V2 Source # | |
(a ~ Double, b ~ Double) => IsDoublePair (a, b) Source # | |