I want to run Wilcoxon test to compare 3 test groups (B, C and D) against the control group (A)
The data are organized in the following format:
Group CustomerID Value
A 23483 61
A 23484 54
A 23485 57
A 23486 59
A 23487 69
A 23488 69
B 23489 57
B 23490 53
B 23491 68
B 23492 59
B 23493 57
C 23494 58
C 23495 70
C 23496 69
C 23497 62
C 23498 53
D 23499 65
D 23500 62
D 23501 60
D 23502 62
D 23503 63
D 23504 68
So far I've written the code below
#Seperate Control Data
DataControl<- Data%>%
select(Group,Value)%>%
filter(Group =="A")
#Filter data
Data%>%
filter(Group!="A")%>%
select(Group,Value)%>%
group_by(Group)
summarise(p_value = wilcox.test(DataControl$Value,exact =FALSE)$p.value)
but I am getting the following errors
Error in summarise_(.data, .dots = compat_as_lazy_dots(...)) :
argument ".data" is missing, with no default
The desired output shall be
Group P-value
B 0.04
C 0.10
D 0.01
There's a built-in pairwise function; I'd start there. Then just tidy it up and pick the pieces you need.
Note that my code (and yours too) doesn't correct for multiple comparisons. You should think about if that's appropriate here.
foo <- pairwise.wilcox.test(Data$Value, Data$Group, p.adjust.method="none")
foo
## Pairwise comparisons using Wilcoxon rank sum test
## data: Data$Value and Data$Group
## A B C
## B 0.355 - -
## C 0.782 0.344 -
## D 0.470 0.098 0.927
##
## P value adjustment method: none
library(tidyverse)
broom::tidy(foo) %>% filter(group2=="A")
## # A tibble: 3 x 3
## group1 group2 p.value
## <chr> <chr> <dbl>
## 1 B A 0.355
## 2 C A 0.782
## 3 D A 0.470
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With