# Is it wrong to jitter before performing Wilcoxon test?

I wrote a script tests the data using the wilcox.test, but when I got the results, all the p-values where equal to 1. I read in some websites that you could use jitter before testing the data (to avoid ties as they said), I did this and now I have an acceptable result. Is it wrong to do this?

test<- function(column,datacol){
library(ggplot2)
uni=unique(c(t$V9)) for (xp in uni) { for(yp in uni) { testx <- subset(t, V9==xp) testy <- subset(t, V9==yp) zz <- wilcox.test(testx[[datacol]],jitter(testy[[datacol]])) p.value <- zz$p.value
}
}
}


This is the output of dput(head(t))

structure(list(V1 = c(0.268912,
0.314681, 0.347078, 0.286945,
0.39562, 0.282182), V2 = c(0.158921, 0.210526, 0.262024, 0.322006,
0.133417, 0.283025), V3 = c(0.214082, 0.166895, 0.132547, 0.147361,
0.09174, 0.169093), V4 = c(0.358085, 0.307898, 0.258352, 0.243688,
0.379224, 0.2657), V5= c(-0.142223, 0.010895, 0.14655,
0.08152, 0.02116, 0.030083), V6 = c(0.096408, -0.091896,

-0.331229, -0.446603, -0.088493, -0.262037), V7 = c(1.680946,
1.649559, 1.534401, 1.130529, 3.441356, 1.211815), V8 = c("NC_000834",  "NC_000844",
"NC_000845", "NC_000846", "NC_000857",
"NC_000860" ), V9 = c("Chordata",
"Arthropoda", "Chordata", "Chordata",
"Arthropoda", "Chordata"), V10 =
c("???:???", "Diplostraca",
"???:???", "Rheiformes", "Diptera",
"Salmoniformes"), V11 = c("???:???",
"Branchiopoda", "Mammalia", "Aves",
"Insecta", "Actinopterygii" )), .Names
= c("V1", "V2", "V3", "V4", "V5", "V6",  "V7",
"V8", "V9", "V10",
"V11"), row.names = c(NA,  6L),
class = "data.frame")


The data is very large, and that's the thread I started and they told me it might be wrong to do this

Note This question comes from tex.SE: generating PDFcontain R output inside latex table

• You don't tell us what your data is, but I'd be very suspicious of any procedure that adds random noise to data and then runs a statistical test on it. In addition, are you sure your code does what you think it does? My reading is that despite your loop, it will return a single p.value - that of x=y={lastvaluof}(uni) – Andrie Apr 5 '11 at 15:12
• @Andrie: thanks for your help, but that's not the complete code, that's a part of the function that calculate the wilcox test , and the code producing different values of p-value for each (xp,yp) ,that's a link of a part of my data , you can view it and check if i can do this, thanks in advance . mediafire.com/?mnj26kp4bv5lcr5 – weblover Apr 5 '11 at 15:29
• I would be very suspicious of links to data that require redirecting to other links, especially when R provides the very useful dput()` function that eliminates any need for doing that. Please provide a reproducible example to receive assistance. – Chase Apr 5 '11 at 15:34
• cross posted: stackoverflow.com/questions/5554037/… – Chase Apr 5 '11 at 15:54
• @weblover When I suggested (on tex.SE) to ask your stats question here, I wasn't aware you already asked on SO. Please, delete one of your two posts (probably on SO, since this is a stats question). – chl Apr 5 '11 at 16:15

The first suggestion there is to repeat the test a large of number of times with different jittering and then combine the p-values to get an overall p-value, either by taking an average or a maximum. They also suggest that a straightforward permutation test could be used instead (of the two, that's what I'd prefer). See the question Which permutation test implementation in R to use instead of t-tests (paired and non-paired)? for some examples of permutation tests.

Elsewhere in that thread, Greg Snow writes: Adding random noise to data in order to avoid a warning is like removing the batteries from a smoke detector to silence it rather than investigating the what is causing the alarm to go off. (See http://tolstoy.newcastle.edu.au/R/e8/help/09/12/9195.html )

• thanks for your reply , but i did not got the point , what should i do now ? change the test , or adjust the data based on something , and what's this something??? – weblover Apr 5 '11 at 21:15
• I'll summarize the page I linked to. – Aaron left Stack Overflow Apr 6 '11 at 14:31

(disclaimer: I didn't check the code, my answer is just based on your description)

I have the feeling that what you want to do is a really bad idea. Wilcoxon is a resampling (or randomization) test for ranks. That is, it takes the rank of the values and compares these ranks to all possible permutations of the ranks (see e.g., here).

So, as you realized, ties are pretty bad as you don't get ranks out of them. However, adding random noise (jitter) to your data will transform all ranks, so that they have random ranks! That is, it distorts your data severely.

Therefore: It is wrong to do so.

• thnx for you answer , but what should i do in this case ?? – weblover Apr 5 '11 at 21:14

You've asked several people what you should do now. In my view, what you should do now is accept that the proper p-value here is 1.000. Your groups don't differ.

• hello , is it rational to accept this ?? because all groups and subgroups when compared together , gives the same p-value , that's not logical because in each case i'm testing 1 variable e.g : test("Ph",V1) , soo p-value should not be the same for all . any ideas ?? – weblover Apr 6 '11 at 8:01
• Sure, it could be rational. A p-value of 1 means that the two groups are as close to the same as possible. If you've got almost all ties, this could be true. – Aaron left Stack Overflow Apr 6 '11 at 14:27
• @Aaron @Web These data (V1 through V7) are not tied. An error must have been made somewhere in obtaining p-values of 1. I get a lot of p-values of 0.036 when comparing them with the Wilcoxon signed-rank test. – whuber Apr 7 '11 at 5:41
• The OP only posted the first few rows of the data; apparently there must be ties further on, though that does seem unlikely as the data goes to six decimal places. So yes, it does seem that there might be an error in the analysis, though not exactly the one you point out. – Aaron left Stack Overflow Apr 7 '11 at 12:00