Kappa applied to all pairwise combinations of raters, and store the result












0















For a visualisation, I need to compute the weighted kappa of all combinations / pairs of seven raters. So, if I use some sample data with seven columns:



ex <- structure(list(`1` = c(1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 1, 1, 1, 
1, 1, 1, 2, 1, 2, 2), `2` = c(1, 1, 1, 1, 2, 1, 1, 1, 2, 3, 1,
2, 1, 1, 2, 2, 1, 2, 2, 2), `3` = c(1, 1, 2, 1, 2, 1, 1, 1, 2,
3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2), `4` = c(1, 1, 2, 2, 2, 1, 2,
2, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2), pa = c(1, 2, 1, 2, 3,
1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 3, 2), ta = c(2, 2, 2,
1, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 3), ka = c(1,
1, 2, 1, 2, 1, 1, 1, 2, 3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2)), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))


I would like to get a structure that captures the output of irr::kappa2 on all combinations of columns. A structure like:



out <- data.frame("1_2"=irr::kappa2(ex[c(1,2)]),
"1_3"=irr::kappa2(ex[c(1,3)]),"1_4"=irr::kappa2(ex[c(1,3)]),....


(for all unique combinations of columns).



Any ideas?










share|improve this question























  • Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

    – Ric S
    Jan 19 at 16:05











  • The kappa value is the what I want primarily.

    – Fredrik Karlsson
    Jan 19 at 16:16











  • Ok then, I'll edit my answer below in the case you want only the kappa value

    – Ric S
    Jan 19 at 16:18











  • Great thank you very much!

    – Fredrik Karlsson
    Jan 19 at 16:24











  • You're welcome! :)

    – Ric S
    Jan 19 at 16:27
















0















For a visualisation, I need to compute the weighted kappa of all combinations / pairs of seven raters. So, if I use some sample data with seven columns:



ex <- structure(list(`1` = c(1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 1, 1, 1, 
1, 1, 1, 2, 1, 2, 2), `2` = c(1, 1, 1, 1, 2, 1, 1, 1, 2, 3, 1,
2, 1, 1, 2, 2, 1, 2, 2, 2), `3` = c(1, 1, 2, 1, 2, 1, 1, 1, 2,
3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2), `4` = c(1, 1, 2, 2, 2, 1, 2,
2, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2), pa = c(1, 2, 1, 2, 3,
1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 3, 2), ta = c(2, 2, 2,
1, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 3), ka = c(1,
1, 2, 1, 2, 1, 1, 1, 2, 3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2)), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))


I would like to get a structure that captures the output of irr::kappa2 on all combinations of columns. A structure like:



out <- data.frame("1_2"=irr::kappa2(ex[c(1,2)]),
"1_3"=irr::kappa2(ex[c(1,3)]),"1_4"=irr::kappa2(ex[c(1,3)]),....


(for all unique combinations of columns).



Any ideas?










share|improve this question























  • Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

    – Ric S
    Jan 19 at 16:05











  • The kappa value is the what I want primarily.

    – Fredrik Karlsson
    Jan 19 at 16:16











  • Ok then, I'll edit my answer below in the case you want only the kappa value

    – Ric S
    Jan 19 at 16:18











  • Great thank you very much!

    – Fredrik Karlsson
    Jan 19 at 16:24











  • You're welcome! :)

    – Ric S
    Jan 19 at 16:27














0












0








0








For a visualisation, I need to compute the weighted kappa of all combinations / pairs of seven raters. So, if I use some sample data with seven columns:



ex <- structure(list(`1` = c(1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 1, 1, 1, 
1, 1, 1, 2, 1, 2, 2), `2` = c(1, 1, 1, 1, 2, 1, 1, 1, 2, 3, 1,
2, 1, 1, 2, 2, 1, 2, 2, 2), `3` = c(1, 1, 2, 1, 2, 1, 1, 1, 2,
3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2), `4` = c(1, 1, 2, 2, 2, 1, 2,
2, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2), pa = c(1, 2, 1, 2, 3,
1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 3, 2), ta = c(2, 2, 2,
1, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 3), ka = c(1,
1, 2, 1, 2, 1, 1, 1, 2, 3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2)), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))


I would like to get a structure that captures the output of irr::kappa2 on all combinations of columns. A structure like:



out <- data.frame("1_2"=irr::kappa2(ex[c(1,2)]),
"1_3"=irr::kappa2(ex[c(1,3)]),"1_4"=irr::kappa2(ex[c(1,3)]),....


(for all unique combinations of columns).



Any ideas?










share|improve this question














For a visualisation, I need to compute the weighted kappa of all combinations / pairs of seven raters. So, if I use some sample data with seven columns:



ex <- structure(list(`1` = c(1, 1, 2, 1, 2, 1, 1, 1, 2, 3, 1, 1, 1, 
1, 1, 1, 2, 1, 2, 2), `2` = c(1, 1, 1, 1, 2, 1, 1, 1, 2, 3, 1,
2, 1, 1, 2, 2, 1, 2, 2, 2), `3` = c(1, 1, 2, 1, 2, 1, 1, 1, 2,
3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2), `4` = c(1, 1, 2, 2, 2, 1, 2,
2, 2, 3, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2), pa = c(1, 2, 1, 2, 3,
1, 2, 2, 2, 2, 2, 2, 1, 2, 1, 2, 2, 1, 3, 2), ta = c(2, 2, 2,
1, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 1, 1, 3), ka = c(1,
1, 2, 1, 2, 1, 1, 1, 2, 3, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2)), row.names = c(NA, -20L), class = c("tbl_df", "tbl", "data.frame"))


I would like to get a structure that captures the output of irr::kappa2 on all combinations of columns. A structure like:



out <- data.frame("1_2"=irr::kappa2(ex[c(1,2)]),
"1_3"=irr::kappa2(ex[c(1,3)]),"1_4"=irr::kappa2(ex[c(1,3)]),....


(for all unique combinations of columns).



Any ideas?







r functional-programming tidyverse






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 19 at 15:50









Fredrik KarlssonFredrik Karlsson

345314




345314













  • Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

    – Ric S
    Jan 19 at 16:05











  • The kappa value is the what I want primarily.

    – Fredrik Karlsson
    Jan 19 at 16:16











  • Ok then, I'll edit my answer below in the case you want only the kappa value

    – Ric S
    Jan 19 at 16:18











  • Great thank you very much!

    – Fredrik Karlsson
    Jan 19 at 16:24











  • You're welcome! :)

    – Ric S
    Jan 19 at 16:27



















  • Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

    – Ric S
    Jan 19 at 16:05











  • The kappa value is the what I want primarily.

    – Fredrik Karlsson
    Jan 19 at 16:16











  • Ok then, I'll edit my answer below in the case you want only the kappa value

    – Ric S
    Jan 19 at 16:18











  • Great thank you very much!

    – Fredrik Karlsson
    Jan 19 at 16:24











  • You're welcome! :)

    – Ric S
    Jan 19 at 16:27

















Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

– Ric S
Jan 19 at 16:05





Just to be clear, do you need the whole output of irr::kappa2() or just the value of Kappa?

– Ric S
Jan 19 at 16:05













The kappa value is the what I want primarily.

– Fredrik Karlsson
Jan 19 at 16:16





The kappa value is the what I want primarily.

– Fredrik Karlsson
Jan 19 at 16:16













Ok then, I'll edit my answer below in the case you want only the kappa value

– Ric S
Jan 19 at 16:18





Ok then, I'll edit my answer below in the case you want only the kappa value

– Ric S
Jan 19 at 16:18













Great thank you very much!

– Fredrik Karlsson
Jan 19 at 16:24





Great thank you very much!

– Fredrik Karlsson
Jan 19 at 16:24













You're welcome! :)

– Ric S
Jan 19 at 16:27





You're welcome! :)

– Ric S
Jan 19 at 16:27












1 Answer
1






active

oldest

votes


















2














A solution would be to store the whole output structure of function kappa2 into an element of a list, and to have an element for each possible combination of columns:



# initialization
out_list <- list()
column <- 1

# cycle for storing kappa2's output structure
for (i in 1:(ncol(ex)-1)){
for (j in (i+1):ncol(ex)){
out_list[[column]] <- irr::kappa2(ex[,c(i,j)])
# renaming the elements
names(out_list)[column] <- paste0(i, "_", j)
column <- column + 1
}
}




In case you just want the Kappa value for each pair of columns, like you said in the comments, you can use the following (very similar to before) code:



# initialization
# the number of columns of "out" is from mathematics
out <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(ex) * (ncol(ex)-1) / 2))
column <- 1

# cycle for calculation kappa
for (i in 1:(ncol(ex)-1)){
for (j in (i+1):ncol(ex)){
out[1,column] <- irr::kappa2(ex[,c(i,j)])$value
colnames(out)[column] <- paste0(i, "_", j)
column <- column + 1
}
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268798%2fkappa-applied-to-all-pairwise-combinations-of-raters-and-store-the-result%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    A solution would be to store the whole output structure of function kappa2 into an element of a list, and to have an element for each possible combination of columns:



    # initialization
    out_list <- list()
    column <- 1

    # cycle for storing kappa2's output structure
    for (i in 1:(ncol(ex)-1)){
    for (j in (i+1):ncol(ex)){
    out_list[[column]] <- irr::kappa2(ex[,c(i,j)])
    # renaming the elements
    names(out_list)[column] <- paste0(i, "_", j)
    column <- column + 1
    }
    }




    In case you just want the Kappa value for each pair of columns, like you said in the comments, you can use the following (very similar to before) code:



    # initialization
    # the number of columns of "out" is from mathematics
    out <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(ex) * (ncol(ex)-1) / 2))
    column <- 1

    # cycle for calculation kappa
    for (i in 1:(ncol(ex)-1)){
    for (j in (i+1):ncol(ex)){
    out[1,column] <- irr::kappa2(ex[,c(i,j)])$value
    colnames(out)[column] <- paste0(i, "_", j)
    column <- column + 1
    }
    }





    share|improve this answer






























      2














      A solution would be to store the whole output structure of function kappa2 into an element of a list, and to have an element for each possible combination of columns:



      # initialization
      out_list <- list()
      column <- 1

      # cycle for storing kappa2's output structure
      for (i in 1:(ncol(ex)-1)){
      for (j in (i+1):ncol(ex)){
      out_list[[column]] <- irr::kappa2(ex[,c(i,j)])
      # renaming the elements
      names(out_list)[column] <- paste0(i, "_", j)
      column <- column + 1
      }
      }




      In case you just want the Kappa value for each pair of columns, like you said in the comments, you can use the following (very similar to before) code:



      # initialization
      # the number of columns of "out" is from mathematics
      out <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(ex) * (ncol(ex)-1) / 2))
      column <- 1

      # cycle for calculation kappa
      for (i in 1:(ncol(ex)-1)){
      for (j in (i+1):ncol(ex)){
      out[1,column] <- irr::kappa2(ex[,c(i,j)])$value
      colnames(out)[column] <- paste0(i, "_", j)
      column <- column + 1
      }
      }





      share|improve this answer




























        2












        2








        2







        A solution would be to store the whole output structure of function kappa2 into an element of a list, and to have an element for each possible combination of columns:



        # initialization
        out_list <- list()
        column <- 1

        # cycle for storing kappa2's output structure
        for (i in 1:(ncol(ex)-1)){
        for (j in (i+1):ncol(ex)){
        out_list[[column]] <- irr::kappa2(ex[,c(i,j)])
        # renaming the elements
        names(out_list)[column] <- paste0(i, "_", j)
        column <- column + 1
        }
        }




        In case you just want the Kappa value for each pair of columns, like you said in the comments, you can use the following (very similar to before) code:



        # initialization
        # the number of columns of "out" is from mathematics
        out <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(ex) * (ncol(ex)-1) / 2))
        column <- 1

        # cycle for calculation kappa
        for (i in 1:(ncol(ex)-1)){
        for (j in (i+1):ncol(ex)){
        out[1,column] <- irr::kappa2(ex[,c(i,j)])$value
        colnames(out)[column] <- paste0(i, "_", j)
        column <- column + 1
        }
        }





        share|improve this answer















        A solution would be to store the whole output structure of function kappa2 into an element of a list, and to have an element for each possible combination of columns:



        # initialization
        out_list <- list()
        column <- 1

        # cycle for storing kappa2's output structure
        for (i in 1:(ncol(ex)-1)){
        for (j in (i+1):ncol(ex)){
        out_list[[column]] <- irr::kappa2(ex[,c(i,j)])
        # renaming the elements
        names(out_list)[column] <- paste0(i, "_", j)
        column <- column + 1
        }
        }




        In case you just want the Kappa value for each pair of columns, like you said in the comments, you can use the following (very similar to before) code:



        # initialization
        # the number of columns of "out" is from mathematics
        out <- as.data.frame(matrix(0, nrow = 1, ncol = ncol(ex) * (ncol(ex)-1) / 2))
        column <- 1

        # cycle for calculation kappa
        for (i in 1:(ncol(ex)-1)){
        for (j in (i+1):ncol(ex)){
        out[1,column] <- irr::kappa2(ex[,c(i,j)])$value
        colnames(out)[column] <- paste0(i, "_", j)
        column <- column + 1
        }
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 19 at 16:27

























        answered Jan 19 at 16:13









        Ric SRic S

        669418




        669418






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268798%2fkappa-applied-to-all-pairwise-combinations-of-raters-and-store-the-result%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Callistus III

            Plistias Cous

            Index Sanctorum