Kappa applied to all pairwise combinations of raters, and store the result
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
add a comment |
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
Just to be clear, do you need the whole output ofirr::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
add a comment |
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
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
r functional-programming tidyverse
asked Jan 19 at 15:50
Fredrik KarlssonFredrik Karlsson
345314
345314
Just to be clear, do you need the whole output ofirr::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
add a comment |
Just to be clear, do you need the whole output ofirr::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
add a comment |
1 Answer
1
active
oldest
votes
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
}
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
}
}
add a comment |
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
}
}
add a comment |
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
}
}
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
}
}
edited Jan 19 at 16:27
answered Jan 19 at 16:13
Ric SRic S
669418
669418
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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