简体   繁体   English

如何解开具有2个值的向量

[英]How to unbox vector with 2 values

I am trying to do wilcoxonMatchedPairTest as given here : 我试图给出做wilcoxonMatchedPairTest 这里

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. 谢谢你的帮助。

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: 您需要使用fromList :: Unbox a => [a] -> Vector aData.Vector.UnboxedfromList :: Unbox a => [a] -> Vector a 2元组的列表转换为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 Vector s, you can use zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b) to zip two Vector s to a Vector of items: 或者如果您有两个Vector ,则可以使用zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b)将两个Vector zip到项目的Vector

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 = ()}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM