Load the required packages

library(CTT)
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:CTT':
## 
##     polyserial

Import the item responses and scoring key

setwd("/Users/munira/Desktop/Education/Masters/Illinois Institute of Technology/Coursework/511-Psychometrics/Homework/HW3")
remove(list=ls())
data <- read.csv("Ex 13.1 data.csv")
key <- read.csv("Ex 13.1 key.csv")

Make a subset of data with items only (excluding ID)

items <- data[,2:14]

Score the items (converting to 0/1) according to the scoring key

scores <- data.frame(score(items, key, output.scored = TRUE)$scored)
names(scores) <- names(items)
View(scores)

Item analysis using CTT package

results <- itemAnalysis(scores, itemReport = TRUE)
## Warning in cor(items[, i], Xd): the standard deviation is zero
View(results$itemReport)

Distractor analysis using CTT package

distractorAnalysis(items = items, key = key, csvReport = "Ex 13.1 distractor analysis.csv")
## $Q1
##   correct key n      rspP       pBis discrim lower mid50 mid75 upper
## 1           1 0 0.0000000         NA    0.00  0.00     0   0.0     0
## 2       *   2 8 0.6666667  0.3952847    0.75  0.25     1   0.5     1
## 3           3 0 0.0000000         NA    0.00  0.00     0   0.0     0
## 4           4 4 0.3333333 -0.6645570   -0.75  0.75     0   0.5     0
## 
## $Q2
##   correct key n       rspP       pBis discrim lower     mid50 mid75 upper
## 1           1 1 0.08333333 -0.6404230   -0.25  0.25 0.0000000   0.0     0
## 2           2 4 0.33333333 -0.4265626   -0.50  0.50 0.3333333   0.5     0
## 3           3 1 0.08333333 -0.1910634    0.00  0.00 0.3333333   0.0     0
## 4       *   4 6 0.50000000  0.4561716    0.75  0.25 0.3333333   0.5     1
## 
## $Q3
##   correct key n       rspP       pBis discrim lower     mid50 mid75 upper
## 1           1 2 0.16666667 -0.4303315    -0.5   0.5 0.0000000     0     0
## 2           2 1 0.08333333 -0.1910634     0.0   0.0 0.3333333     0     0
## 3           3 0 0.00000000         NA     0.0   0.0 0.0000000     0     0
## 4       *   4 9 0.75000000  0.1426197     0.5   0.5 0.6666667     1     1
## 
## $Q4
##   correct key  n rspP pBis discrim lower mid50 mid75 upper
## 1           1  0    0   NA       0     0     0     0     0
## 2           2  0    0   NA       0     0     0     0     0
## 3       *   3 12    1   NA       0     1     1     1     1
## 4           4  0    0   NA       0     0     0     0     0
## 
## $Q5
##   correct key n       rspP        pBis     discrim lower     mid50 mid75
## 1           1 1 0.08333333 -0.30765537 -0.25000000  0.25 0.0000000   0.0
## 2       *   2 4 0.33333333  0.04926646  0.33333333  0.00 0.6666667   0.5
## 3           3 7 0.58333333 -0.30210205 -0.08333333  0.75 0.3333333   0.5
## 4           4 0 0.00000000          NA  0.00000000  0.00 0.0000000   0.0
##       upper
## 1 0.0000000
## 2 0.3333333
## 3 0.6666667
## 4 0.0000000
## 
## $Q6
##   correct key n       rspP        pBis discrim lower mid50 mid75 upper
## 1           1 1 0.08333333 -0.07135061    0.00  0.00     0   0.5     0
## 2           2 1 0.08333333 -0.07135061    0.00  0.00     0   0.5     0
## 3       *   3 9 0.75000000  0.14261974    0.25  0.75     1   0.0     1
## 4           4 1 0.08333333 -0.64042300   -0.25  0.25     0   0.0     0
## 
## $Q7
##   correct key n       rspP        pBis     discrim lower     mid50 mid75
## 1           1 1 0.08333333  0.30856302  0.33333333  0.00 0.0000000     0
## 2       *   2 4 0.33333333 -0.02428215  0.08333333  0.25 0.0000000     1
## 3           3 2 0.16666667 -0.34859574 -0.25000000  0.25 0.3333333     0
## 4           4 5 0.41666667 -0.40352334 -0.16666667  0.50 0.6666667     0
##       upper
## 1 0.3333333
## 2 0.3333333
## 3 0.0000000
## 4 0.3333333
## 
## $Q8
##   correct key n       rspP       pBis discrim lower     mid50 mid75 upper
## 1           1 0 0.00000000         NA     0.0   0.0 0.0000000     0     0
## 2           2 1 0.08333333 -0.1910634     0.0   0.0 0.3333333     0     0
## 3           3 5 0.41666667 -0.5765553    -0.5   0.5 0.3333333     1     0
## 4       *   4 6 0.50000000  0.2940858     0.5   0.5 0.3333333     0     1
## 
## $Q9
##   correct key  n      rspP       pBis discrim lower     mid50 mid75 upper
## 1       *   1 10 0.8333333 -0.1203314       0     1 0.6666667   0.5     1
## 2           2  0 0.0000000         NA       0     0 0.0000000   0.0     0
## 3           3  2 0.1666667 -0.1788854       0     0 0.3333333   0.5     0
## 4           4  0 0.0000000         NA       0     0 0.0000000   0.0     0
## 
## $Q10
##   correct key n       rspP       pBis discrim lower     mid50 mid75 upper
## 1           1 3 0.25000000 -0.3890891   -0.25  0.25 0.6666667     0     0
## 2           2 0 0.00000000         NA    0.00  0.00 0.0000000     0     0
## 3       *   3 8 0.66666667  0.3952847    0.50  0.50 0.3333333     1     1
## 4           4 1 0.08333333 -0.6404230   -0.25  0.25 0.0000000     0     0
## 
## $Q11
##   correct key n rspP       pBis discrim lower mid50 mid75 upper
## 1           1 6  0.5 -0.7673657   -0.75  0.75     1     0     0
## 2           2 0  0.0         NA    0.00  0.00     0     0     0
## 3           3 0  0.0         NA    0.00  0.00     0     0     0
## 4       *   4 6  0.5  0.5416763    0.75  0.25     0     1     1
## 
## $Q12
##   correct key n       rspP        pBis discrim lower     mid50 mid75 upper
## 1           1 1 0.08333333 -0.07135061    0.00  0.00 0.0000000   0.5     0
## 2           2 3 0.25000000 -0.71665619   -0.75  0.75 0.0000000   0.0     0
## 3       *   3 6 0.50000000  0.54167626    1.00  0.00 0.6666667   0.5     1
## 4           4 2 0.16666667 -0.34859574   -0.25  0.25 0.3333333   0.0     0
## 
## $Q13
##   correct key n      rspP       pBis    discrim lower     mid50 mid75
## 1       *   1 4 0.3333333  0.3668997  0.6666667  0.00 0.3333333   0.5
## 2           2 4 0.3333333 -0.1653595 -0.1666667  0.50 0.0000000   0.5
## 3           3 2 0.1666667 -0.5881176 -0.2500000  0.25 0.3333333   0.0
## 4           4 2 0.1666667 -0.3485957 -0.2500000  0.25 0.3333333   0.0
##       upper
## 1 0.6666667
## 2 0.3333333
## 3 0.0000000
## 4 0.0000000

Descriptive statistics

summary(scores)
##        Q1               Q2            Q3             Q4   
##  Min.   :0.0000   Min.   :0.0   Min.   :0.00   Min.   :1  
##  1st Qu.:0.0000   1st Qu.:0.0   1st Qu.:0.75   1st Qu.:1  
##  Median :1.0000   Median :0.5   Median :1.00   Median :1  
##  Mean   :0.6667   Mean   :0.5   Mean   :0.75   Mean   :1  
##  3rd Qu.:1.0000   3rd Qu.:1.0   3rd Qu.:1.00   3rd Qu.:1  
##  Max.   :1.0000   Max.   :1.0   Max.   :1.00   Max.   :1  
##        Q5               Q6             Q7               Q8     
##  Min.   :0.0000   Min.   :0.00   Min.   :0.0000   Min.   :0.0  
##  1st Qu.:0.0000   1st Qu.:0.75   1st Qu.:0.0000   1st Qu.:0.0  
##  Median :0.0000   Median :1.00   Median :0.0000   Median :0.5  
##  Mean   :0.3333   Mean   :0.75   Mean   :0.3333   Mean   :0.5  
##  3rd Qu.:1.0000   3rd Qu.:1.00   3rd Qu.:1.0000   3rd Qu.:1.0  
##  Max.   :1.0000   Max.   :1.00   Max.   :1.0000   Max.   :1.0  
##        Q9              Q10              Q11           Q12     
##  Min.   :0.0000   Min.   :0.0000   Min.   :0.0   Min.   :0.0  
##  1st Qu.:1.0000   1st Qu.:0.0000   1st Qu.:0.0   1st Qu.:0.0  
##  Median :1.0000   Median :1.0000   Median :0.5   Median :0.5  
##  Mean   :0.8333   Mean   :0.6667   Mean   :0.5   Mean   :0.5  
##  3rd Qu.:1.0000   3rd Qu.:1.0000   3rd Qu.:1.0   3rd Qu.:1.0  
##  Max.   :1.0000   Max.   :1.0000   Max.   :1.0   Max.   :1.0  
##       Q13        
##  Min.   :0.0000  
##  1st Qu.:0.0000  
##  Median :0.0000  
##  Mean   :0.3333  
##  3rd Qu.:1.0000  
##  Max.   :1.0000
describe(scores)
##     vars  n mean   sd median trimmed  mad min max range  skew kurtosis
## Q1     1 12 0.67 0.49    1.0     0.7 0.00   0   1     1 -0.62    -1.74
## Q2     2 12 0.50 0.52    0.5     0.5 0.74   0   1     1  0.00    -2.16
## Q3     3 12 0.75 0.45    1.0     0.8 0.00   0   1     1 -1.01    -1.04
## Q4     4 12 1.00 0.00    1.0     1.0 0.00   1   1     0   NaN      NaN
## Q5     5 12 0.33 0.49    0.0     0.3 0.00   0   1     1  0.62    -1.74
## Q6     6 12 0.75 0.45    1.0     0.8 0.00   0   1     1 -1.01    -1.04
## Q7     7 12 0.33 0.49    0.0     0.3 0.00   0   1     1  0.62    -1.74
## Q8     8 12 0.50 0.52    0.5     0.5 0.74   0   1     1  0.00    -2.16
## Q9     9 12 0.83 0.39    1.0     0.9 0.00   0   1     1 -1.57     0.53
## Q10   10 12 0.67 0.49    1.0     0.7 0.00   0   1     1 -0.62    -1.74
## Q11   11 12 0.50 0.52    0.5     0.5 0.74   0   1     1  0.00    -2.16
## Q12   12 12 0.50 0.52    0.5     0.5 0.74   0   1     1  0.00    -2.16
## Q13   13 12 0.33 0.49    0.0     0.3 0.00   0   1     1  0.62    -1.74
##       se
## Q1  0.14
## Q2  0.15
## Q3  0.13
## Q4  0.00
## Q5  0.14
## Q6  0.13
## Q7  0.14
## Q8  0.15
## Q9  0.11
## Q10 0.14
## Q11 0.15
## Q12 0.15
## Q13 0.14

Realiability analysis (alpha)

alpha(scores, check.keys = TRUE)
## Warning in alpha(scores, check.keys = TRUE): Item = Q4 had no variance and
## was deleted
## Warning in cor.smooth(r): Matrix was not positive definite, smoothing was
## done
## Warning in alpha(scores, check.keys = TRUE): Some items were negatively correlated with total scale and were automatically reversed.
##  This is indicated by a negative sign for the variable name.
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done
## In smc, the correlation matrix was not invertible, smc's returned as 1s
## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done

## Warning in cor.smooth(R): Matrix was not positive definite, smoothing was
## done
## 
## Reliability analysis   
## Call: alpha(x = scores, check.keys = TRUE)
## 
##   raw_alpha std.alpha G6(smc) average_r S/N  ase mean   sd median_r
##       0.64      0.63    0.96      0.12 1.7 0.15 0.53 0.22  9.6e-21
## 
##  lower alpha upper     95% confidence boundaries
## 0.35 0.64 0.94 
## 
##  Reliability if an item is dropped:
##     raw_alpha std.alpha G6(smc) average_r S/N var.r   med.r
## Q1       0.59      0.58    0.92     0.110 1.4 0.075 0.0e+00
## Q2       0.59      0.57    0.95     0.109 1.3 0.076 9.6e-21
## Q3       0.68      0.67    0.96     0.158 2.1 0.071 1.2e-01
## Q5       0.62      0.60    0.95     0.118 1.5 0.073 9.6e-21
## Q6       0.63      0.62    0.94     0.129 1.6 0.071 9.6e-21
## Q7-      0.68      0.66    0.95     0.150 1.9 0.072 1.2e-20
## Q8       0.62      0.60    0.93     0.122 1.5 0.077 1.2e-20
## Q9-      0.65      0.65    1.00     0.142 1.8 0.066 1.2e-01
## Q10      0.62      0.61    0.94     0.124 1.6 0.068 1.2e-20
## Q11      0.61      0.59    0.93     0.116 1.4 0.070 0.0e+00
## Q12      0.57      0.56    0.92     0.102 1.3 0.076 0.0e+00
## Q13      0.55      0.53    0.93     0.092 1.1 0.072 0.0e+00
## 
##  Item statistics 
##      n raw.r std.r r.cor r.drop mean   sd
## Q1  12 0.583 0.576 0.589  0.438 0.67 0.49
## Q2  12 0.593 0.590 0.573  0.441 0.50 0.52
## Q3  12 0.076 0.073 0.031 -0.095 0.75 0.45
## Q5  12 0.466 0.492 0.466  0.302 0.33 0.49
## Q6  12 0.381 0.376 0.366  0.221 0.75 0.45
## Q7- 12 0.163 0.163 0.118 -0.024 0.67 0.49
## Q8  12 0.462 0.453 0.449  0.285 0.50 0.52
## Q9- 12 0.206 0.240 0.220  0.060 0.17 0.39
## Q10 12 0.443 0.425 0.434  0.275 0.67 0.49
## Q11 12 0.528 0.510 0.521  0.362 0.50 0.52
## Q12 12 0.659 0.653 0.667  0.523 0.50 0.52
## Q13 12 0.746 0.762 0.760  0.643 0.33 0.49
## 
## Non missing response frequency for each item
##        0    1 miss
## Q1  0.33 0.67    0
## Q2  0.50 0.50    0
## Q3  0.25 0.75    0
## Q5  0.67 0.33    0
## Q6  0.25 0.75    0
## Q7  0.67 0.33    0
## Q8  0.50 0.50    0
## Q9  0.17 0.83    0
## Q10 0.33 0.67    0
## Q11 0.50 0.50    0
## Q12 0.50 0.50    0
## Q13 0.67 0.33    0