rr-markdownflextableirr

How to generate a summary table (flextable) for r-markdown from irr output?


I have run 3 different Kappa2 analysis using the irr package.

library(irr)

data("diagnoses", package = "irr")

# Analysis 1
kappa2(diagnoses[, c("rater1", "rater2")], weight = "unweighted")

# Analysis 2
kappa2(diagnoses[, c("rater1", "rater3")], weight = "unweighted")

# Analysis 3
kappa2(diagnoses[, c("rater3", "rater2")], weight = "unweighted")

Is there a good way to generate summary of the output as presentation table (flextable if possible) for r markdown?. I`m looking for a table with: Analysis 1, Analysis 2, and Analysis 3 as rows. Subjects, Raters, Kappa, z and p-value as columns.


Solution

  • Would something like this work for your case ?

    We gather all the analysis in a list and extract the relevant values from it using lapply.

    library(irr)
    
    analysis1 <- kappa2(diagnoses[, c("rater1", "rater2")], weight = "unweighted")
    analysis2 <- kappa2(diagnoses[, c("rater1", "rater3")], weight = "unweighted")
    analysis3 <- kappa2(diagnoses[, c("rater3", "rater2")], weight = "unweighted")
    list_model <- dplyr::lst(analysis1, analysis2, analysis3)
    
    purrr::map_df(list_model, function(x) {
                data.frame(Subjects = x$subjects, 
                           Raters = x$raters, 
                           kappa = x$value, 
                           p_value = x$p.value)
    }) -> result
    
    flextable::flextable(cbind(model = names(list_model), result))
    

    enter image description here