rowMeans()1. Calculate the percent agreement across all variables for each teacher/pair of raters
Review the data (rater_data)
# A tibble: 6 x 5
tch_id rater_id item1 item2 item3
<dbl> <dbl> <dbl> <dbl> <dbl>
1 100 5 1 0 3
2 100 10 1 1 3
3 101 5 0 1 2
4 101 8 0 0 2
5 102 6 1 1 1
6 102 8 1 1 1
First get an agreement score for each variable. 0 = no agreement, 1 = agreement
We can do this by
1. First grouping by tch_id using
dplyr::group_by()
2. Then summarizing the differences between raters across all variables
using dplyr::across() and base::diff()
3. Then using dplyr::mutate() to recode the items to values
of 0 (no agreement) or 1 (agreement)
rater_summary <- rater_data %>%
group_by(tch_id) %>%
summarise(across(item1:item3, diff)) %>%
mutate(across(item1:item3,
~ case_when(
. == 0 ~ 1,
.default = 0
)))
rater_summary
# A tibble: 3 x 4
tch_id item1 item2 item3
<dbl> <dbl> <dbl> <dbl>
1 100 1 0 1
2 101 1 0 1
3 102 1 1 1
Next we can calculate a row mean (using
base::rowMeans()) to get a percent agreement per
teacher/rater pair.
rater_summary %>%
mutate(percent_agree =
round(rowMeans(across(item1:item3), na.rm = TRUE),
digits = 2))
# A tibble: 3 x 5
tch_id item1 item2 item3 percent_agree
<dbl> <dbl> <dbl> <dbl> <dbl>
1 100 1 0 1 0.67
2 101 1 0 1 0.67
3 102 1 1 1 1
Return to Calculate Sums and Means