How to unbox vector with 2 values

77 views Asked by At

I am trying to do wilcoxonMatchedPairTest as given here:

import Data.Vector as V
import Statistics.Test.WilcoxonT

sampleA = [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

However, I am getting following error:

rnwilcox.hs:10:50: error:
    • Couldn't match expected type ‘Data.Vector.Unboxed.Base.Vector
                                      (a0, a0)’
                  with actual type ‘[(Double, Double)]’
    • In the second argument of ‘wilcoxonMatchedPairTest’, namely
        ‘(Prelude.zip sampleA sampleB)’
      In the first argument of ‘print’, namely
        ‘(wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))’
      In a stmt of a 'do' block:
        print
          (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

Apparently, I need to unbox the vector here. I tried using # as follows:

(# Prelude.zip sampleA sampleB #)

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

1

There are 1 answers

0
willeM_ Van Onsem On BEST ANSWER

You need to convert the list of 2-tuples to a Vector with fromList :: Unbox a => [a] -> Vector a here from the Data.Vector.Unboxed package to create such a vector:

import Data.Vector.Unboxed as VU
import Statistics.Test.WilcoxonT

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (VU.fromList (Prelude.zip sampleA sampleB)))

or if you have two Vectors, you can use zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b) to zip two Vectors to a Vector of items:

import Data.Vector.Unboxed as VU
import Statistics.Test.WilcoxonT

sampleA = VU.fromList [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = VU.fromList [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (VU.zip sampleA sampleB))

For the given sample data, this gives us:

Prelude VU Statistics.Test.WilcoxonT> main

Result of wilcoxonMatchedPairTest: 
Test {testSignificance = mkPValue 1.0, testStatistics = 36.0, testDistribution = ()}