Evistral
Evistral

Reputation: 1

How do I sample and conduct a random permutation test for data with unequal list lengths in R?

I have an issue where I have 2 lists of unequal lengths, and I want to conduct a random permutation test of 5000 iterations on them to find out if the difference in means for both is significant.

dataset1v <- c(10, 10, 5, 10, 50, 2, 5, 50, 10, 40, 50, 20, 25, 20, 10, 10, 50, 10)
dataset2v <- c(50, 10, 20, 10, 40, 10, 20, 30, 10, 10, 80, 15)

All the tutorials on random permutation tests out there assume equal list lengths, and so they don't apply since a warning pops up when I run it with my lists. I've tried permutation.test.discrete among other options, but it's always the same issue: list length is unequal. Also, I would also like to resample each data into their original list lengths (18 and 12 each). I'm a beginner at coding for R, so I have spent hours upon hours trying to figure out how to solve this issue. Would appreciate some help and pointers in the right direction! Thanks!!

Upvotes: 0

Views: 227

Answers (1)

jay.sf
jay.sf

Reputation: 73562

You could use the twot.permutation of the DAAG package.

library("DAAG")
set.seed(42)
twot.permutation(dataset1v, dataset2v, nsim=5e3)
# [1] 0.605

It also includes a plotting functionality:

enter image description here


Data

dataset1v <- c(10, 10, 5, 10, 50, 2, 5, 50, 10, 40, 50, 20, 25, 20, 10, 10, 50, 10)
dataset2v <- c(50, 10, 20, 10, 40, 10, 20, 30, 10, 10, 80, 15)

Upvotes: 0

Related Questions