2
$\begingroup$

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.

$\endgroup$
0

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
2
  • $\begingroup$ 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? $\endgroup$
    – none
    Jan 27, 2023 at 16:22
  • $\begingroup$ Difference between which variables? @none $\endgroup$
    – Dave
    Jan 27, 2023 at 16:36
0
$\begingroup$

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.

$\endgroup$
1
  • 1
    $\begingroup$ 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. $\endgroup$ Jan 27, 2023 at 17:05

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