How to obtain the results of the Nemenyi post-hoc test in a table showing grouped pairs?

I performed a Friedman's test, which showed that there are differences among my treatments. Thus, I choose to perform the Nemenyi's post-hoc test in order to infer which treatments statistically differ among them. Thus, I used the posthoc.friedman.nemenyi.test from the PMCMR package to perform pairwise comparisons between treatments.

Now, I want to divide my treatments into groups, like the example below.

Treatment 1    a
Treatment 2    ab
Treatment 3     b
Treatment 4      c


My question is: Given the p-values of a multiple-comparison post-hoc test, how can I split my treatments into groups as the above example?

Note: This question is very similar to How to obtain the results of a Tukey HSD post-hoc test in a table showing grouped pairs?. However, I want to get this information for the Nemenyi's test instead of the Tukey's test.

• What do you mean by "How can I do that?"? Are you asking for code? (Note that questions that are only about how to use software are off topic here.) – gung Oct 15 '18 at 18:49
• This is virtually the same question as pointed in my reference (that was answered here in Cross Validated). I want an algorithm (or the idea of an algorithm) to perform such a task, not the code itself. I edited the question for a clearer objective. – Iago Carvalho Oct 15 '18 at 18:52

After a little more of research, I found a R code that solved this question. However, I still don't know how it works.

It is possible to use the multcompLetters function of the multcompView package along with the fullPTable function of the rcompanion package.

Thus, the following code outputs the grouped treatments:

if(!require(multcompView)){install.packages("multcompView")}
if(!require(PMCMR)){install.packages("PMCMR")}
if(!require(rcompanion)){install.packages("rcompanion")}

library(PMCMR)
library(rcompanion)
library(multcompView)

pTable  = posthoc.friedman.nemenyi.test(input)\$p.value
pTableComplete = fullPTable(pTable)
multcompLetters(pTableComplete)