Skip to main content
fixed formatting / added plot
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value
 
[Figure][1]


  [1]: https://i.sstatic.net/90JrD.png

Figure

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value
 
[Figure][1]


  [1]: https://i.sstatic.net/90JrD.png

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value

Figure

deleted 6 characters in body
Source Link
ava
  • 120
  • 9

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value

[![figure][1]][1][Figure][1]


  [1]: https://i.sstatic.net/htsGg90JrD.png

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value

[![figure][1]][1]


  [1]: https://i.sstatic.net/htsGg.png

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value

[Figure][1]


  [1]: https://i.sstatic.net/90JrD.png
Source Link
ava
  • 120
  • 9

Here a R solution with a Wilcoxon test and a figure example:

# library
library(tidyverse)
library(ggpubr)

# get data
sample= c(1:30)
M1=c(3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)
M2=c(3,2,3,3,2,2,3,3,3,2,2,3,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,2,2)

data.frame(sample,M1,M2) -> df

# calculate wilcox test
wilcox.test(df$M1,df$M2)
#>  Wilcoxon rank sum test with continuity correction
#> 
#> data:  df$M1 and df$M2
#> W = 360, p-value = 0.09554
#> alternative hypothesis: true location shift is not equal to 0

# prepare data for figure
df %>% 
  gather(key="key",value="value",-sample) -> df

# make figure
my_comparisons <- list( c("M1", "M2"))
ggboxplot(df, x = "key", y = "value",
          color = "key", palette = "jco")+ 
  stat_compare_means(comparisons = my_comparisons) # Add pairwise comparisons p-value

[![figure][1]][1]


  [1]: https://i.sstatic.net/htsGg.png