Setup

# Attach packages
library(psych)     
library(psychTools)
library(psychometric) 
library(irr)       
library(dplyr)    
library(ltm)       

Attach and Preview Data

In this example, we will use the bfi data set that is part of the psychTools package. The data set contains 25 personality items from the International Personality Item Pool (IPIP) along with three demographic variables.

data(bfi)

Each row in the data set corresponds to a different person, and each column corresponds to a different variable.

head(bfi)
##       A1 A2 A3 A4 A5 C1 C2 C3 C4 C5 E1 E2 E3 E4 E5 N1 N2 N3 N4 N5 O1 O2 O3 O4
## 61617  2  4  3  4  4  2  3  3  4  4  3  3  3  4  4  3  4  2  2  3  3  6  3  4
## 61618  2  4  5  2  5  5  4  4  3  4  1  1  6  4  3  3  3  3  5  5  4  2  4  3
## 61620  5  4  5  4  4  4  5  4  2  5  2  4  4  4  5  4  5  4  2  3  4  2  5  5
## 61621  4  4  6  5  5  4  4  3  5  5  5  3  4  4  4  2  5  2  4  1  3  3  4  3
## 61622  2  3  3  4  5  4  4  5  3  2  2  2  5  4  5  2  3  4  4  3  3  3  4  3
## 61623  6  6  5  6  5  6  6  6  1  3  2  1  6  5  6  3  5  2  2  3  4  3  5  6
##       O5 gender education age
## 61617  3      1        NA  16
## 61618  3      2        NA  18
## 61620  2      2        NA  17
## 61621  5      2        NA  17
## 61622  3      1        NA  17
## 61623  1      2         3  21

The responses are coded such that 1 = Very Inaccurate, 2 = Moderately Inaccurate, 3 = Slightly Inaccurate, 4 = Slightly Accurate, 5 = Moderately Accurate, and 6 = Very Accurate. However, some of the items are negatively worded. These items must be reverse coded.

# Keep only the personality items
bfi_recoded <- bfi[, 1:25]

# Reverse code negatively worded items
bfi_recoded[, c("A1", "C4", "C5", "E1", "E2", "O2", "O5")] <-
  7 - bfi_recoded[, c("A1", "C4", "C5", "E1", "E2", "O2", "O5")]

Item Difficulty

# Compute mean score per item
item_difficulty <- colMeans(bfi_recoded, na.rm = TRUE)

# Display results
item_difficulty
##       A1       A2       A3       A4       A5       C1       C2       C3 
## 4.586566 4.802380 4.603821 4.699748 4.560345 4.502339 4.369957 4.303957 
##       C4       C5       E1       E2       E3       E4       E5       N1 
## 4.446647 3.703305 4.025567 3.858118 4.000721 4.422429 4.416337 2.929086 
##       N2       N3       N4       N5       O1       O2       O3       O4 
## 3.507737 3.216565 3.185601 2.969686 4.816055 4.286786 4.438312 4.892319 
##       O5 
## 4.510432

Item Discrimination

# Compute polyserial correlation of each item with total test score
total_score <- rowSums(bfi_recoded)  
polyserial_values <- sapply(bfi_recoded, function(item) polyserial(item, total_score))

# Display polyserial correlation for each item
polyserial_values
##         A1         A2         A3         A4         A5         C1         C2 
## 0.25045939 0.51682340 0.53643207 0.40437339 0.48187688 0.42149381 0.45800082 
##         C3         C4         C5         E1         E2         E3         E4 
## 0.35545137 0.37995331 0.34002312 0.42323625 0.44009931 0.55737176 0.47721750 
##         E5         N1         N2         N3         N4         N5         O1 
## 0.55613781 0.17906978 0.19094210 0.22183167 0.02057649 0.14449132 0.39887400 
##         O2         O3         O4         O5 
## 0.23006642 0.49990756 0.21880097 0.29001614

Test Reliability

# Compute Cronbach's Alpha for all items
cronbach_alpha <- psych::alpha(bfi_recoded, check.keys = TRUE)

# Display results
cronbach_alpha$total
##  raw_alpha std.alpha   G6(smc) average_r      S/N         ase     mean
##  0.8202549 0.8188383 0.8618576 0.1531145 4.519931 0.004856336 4.185886
##         sd  median_r
##  0.6141525 0.1276028

Inter-rater Reliability

# Assume multiple raters provided scores (simulated by selecting 3 raters' responses)
bfi_raters <- bfi_recoded[, 1:3]

# Compute Intraclass Correlation Coefficient (ICC)
icc_result <- icc(bfi_raters, model="twoway", type="agreement", unit="average")

# Display ICC result
icc_result
##  Average Score Intraclass Correlation
## 
##    Model: twoway 
##    Type : agreement 
## 
##    Subjects = 2736 
##      Raters = 3 
##    ICC(A,3) = 0.62
## 
##  F-Test, H0: r0 = 0 ; H1: r0 > 0 
## F(2735,4237) = 2.65 , p = 1.4e-179 
## 
##  95%-Confidence Interval for ICC Population Values:
##   0.593 < ICC < 0.645