# Perform pairwise Wilcoxon test, classify groups by significance and plot results

**R – Fabio Marroni's Blog**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This post is the result of work performed in collaboration with my colleague Eleonora Paparelli (who actually did most of the work!). We wanted to compare several distributions using Wilcoxon test and summarize results (i.e. indicate the comparisons showing significant differences).

R base includes pairwise.wilcox.test to perform Wilcoxon rank sum test between all pairs of samples in a study.

A common way to represent significance in pairwise comparisons is the use of letters. Samples sharing a letter are not different from each other. Samples not sharing letters are different.

Library multcompView in R can take a square matrix of p-values and return letters for all samples.

Sadly enough, pairwise.wilcox.test returns a triangular matrix, so I had to write a small function – named tri.to.squ – to take the output of pairwise.wilcox.test and convert it in a suitable input for the multcompLetters function of multcompView.

Now we can easily plot the distributions as box plot and add the letters as text.

library(multcompView) tri.to.squ

**leave a comment**for the author, please follow the link and comment on their blog:

**R – Fabio Marroni's Blog**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.