-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple linear and quadratic regression -- -- A simple package with a module for -- -- -- -- All specialized to Double. @package regression-simple @version 0.1.1 module Math.Regression.Simple -- | Linear regression. -- -- The type is -- --
--   linear :: [(Double, Double)] -> V2
--   
-- -- but overloaded to work with boxed and unboxed Vectors. -- --
--   >>> 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
--   
linear :: (Foldable' xs x, IsDoublePair x) => xs -> V2 -- | 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)
--   
linearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V2, V2) -- | Quadratic regression. -- -- The type is -- --
--   quadratic :: [(Double, Double)] -> V3
--   
-- -- but overloaded to work with boxed and unboxed Vectors. -- --
--   >>> 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
--   
quadratic :: (Foldable' xs x, IsDoublePair x) => xs -> V3 -- | 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)
--   
quadraticWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V3) -- | 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)
--   
quadraticAndLinear :: (Foldable' xs x, IsDoublePair x) => xs -> (V3, V2) -- | 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))
--   
quadraticAndLinearWithErrors :: (Foldable' xs x, IsDoublePair x) => xs -> ((V3, V2), (V3, V2)) -- | Addition class Add a zero :: Add a => a add :: Add a => a -> a -> a infixl 6 `add` -- | Identity class Eye a eye :: Eye a => a -- | Multiplication of different things. class Eye a => Mult a b c | a b -> c mult :: Mult a b c => a -> b -> c infixl 7 `mult` -- | Determinant class Eye a => Det a det :: Det a => a -> Double -- | Inverse class Det a => Inv a inv :: Inv a => a -> a -- | Solve linear equation. -- --
--   >>> zerosLin (V2 1 2)
--   -2.0
--   
zerosLin :: V2 -> Double -- | 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)
--   
zerosQuad :: V3 -> Either (Complex Double, Complex Double) (Double, Double) -- | Find an optima point. -- --
--   >>> optimaQuad (V3 1 (-2) 0)
--   1.0
--   
-- -- compare to -- --
--   >>> zerosQuad (V3 1 (-2) 0)
--   Right (0.0,2.0)
--   
optimaQuad :: V3 -> Double -- | 2d vector. Strict pair of Doubles. -- -- Also used to represent linear polynomial: V2 a b -- <math>. data V2 V2 :: !Double -> !Double -> V2 -- | 2×2 matrix. data M22 M22 :: !Double -> !Double -> !Double -> !Double -> M22 -- | 3d vector. Strict triple of Doubles. -- -- Also used to represent quadratic polynomial: V3 a b c -- <math>. data V3 V3 :: !Double -> !Double -> !Double -> V3 -- | 3×3 matrix. data M33 M33 :: !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> M33 -- | Like Foldable but with element in the class definition. class Foldable' xs x | xs -> x foldl' :: Foldable' xs x => (b -> x -> b) -> b -> xs -> b -- | Class witnessing that dp has a pair of Doubles. class IsDoublePair dp withDP :: IsDoublePair dp => dp -> (Double -> Double -> r) -> r makeDP :: IsDoublePair dp => Double -> Double -> dp instance GHC.Show.Show Math.Regression.Simple.V2 instance GHC.Classes.Eq Math.Regression.Simple.V2 instance GHC.Show.Show Math.Regression.Simple.M22 instance GHC.Classes.Eq Math.Regression.Simple.M22 instance GHC.Show.Show Math.Regression.Simple.V3 instance GHC.Classes.Eq Math.Regression.Simple.V3 instance GHC.Show.Show Math.Regression.Simple.M33 instance GHC.Classes.Eq Math.Regression.Simple.M33 instance Math.Regression.Simple.IsDoublePair Math.Regression.Simple.V2 instance (a GHC.Types.~ GHC.Types.Double, b GHC.Types.~ GHC.Types.Double) => Math.Regression.Simple.IsDoublePair (a, b) instance Math.Regression.Simple.Foldable' [a] a instance Math.Regression.Simple.Foldable' (Data.Vector.Vector a) a instance Data.Vector.Unboxed.Base.Unbox a => Math.Regression.Simple.Foldable' (Data.Vector.Unboxed.Base.Vector a) a instance Math.Regression.Simple.Add Math.Regression.Simple.M33 instance Math.Regression.Simple.Eye Math.Regression.Simple.M33 instance Math.Regression.Simple.Det Math.Regression.Simple.M33 instance Math.Regression.Simple.Inv Math.Regression.Simple.M33 instance Math.Regression.Simple.Mult GHC.Types.Double Math.Regression.Simple.M33 Math.Regression.Simple.M33 instance Math.Regression.Simple.Mult Math.Regression.Simple.M33 Math.Regression.Simple.V3 Math.Regression.Simple.V3 instance Math.Regression.Simple.Add Math.Regression.Simple.V3 instance Math.Regression.Simple.Mult GHC.Types.Double Math.Regression.Simple.V3 Math.Regression.Simple.V3 instance Math.Regression.Simple.Add Math.Regression.Simple.M22 instance Math.Regression.Simple.Eye Math.Regression.Simple.M22 instance Math.Regression.Simple.Det Math.Regression.Simple.M22 instance Math.Regression.Simple.Inv Math.Regression.Simple.M22 instance Math.Regression.Simple.Mult GHC.Types.Double Math.Regression.Simple.M22 Math.Regression.Simple.M22 instance Math.Regression.Simple.Mult Math.Regression.Simple.M22 Math.Regression.Simple.V2 Math.Regression.Simple.V2 instance Math.Regression.Simple.Mult Math.Regression.Simple.M22 Math.Regression.Simple.M22 Math.Regression.Simple.M22 instance Math.Regression.Simple.Add Math.Regression.Simple.V2 instance Math.Regression.Simple.Mult GHC.Types.Double Math.Regression.Simple.V2 Math.Regression.Simple.V2 instance Math.Regression.Simple.Inv GHC.Types.Double instance Math.Regression.Simple.Det GHC.Types.Double instance Math.Regression.Simple.Eye GHC.Types.Double instance Math.Regression.Simple.Add GHC.Types.Double