# Wilcox test in R

I am trying to perform Wilcox test in R. For the simplicity I will use artificial data in example below:

# Weight before experiment
before <-c(200.1, 190.9, 192.7, 213, 241.4, 196.9, 172.2, 185.5, 205.2, 193.7)

# Weight after experiment
after <-c(392.9, 393.2, 345.1, 393, 434, 427.9, 422, 383.9, 392.3, 352.2)

# Create a data frame
my_data <- data.frame(
group = rep(c("before", "after"), each = 10),
weight = c(before,  after)
)


So next step is performing Wilcox test. I want to test test Ho-hypothesis which mean data before and after experiment have same median, or alternative Ha: Sample after experiment have big value than sample before experiment.

In order to do this I perform this test below :

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

#Wilcoxon signed rank test

#data:  weight by group
#V = 55, p-value = 1
#alternative hypothesis: true location shift is less than 0


So can anybody help me with interpretation of this results ? First does my hypothesis is good and second what will be explanation because value of P is exactly 1 ?

In your example, everyone gained weight and you tested the hypothesis that everyone lost weight (alternative = "less"), so it VERY VERY UNLIKELY that the participants lost weight, so $$p=1$$. Try instead "greater" or "two-sided".

> wilcox.test(weight ~ group, data = my_data, paired = TRUE,
+             alternative = "greater")

Wilcoxon signed rank exact test

data:  weight by group
V = 55, p-value = 0.0009766
alternative hypothesis: true location shift is greater than 0


Now, you have a significant result, $$p < .001$$, so you can reject the null hypothesis : it is likely that participants gained weight.