diff --git a/statistics.cabal b/statistics.cabal index 6f12ab70..ce17fe7c 100644 --- a/statistics.cabal +++ b/statistics.cabal @@ -124,6 +124,7 @@ test-suite tests Tests.ApproxEq Tests.Correlation Tests.Distribution + Tests.Regression Tests.Function Tests.Helpers Tests.KDE diff --git a/tests/Tests/Regression.hs b/tests/Tests/Regression.hs new file mode 100644 index 00000000..d3981515 --- /dev/null +++ b/tests/Tests/Regression.hs @@ -0,0 +1,41 @@ +module Tests.Regression + ( tests ) where + +import Data.Vector.Unboxed (Vector) +import qualified Data.Vector.Unboxed as U +import Debug.Trace (trace) +import Statistics.Regression +import Test.Framework (Test, testGroup) +import Test.Framework.Providers.QuickCheck2 (testProperty) +import Test.QuickCheck + +data Predictor = Predictor [Vector Double] (Vector Double) + deriving Show + +instance Arbitrary Predictor where + arbitrary = do + -- we pick an arbitrary length N - this is the length the + -- predictor vectors and the responder vector will have + n <- arbitrary `suchThat` (>1) + + matrix <- listOf1 (vectorOf n $ elements [1,2,3]) + -- the matrix must have more rows than columns + `suchThat` (( Bool +testOLS (Predictor matrix responder) = + let (v,double) = olsRegress matrix responder in + let vlen = U.length v + mlen = length matrix in + if (vlen == mlen+1 && double >=0 && double <= 1) + then True + else trace (show ("ols", vlen,mlen,U.length (head matrix), double)) False diff --git a/tests/tests.hs b/tests/tests.hs index 128ec2ef..025c3ccb 100644 --- a/tests/tests.hs +++ b/tests/tests.hs @@ -1,11 +1,13 @@ -import Test.Framework (defaultMain) -import qualified Tests.Distribution as Distribution -import qualified Tests.Function as Function -import qualified Tests.KDE as KDE -import qualified Tests.Matrix as Matrix +import Test.Framework (defaultMain) +import qualified Tests.Correlation as Correlation +import qualified Tests.Distribution as Distribution +import qualified Tests.Function as Function +import qualified Tests.KDE as KDE +import qualified Tests.Matrix as Matrix import qualified Tests.NonParametric as NonParametric -import qualified Tests.Transform as Transform -import qualified Tests.Correlation as Correlation +import qualified Tests.Regression as Regression +import qualified Tests.Transform as Transform + main :: IO () main = defaultMain [ Distribution.tests @@ -15,4 +17,5 @@ main = defaultMain [ Distribution.tests , NonParametric.tests , Transform.tests , Correlation.tests + , Regression.tests ]