I have a dataframe with multiple items and subitems in which I want to calculate the kappa per item, with the irr
package using kappa2()
. for every item there is a '_1' and '_2', so; item1_1 and item1_2. which represents the first and second moment of data measuring.
An example of the dataframe:
edit:
items <- data.frame(matrix(0, nrow = 51, ncol = 41))
# Set the column names for the first column and items columns
colnames(items) <- c("ID", paste(rep(paste0("item", 1:20), each = 2), c("_1", "_2"), sep = ""))
# Fill the ID column with values 1 to 51
items$ID <- 1:51
# Fill the item columns with random 0's and 1's
set.seed(123) # Set seed for reproducibility
items[, 2:41] <- matrix(sample(c(0, 1), size = 20 * 2 * 51, replace = TRUE), ncol = 40)
# Show the resulting data frame
items
I want a dataframe which would look something like this:
item method subjects raters irr.name value stat.name statistic p.value
1 Cohenskappa.. 51 2 Kappa 0.536.. Z 3.897 0.023947
2 Cohenskappa.. 51 2 Kappa 0.705.. Z 5.757 0.000002
3 Cohenskappa.. 51 2 Kappa 0.890.. Z 6.447 0.072732
4 Cohenskappa.. 51 2 Kappa 0.236.. Z 3.429 0.005636
..
20 Cohenskappa.. 51 2 Kappa 0.686.. Z 4.897 0.000056
An option is creating single dataframes for every item and calculating the kappa, but this eventually result in wil result in more than 76 dataframes. There should be a more compact and quicker way.