Why is p value different in same hypothesis? [closed]


wilcox.test(weight ~ group, data = my_data, paired = TRUE)

wilcox.test(weight , group, data = my_data, paired = TRUE)



can anyone specify the difference to me with "," and "~" both are giving different outputs, whereas i use ggplot to see the data second one gives me the correct result that there is a difference in groups.

These are totally different commands. In the first one, the syntax tells the function to stratify the weight according to the group and compare the weights of your groups. I suspect that you want this. In the second one, the syntax tells the function to compare the weights to the group labels, which I suspect are coded as $$0$$ and $$1$$. Depending on what you're weighing, I would expect all of the weights to be much higher than $$1$$. Consequently, the distributions of weights and 0/1 group labels are totally different, and the test catches this.

EDT

You're doing a paired test, so to be a bit more detailed, the first syntax tells the function to do a test on something like weight[group == 1] - weight[group == 0], while the second tells the function to do a test on weight - group.

• I just want a hypothesis where i'm putting null where both are equal and second one is there is difference, i want to measure the difference between these to variables, so which one should i use?
– none
Jan 27, 2023 at 16:22
• Difference between which variables? @none
– Dave
Jan 27, 2023 at 16:36

If you are using a console like rstudio then you can use the command ?wilcox.test to get the manual of the function.

if both x and y are given and paired is TRUE, a Wilcoxon signed rank test of the null that the distribution ... of x - y (in the paired two sample case) is symmetric about mu is performed

That's probably not what you want, compare the variable weight and group. The formula form seems better, although it won't know how to pair the weights. It would be more ideal to construct two vectors manually.

• Happily enough, you don't need Rstudio to be able to use ?wilcox.text. The plain vanilla R console will do this quite as well. Jan 27, 2023 at 17:05