rsurvival-analysissurvivalpairwise

custom code for compact letter display from pairwise table output


I would like to create a custom code that creates a compact letter display from a pairwise test I have performed.

I have done this with pairwise t-tests with success (packages for this exist), and I am also familiar with the package library(multcomp) when I run linear models and the function cld() to get the compact letter displays, but they will not work for my specific case here.

I work with kaplan meier survival data often, and after I run the pairwise_survdiff() function to see if any statistical differences exist between groups (found in the packages library(survival) and library(survminer), I am easily able to extract a table to display all pairwise comparisons and their corresponding p-values. I have included an example for you here today. (see df below)

When their are many comparisons to do by hand, this becomes a mess to found out which groups are different / similar, and it's prone to human error when many levels exist, and up to now, I've always done it by hand. I would like to change this.

Could someone help me with a code that helps do this automatically?

Here is a mock dataframe df with 10 treatments (named treatment-1....treatment-10), and the rows are filled with p-values. Let's assume anything below p<0.05 as significant. However, it would be very cool to have a code that would allow a more conservative approach, and say set the desired cut off for statistical significance (say anything below p<0.01 as significant for example).

Thanks for your help, and again, here is a play datatframe

df <- read.table("https://pastebin.com/raw/ZAKDBjVs", header = T)


Solution

  • While reflecting on this, I believe I found an answer on my own, with the library(mulcompView) and library(rcompanion)

    Nonetheless, I think it's important, since I have seen / heard this question multiple times. Here is how I solved my problem

    library(rcompanion)
    library(multcompView)
    df <- read.table("https://pastebin.com/raw/ZAKDBjVs", header=T)
    
    
    PT1 = fullPTable(df)
    multcompLetters(PT1,
                    compare="<",
                    threshold=0.05,
                    Letters=letters,
                    reversed = FALSE)
    
    

    This gives me the desired output with the compact letter displays between groups. Additionally, one could edit the statistical threshold to be either more/less conservative by changing the threshold=

    Very happy with the result. This has bothered me for a while. I hope it is useful to other members