Sunday, 15 February 2015

r - Comparing distribution of two vectors -


I have 5 different vectors and then a vector I want to compare them to. I need to get the most common vectors from 5 different parts.

The vector is quite long, so I will show it a little bit:

  To compare with # vectors: v1 & lt; - c (0.2500, 0.4375, 0.1250, 0.3125, 0.0000, 0.5625, 0.1250, 0.1875, 0.1875, 0.1875, 0.1875) # one of the vectors v2 and lt; - c (2, 1, 0, 1, 1, 1, 1, 0, 2, 1, 2) To compare # vectors: v3 & lt; -c (5, 0, 3, 1, 1, 2, 1, 2, 0, 1, 2)  

What I need to do in practice is given by those vectors A statistical test to compare the distribution of the histogram and tell me which one is closest I tried to use the ks.test , but there was a problem with the duplicate value in the vector and returned P-value was like 0.0000000000001. Any idea how to do it (except blind)?

It is not clear to me that what you want to do to all, / Em> Why the exam is needed, which is the closest I just compute the histogram and compare their distance.

Generate Data:

  v1 < -c (0.2500, 0.4375, 0.1250, 0.3125, 0.0000, 0.5625, 0.1250, 0.1875, 0.1875, 0.1875, 0.1875) v2 & lt; -c (2, 1, 0, 1, 1, 1, 1, 0, 2, 1, 2) * 0.1 v3 & lt; -c (5, 0, 3, 1, 1, 2, 1, 2, 0, 1, 2) * 0.1  

Note that I changed vectors 2 and 3 a bit , So that their distribution actually overlaps the comparison vector

  vList & lt; - List (v1, v2, v3) brkvec & lt; - seq (0,0.7, by 0.1) hList & lt; - Lapply (vList, function X) Hist (X, plot = FALSE, breaks = brkvec) $ calculation)  

This is slightly disabled because it all and then throws most of them ...

  dmat < - dist (do.call (rbind, hList) dvec & lt; - as.matrix (dmat) [- 1.11] ## 2 3 ## 7.874008 6.000000  

The second option ignored the warning from ks.test () Nly does not calculate distance estimates, affects hypothesis)

  ks.dist & lt; - sapply (vList [-1], function (x) suppressWarnings (ks.test (v1, x) $ stats)) ks.dist ## DD ## 0.6363636 0.4545455  

Results matching (I.e. v3 is v2 closer to v2)


No comments:

Post a Comment