Search code examples
haskellstatisticst-test

Why data constructor is not in scope here


I am trying to do Student T-test as provided here:

import Data.Vector as V
import Statistics.Test.StudentT
sampleA = V.fromList [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = V.fromList [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]
main = print $ StudentT sampleA sampleB SamplesDiffer

However, I am getting following error:

rnunttest.hs:8:16: error:
    Data constructor not in scope:
      StudentT :: Vector Double -> Vector Double -> PositionTest -> a0

Where is the problem and how can it be solved? Thanks for your help.


Solution

  • You made two mistakes here:

    1. the function is studenTTest, not StudentT, that is the name of the type constructor; and
    2. the constructor takes a PositionTest foollowed by two vectors.
    import Data.Vector as V
    import Statistics.Test.StudentT
    
    sampleA = V.fromList [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
    sampleB = V.fromList [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]
    
    main = print (studentTTest SamplesDiffer sampleA sampleB)

    For the given sample data, this gives us:

    Prelude V Statistics.Test.StudentT> main
    Just (Test {testSignificance = mkPValue 1.351738152442984e-2, testStatistics = -2.8243130467507513, testDistribution = studentT 14.0})