0
$\begingroup$

I am running a wilcoxsign_test from the coin-package and I get different results depending on whether I split my data or not.

My data is a data.frame with 3 columns: "Proband", "Treatment", "Mdev". Treatment is either "user" or "drive" and Mdev is the value that the probands reached in either treatment. So the data is in long form.

Proband | Treatment | Mdev
1         user        0.5
1         drive       0.3
2         user        0.6
2         drive       0.4
...

I don't know if I didn't understand the function correctly, or what the issue is. My feeling tells me, that the first one is correct, because it knows which Probands belong together?

wilcoxsign_test(Mdev ~ Treatment | Proband, df)
#Z = -2.0333, p-value = 0.04202

baseData <- subset(df,Treatment=="user")
treatData <- subset(df,Treatment=="drive")
wilcoxsign_test(baseData$Mdev ~ treatData$Mdev)
#Z = -3.5974, p-value = 0.0003214

wilcox.test(baseData$Mdev, treatData$Mdev, paired=T)
#V = 219, p-value = 6.676e-05

This is my data:

    structure(list(Proband = structure(c(8L, 12L, 11L, 18L, 1L, 7L, 
5L, 13L, 12L, 11L, 9L, 21L, 7L, 20L, 6L, 16L, 16L, 14L, 4L, 17L, 
13L, 14L, 1L, 9L, 4L, 8L, 15L, 10L, 2L, 20L, 5L, 2L, 6L, 17L, 
10L, 19L, 15L, 18L, 3L, 3L, 21L, 19L), .Label = c("4", "5", "9", 
"10", "11", "13", "14", "15", "16", "17", "18", "19", "22", "25", 
"26", "27", "28", "29", "30", "31", "32"), class = "factor"), 
    Treatment = structure(c(2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 
    2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 
    1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
    1L, 2L, 2L), .Label = c("drive", "user"), class = "factor"), 
    Mdev = c(0.77774, 0.70899, 0.67463, 0.63176, 0.58867, 0.57463, 
    0.57292, 0.57211, 0.56916, 0.56678, 0.56117, 0.55627, 0.53442, 
    0.53248, 0.53046, 0.51774, 0.48093, 0.47656, 0.47519, 0.47036, 
    0.46646, 0.46587, 0.4637, 0.44291, 0.44087, 0.42865, 0.42602, 
    0.40904, 0.40524, 0.40499, 0.39791, 0.35671, 0.3315, 0.32965, 
    0.31296, 0.29784, 0.29521, 0.28068, 0.27107, 0.22477, 0.21352, 
    0.20689)), row.names = c(NA, -42L), class = c("tbl_df", "tbl", 
"data.frame"))

(Crosspost from stackoverflow)

$\endgroup$
1
$\begingroup$

If you sort your data first, you will get commensurate results from all three function calls.

df=    structure(list(Proband = structure(c(8L, 12L, 11L, 18L, 1L, 7L, 
5L, 13L, 12L, 11L, 9L, 21L, 7L, 20L, 6L, 16L, 16L, 14L, 4L, 17L, 
13L, 14L, 1L, 9L, 4L, 8L, 15L, 10L, 2L, 20L, 5L, 2L, 6L, 17L, 
10L, 19L, 15L, 18L, 3L, 3L, 21L, 19L), .Label = c("4", "5", "9", 
"10", "11", "13", "14", "15", "16", "17", "18", "19", "22", "25", 
"26", "27", "28", "29", "30", "31", "32"), class = "factor"), 
    Treatment = structure(c(2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 1L, 
    2L, 1L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 
    1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
    1L, 2L, 2L), .Label = c("drive", "user"), class = "factor"), 
    Mdev = c(0.77774, 0.70899, 0.67463, 0.63176, 0.58867, 0.57463, 
    0.57292, 0.57211, 0.56916, 0.56678, 0.56117, 0.55627, 0.53442, 
    0.53248, 0.53046, 0.51774, 0.48093, 0.47656, 0.47519, 0.47036, 
    0.46646, 0.46587, 0.4637, 0.44291, 0.44087, 0.42865, 0.42602, 
    0.40904, 0.40524, 0.40499, 0.39791, 0.35671, 0.3315, 0.32965, 
    0.31296, 0.29784, 0.29521, 0.28068, 0.27107, 0.22477, 0.21352, 
    0.20689)), row.names = c(NA, -42L), class = c("tbl_df", "tbl", 
"data.frame"))

library(coin)

Sorted = df[order(as.numeric(df$Proband), as.numeric(df$Treatment)),] 

baseData <- subset(Sorted,Treatment=="user")
treatData <- subset(Sorted,Treatment=="drive")

hist(baseData$Mdev - treatData$Mdev, col="darkgray")

wilcoxsign_test(Mdev ~ Treatment | Proband, df)

   ### data:  y by x (pos, neg) 
   ### stratified by block
   ### Z = -2.0333, p-value = 0.04202
   ### alternative hypothesis: true mu is not equal to 0

wilcoxsign_test(baseData$Mdev ~ treatData$Mdev)

   ### data:  y by x (pos, neg) 
   ###   stratified by block
   ### Z = 2.0333, p-value = 0.04202
   ### alternative hypothesis: true mu is not equal to 0

wilcox.test(baseData$Mdev, treatData$Mdev, paired=T)

   ### data:  baseData$Mdev and treatData$Mdev
   ### V = 174, p-value = 0.04208
   ### alternative hypothesis: true location shift is not equal to 0
$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.