### Install and load the packages:

# eRm:
citation("eRm")
## The original JSS article: Article about CML Estimation in eRm: Article
## about LLRAs in eRm: Book Chapter about LLRAs: Article about the
## performance of Quasi-Exact Tests in eRm: Article about the Performance
## of the nonparametric Q3 Tests in eRm:
## 
##   Mair P, Hatzinger R (2007). "Extended Rasch modeling: The eRm package
##   for the application of IRT models in R." _Journal of Statistical
##   Software_, *20*. doi:10.18637/jss.v020.i09
##   <https://doi.org/10.18637/jss.v020.i09>.
## 
##   Mair P, Hatzinger R (2007). "CML based estimation of extended Rasch
##   models with the eRm package in R." _Psychology Science_, *49*.
##   doi:10.18637/jss.v020.i09 <https://doi.org/10.18637/jss.v020.i09>.
## 
##   Hatzinger R, Rusch T (2009). "IRT models with relaxed assumptions in
##   eRm: A manual-like instruction." _Psychology Science Quarterly_,
##   *51*.
## 
##   Rusch T, Maier M, Hatzinger R (2013). "Linear logistic models with
##   relaxed assumptions in R." In Lausen B, van den Poel D, Ultsch A
##   (eds.), _Algorithms from and for Nature and Life_, series Studies in
##   Classification, Data Analysis, and Knowledge Organization.
##   doi:10.1007/978-3-319-00035-0_34
##   <https://doi.org/10.1007/978-3-319-00035-0_34>.
## 
##   Koller I, Maier M, Hatzinger R (2015). "An empirical power analysis
##   of quasi-exact tests for the Rasch model: Measurement invariance in
##   small samples." _Methodology_, *11*. doi:10.1027/1614-2241/a000090
##   <https://doi.org/10.1027/1614-2241/a000090>.
## 
##   Debelak R, Koller I (2019). "Testing the local independence
##   assumption of the Rasch model with Q3-based nonparametric model
##   tests." _Applied Psychological Measurement_, *44*.
##   doi:10.1177/0146621619835501
##   <https://doi.org/10.1177/0146621619835501>.
## 
## To see these entries in BibTeX format, use 'print(<citation>,
## bibtex=TRUE)', 'toBibtex(.)', or set
## 'options(citation.bibtex.max=999)'.
#install.packages("eRm")
library("eRm")
## Warning: package 'eRm' was built under R version 4.4.1
retail_5000_labels <- read.csv("retail_salespeople_statistic_64_labels.csv")
summary(retail_5000_labels)
##     Position          Age            Gender         Marital           q01      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00  
##  1st Qu.:2.000   1st Qu.:4.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.00  
##  Median :2.000   Median :5.000   Median :2.000   Median :2.000   Median :1.00  
##  Mean   :2.466   Mean   :4.673   Mean   :1.902   Mean   :1.589   Mean   :1.35  
##  3rd Qu.:3.000   3rd Qu.:6.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.00  
##  Max.   :3.000   Max.   :9.000   Max.   :2.000   Max.   :2.000   Max.   :2.00  
##       q02             q03             q04             q05       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.669   Mean   :1.275   Mean   :1.163   Mean   :1.161  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:1.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q06             q07             q08             q09       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :2.000   Median :2.000   Median :1.000  
##  Mean   :1.432   Mean   :1.548   Mean   :1.575   Mean   :1.369  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q10             q11             q12             q13       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :2.000   Median :1.000   Median :2.000  
##  Mean   :1.629   Mean   :1.846   Mean   :1.454   Mean   :1.547  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q14             q15             q16             q17       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.401   Mean   :1.198   Mean   :1.425   Mean   :1.842  
##  3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q18             q19             q20             q21       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :1.000   Median :2.000   Median :2.000  
##  Mean   :1.478   Mean   :1.253   Mean   :1.695   Mean   :1.856  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q22             q23             q24             q25             q26      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:1.00  
##  Median :2.000   Median :1.000   Median :2.000   Median :2.000   Median :1.00  
##  Mean   :1.525   Mean   :1.333   Mean   :1.523   Mean   :1.863   Mean   :1.48  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.00  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.00  
##       q27             q28             q29             q30       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.093   Mean   :1.377   Mean   :1.466   Mean   :1.742  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q31             q32             q33             q34       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.055   Mean   :1.153   Mean   :1.126   Mean   :1.666  
##  3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q35             q36             q37             q38       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :2.000   Median :1.000   Median :2.000  
##  Mean   :1.198   Mean   :1.694   Mean   :1.211   Mean   :1.815  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q39             q40             q41             q42       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.742   Mean   :1.329   Mean   :1.366   Mean   :1.285  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q43             q44             q45             q46       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :2.000   Median :1.000   Median :1.000  
##  Mean   :1.854   Mean   :1.694   Mean   :1.213   Mean   :1.296  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q47             q48             q49             q50       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :2.000   Median :1.000  
##  Mean   :1.489   Mean   :1.313   Mean   :1.623   Mean   :1.237  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q51             q52            q53             q54            q55       
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.00   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000  
##  Median :1.000   Median :1.00   Median :2.000   Median :1.00   Median :2.000  
##  Mean   :1.207   Mean   :1.27   Mean   :1.516   Mean   :1.29   Mean   :1.728  
##  3rd Qu.:1.000   3rd Qu.:2.00   3rd Qu.:2.000   3rd Qu.:2.00   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.00   Max.   :2.000   Max.   :2.00   Max.   :2.000  
##       q56             q57             q58             q59       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.246   Mean   :1.402   Mean   :1.347   Mean   :1.603  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q60       
##  Min.   :1.000  
##  1st Qu.:1.000  
##  Median :1.000  
##  Mean   :1.457  
##  3rd Qu.:2.000  
##  Max.   :2.000
# Remove the Person Variables:
retail_5000_60 <- subset(retail_5000_labels, select = -c(Position, Age, Gender, Marital))

# Check descriptive statistics:
summary(retail_5000_60)
##       q01            q02             q03             q04             q05       
##  Min.   :1.00   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.00   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.00   Median :2.000   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.35   Mean   :1.669   Mean   :1.275   Mean   :1.163   Mean   :1.161  
##  3rd Qu.:2.00   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:1.000  
##  Max.   :2.00   Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q06             q07             q08             q09       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :2.000   Median :2.000   Median :1.000  
##  Mean   :1.432   Mean   :1.548   Mean   :1.575   Mean   :1.369  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q10             q11             q12             q13       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :2.000   Median :1.000   Median :2.000  
##  Mean   :1.629   Mean   :1.846   Mean   :1.454   Mean   :1.547  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q14             q15             q16             q17       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.401   Mean   :1.198   Mean   :1.425   Mean   :1.842  
##  3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q18             q19             q20             q21       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :1.000   Median :2.000   Median :2.000  
##  Mean   :1.478   Mean   :1.253   Mean   :1.695   Mean   :1.856  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q22             q23             q24             q25             q26      
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.00  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000   1st Qu.:1.00  
##  Median :2.000   Median :1.000   Median :2.000   Median :2.000   Median :1.00  
##  Mean   :1.525   Mean   :1.333   Mean   :1.523   Mean   :1.863   Mean   :1.48  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.00  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.00  
##       q27             q28             q29             q30       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.093   Mean   :1.377   Mean   :1.466   Mean   :1.742  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q31             q32             q33             q34       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.055   Mean   :1.153   Mean   :1.126   Mean   :1.666  
##  3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q35             q36             q37             q38       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:2.000  
##  Median :1.000   Median :2.000   Median :1.000   Median :2.000  
##  Mean   :1.198   Mean   :1.694   Mean   :1.211   Mean   :1.815  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q39             q40             q41             q42       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :1.000   Median :1.000   Median :1.000  
##  Mean   :1.742   Mean   :1.329   Mean   :1.366   Mean   :1.285  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q43             q44             q45             q46       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:2.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :2.000   Median :2.000   Median :1.000   Median :1.000  
##  Mean   :1.854   Mean   :1.694   Mean   :1.213   Mean   :1.296  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q47             q48             q49             q50       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :2.000   Median :1.000  
##  Mean   :1.489   Mean   :1.313   Mean   :1.623   Mean   :1.237  
##  3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:1.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q51             q52            q53             q54            q55       
##  Min.   :1.000   Min.   :1.00   Min.   :1.000   Min.   :1.00   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000   1st Qu.:1.00   1st Qu.:1.000  
##  Median :1.000   Median :1.00   Median :2.000   Median :1.00   Median :2.000  
##  Mean   :1.207   Mean   :1.27   Mean   :1.516   Mean   :1.29   Mean   :1.728  
##  3rd Qu.:1.000   3rd Qu.:2.00   3rd Qu.:2.000   3rd Qu.:2.00   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.00   Max.   :2.000   Max.   :2.00   Max.   :2.000  
##       q56             q57             q58             q59       
##  Min.   :1.000   Min.   :1.000   Min.   :1.000   Min.   :1.000  
##  1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000   1st Qu.:1.000  
##  Median :1.000   Median :1.000   Median :1.000   Median :2.000  
##  Mean   :1.246   Mean   :1.402   Mean   :1.347   Mean   :1.603  
##  3rd Qu.:1.000   3rd Qu.:2.000   3rd Qu.:2.000   3rd Qu.:2.000  
##  Max.   :2.000   Max.   :2.000   Max.   :2.000   Max.   :2.000  
##       q60       
##  Min.   :1.000  
##  1st Qu.:1.000  
##  Median :1.000  
##  Mean   :1.457  
##  3rd Qu.:2.000  
##  Max.   :2.000
# Run the Dichotomous Rasch Model
dichot.retail_5000_60 <- RM(retail_5000_60)
## Warning: 
## The following items have no 0-responses:
## q01 q02 q03 q04 q05 q06 q07 q08 q09 q10 q11 q12 q13 q14 q15 q16 q17 q18 q19 q20 q21 q22 q23 q24 q25 q26 q27 q28 q29 q30 q31 q32 q33 q34 q35 q36 q37 q38 q39 q40 q41 q42 q43 q44 q45 q46 q47 q48 q49 q50 q51 q52 q53 q54 q55 q56 q57 q58 q59 q60
## Responses are shifted such that lowest category is 0.
# Request a summary of the model results
summary(dichot.retail_5000_60)
## 
## Results of RM estimation: 
## 
## Call:  RM(X = retail_5000_60) 
## 
## Conditional log-likelihood: -159238.8 
## Number of iterations: 21 
## Number of parameters: 59 
## 
## Item (Category) Difficulty Parameters (eta): with 0.95 CI:
##     Estimate Std. Error lower CI upper CI
## q02   -0.959      0.030   -1.018   -0.899
## q03    0.746      0.032    0.684    0.808
## q04    1.421      0.038    1.346    1.496
## q05    1.436      0.038    1.361    1.511
## q06    0.038      0.029   -0.019    0.094
## q07   -0.440      0.029   -0.496   -0.384
## q08   -0.552      0.029   -0.608   -0.495
## q09    0.306      0.029    0.248    0.363
## q10   -0.779      0.029   -0.836   -0.721
## q11   -1.977      0.039   -2.054   -1.900
## q12   -0.052      0.029   -0.108    0.004
## q13   -0.433      0.029   -0.489   -0.377
## q14    0.168      0.029    0.112    0.225
## q15    1.178      0.035    1.109    1.248
## q16    0.064      0.029    0.008    0.120
## q17   -1.945      0.039   -2.020   -1.869
## q18   -0.151      0.028   -0.206   -0.095
## q19    0.856      0.032    0.793    0.920
## q20   -1.082      0.031   -1.142   -1.021
## q21   -2.057      0.040   -2.136   -1.978
## q22   -0.343      0.028   -0.399   -0.287
## q23    0.464      0.030    0.405    0.523
## q24   -0.335      0.028   -0.391   -0.279
## q25   -2.116      0.041   -2.196   -2.036
## q26   -0.160      0.028   -0.215   -0.104
## q27    2.063      0.048    1.968    2.157
## q28    0.269      0.029    0.212    0.327
## q29   -0.103      0.028   -0.159   -0.047
## q30   -1.321      0.032   -1.385   -1.258
## q31    2.631      0.061    2.511    2.751
## q32    1.496      0.039    1.419    1.572
## q33    1.718      0.042    1.635    1.801
## q34   -0.946      0.030   -1.005   -0.887
## q35    1.176      0.035    1.107    1.245
## q36   -1.075      0.031   -1.135   -1.015
## q37    1.096      0.035    1.029    1.164
## q38   -1.752      0.036   -1.824   -1.681
## q39   -1.321      0.032   -1.385   -1.258
## q40    0.483      0.030    0.424    0.542
## q41    0.318      0.029    0.260    0.376
## q42    0.691      0.031    0.630    0.753
## q43   -2.044      0.040   -2.122   -1.966
## q44   -1.078      0.031   -1.138   -1.018
## q45    1.088      0.034    1.020    1.155
## q46    0.638      0.031    0.577    0.699
## q47   -0.196      0.028   -0.252   -0.141
## q48    0.559      0.031    0.499    0.618
## q49   -0.756      0.029   -0.813   -0.698
## q50    0.948      0.033    0.883    1.013
## q51    1.122      0.035    1.054    1.190
## q52    0.770      0.032    0.708    0.833
## q53   -0.308      0.028   -0.364   -0.252
## q54    0.671      0.031    0.609    0.732
## q55   -1.246      0.032   -1.308   -1.183
## q56    0.894      0.033    0.830    0.958
## q57    0.163      0.029    0.107    0.220
## q58    0.403      0.030    0.345    0.462
## q59   -0.669      0.029   -0.726   -0.612
## q60   -0.068      0.028   -0.124   -0.012
## 
## Item Easiness Parameters (beta) with 0.95 CI:
##          Estimate Std. Error lower CI upper CI
## beta q01   -0.388      0.030   -0.446   -0.330
## beta q02    0.959      0.030    0.899    1.018
## beta q03   -0.746      0.032   -0.808   -0.684
## beta q04   -1.421      0.038   -1.496   -1.346
## beta q05   -1.436      0.038   -1.511   -1.361
## beta q06   -0.038      0.029   -0.094    0.019
## beta q07    0.440      0.029    0.384    0.496
## beta q08    0.552      0.029    0.495    0.608
## beta q09   -0.306      0.029   -0.363   -0.248
## beta q10    0.779      0.029    0.721    0.836
## beta q11    1.977      0.039    1.900    2.054
## beta q12    0.052      0.029   -0.004    0.108
## beta q13    0.433      0.029    0.377    0.489
## beta q14   -0.168      0.029   -0.225   -0.112
## beta q15   -1.178      0.035   -1.248   -1.109
## beta q16   -0.064      0.029   -0.120   -0.008
## beta q17    1.945      0.039    1.869    2.020
## beta q18    0.151      0.028    0.095    0.206
## beta q19   -0.856      0.032   -0.920   -0.793
## beta q20    1.082      0.031    1.021    1.142
## beta q21    2.057      0.040    1.978    2.136
## beta q22    0.343      0.028    0.287    0.399
## beta q23   -0.464      0.030   -0.523   -0.405
## beta q24    0.335      0.028    0.279    0.391
## beta q25    2.116      0.041    2.036    2.196
## beta q26    0.160      0.028    0.104    0.215
## beta q27   -2.063      0.048   -2.157   -1.968
## beta q28   -0.269      0.029   -0.327   -0.212
## beta q29    0.103      0.028    0.047    0.159
## beta q30    1.321      0.032    1.258    1.385
## beta q31   -2.631      0.061   -2.751   -2.511
## beta q32   -1.496      0.039   -1.572   -1.419
## beta q33   -1.718      0.042   -1.801   -1.635
## beta q34    0.946      0.030    0.887    1.005
## beta q35   -1.176      0.035   -1.245   -1.107
## beta q36    1.075      0.031    1.015    1.135
## beta q37   -1.096      0.035   -1.164   -1.029
## beta q38    1.752      0.036    1.681    1.824
## beta q39    1.321      0.032    1.258    1.385
## beta q40   -0.483      0.030   -0.542   -0.424
## beta q41   -0.318      0.029   -0.376   -0.260
## beta q42   -0.691      0.031   -0.753   -0.630
## beta q43    2.044      0.040    1.966    2.122
## beta q44    1.078      0.031    1.018    1.138
## beta q45   -1.088      0.034   -1.155   -1.020
## beta q46   -0.638      0.031   -0.699   -0.577
## beta q47    0.196      0.028    0.141    0.252
## beta q48   -0.559      0.031   -0.618   -0.499
## beta q49    0.756      0.029    0.698    0.813
## beta q50   -0.948      0.033   -1.013   -0.883
## beta q51   -1.122      0.035   -1.190   -1.054
## beta q52   -0.770      0.032   -0.833   -0.708
## beta q53    0.308      0.028    0.252    0.364
## beta q54   -0.671      0.031   -0.732   -0.609
## beta q55    1.246      0.032    1.183    1.308
## beta q56   -0.894      0.033   -0.958   -0.830
## beta q57   -0.163      0.029   -0.220   -0.107
## beta q58   -0.403      0.030   -0.462   -0.345
## beta q59    0.669      0.029    0.612    0.726
## beta q60    0.068      0.028    0.012    0.124
# Plot the Wright Map
plotPImap(dichot.retail_5000_60, main = "Retail Salespeople Wright Map", irug = FALSE)

### Examine Item Parameters:

# View individual item parameters:
difficulty <- dichot.retail_5000_60$etapar
difficulty
##         q02         q03         q04         q05         q06         q07 
## -0.95859562  0.74562586  1.42121919  1.43612710  0.03760367 -0.43990586 
##         q08         q09         q10         q11         q12         q13 
## -0.55177162  0.30585511 -0.77850285 -1.97692039 -0.05236516 -0.43332127 
##         q14         q15         q16         q17         q18         q19 
##  0.16831095  1.17846060  0.06420157 -1.94451902 -0.15061755  0.85625377 
##         q20         q21         q22         q23         q24         q25 
## -1.08185027 -2.05705140 -0.34313841  0.46387370 -0.33496595 -2.11590459 
##         q26         q27         q28         q29         q30         q31 
## -0.15959773  2.06277327  0.26933208 -0.10320536 -1.32136361  2.63089029 
##         q32         q33         q34         q35         q36         q37 
##  1.49572963  1.71796448 -0.94572855  1.17591458 -1.07512271  1.09637490 
##         q38         q39         q40         q41         q42         q43 
## -1.75244994 -1.32136362  0.48313280  0.31810373  0.69129810 -2.04393128 
##         q44         q45         q46         q47         q48         q49 
## -1.07800382  1.08789141  0.63817411 -0.19630850  0.55861749 -0.75584661 
##         q50         q51         q52         q53         q54         q55 
##  0.94827938  1.12207348  0.77018940 -0.30801797  0.67050207 -1.24593438 
##         q56         q57         q58         q59         q60 
##  0.89408746  0.16322975  0.40320156 -0.66895362 -0.06796626
# Calculate the location for item 1:
n.items <- ncol(retail_5000_60)
i1 <- 0 - sum(difficulty[1:(n.items - 1)])
difficulty.all <- c(i1, difficulty[c(1:(n.items - 1))])
difficulty.all
##                     q02         q03         q04         q05         q06 
##  0.38793241 -0.95859562  0.74562586  1.42121919  1.43612710  0.03760367 
##         q07         q08         q09         q10         q11         q12 
## -0.43990586 -0.55177162  0.30585511 -0.77850285 -1.97692039 -0.05236516 
##         q13         q14         q15         q16         q17         q18 
## -0.43332127  0.16831095  1.17846060  0.06420157 -1.94451902 -0.15061755 
##         q19         q20         q21         q22         q23         q24 
##  0.85625377 -1.08185027 -2.05705140 -0.34313841  0.46387370 -0.33496595 
##         q25         q26         q27         q28         q29         q30 
## -2.11590459 -0.15959773  2.06277327  0.26933208 -0.10320536 -1.32136361 
##         q31         q32         q33         q34         q35         q36 
##  2.63089029  1.49572963  1.71796448 -0.94572855  1.17591458 -1.07512271 
##         q37         q38         q39         q40         q41         q42 
##  1.09637490 -1.75244994 -1.32136362  0.48313280  0.31810373  0.69129810 
##         q43         q44         q45         q46         q47         q48 
## -2.04393128 -1.07800382  1.08789141  0.63817411 -0.19630850  0.55861749 
##         q49         q50         q51         q52         q53         q54 
## -0.75584661  0.94827938  1.12207348  0.77018940 -0.30801797  0.67050207 
##         q55         q56         q57         q58         q59         q60 
## -1.24593438  0.89408746  0.16322975  0.40320156 -0.66895362 -0.06796626
# Alternative method to calculate item difficulty (easiness * -1):
difficulty2 <- dichot.retail_5000_60$betapar * -1
difficulty2
##    beta q01    beta q02    beta q03    beta q04    beta q05    beta q06 
##  0.38793241 -0.95859562  0.74562586  1.42121919  1.43612710  0.03760367 
##    beta q07    beta q08    beta q09    beta q10    beta q11    beta q12 
## -0.43990586 -0.55177162  0.30585511 -0.77850285 -1.97692039 -0.05236516 
##    beta q13    beta q14    beta q15    beta q16    beta q17    beta q18 
## -0.43332127  0.16831095  1.17846060  0.06420157 -1.94451902 -0.15061755 
##    beta q19    beta q20    beta q21    beta q22    beta q23    beta q24 
##  0.85625377 -1.08185027 -2.05705140 -0.34313841  0.46387370 -0.33496595 
##    beta q25    beta q26    beta q27    beta q28    beta q29    beta q30 
## -2.11590459 -0.15959773  2.06277327  0.26933208 -0.10320536 -1.32136361 
##    beta q31    beta q32    beta q33    beta q34    beta q35    beta q36 
##  2.63089029  1.49572963  1.71796448 -0.94572855  1.17591458 -1.07512271 
##    beta q37    beta q38    beta q39    beta q40    beta q41    beta q42 
##  1.09637490 -1.75244994 -1.32136362  0.48313280  0.31810373  0.69129810 
##    beta q43    beta q44    beta q45    beta q46    beta q47    beta q48 
## -2.04393128 -1.07800382  1.08789141  0.63817411 -0.19630850  0.55861749 
##    beta q49    beta q50    beta q51    beta q52    beta q53    beta q54 
## -0.75584661  0.94827938  1.12207348  0.77018940 -0.30801797  0.67050207 
##    beta q55    beta q56    beta q57    beta q58    beta q59    beta q60 
## -1.24593438  0.89408746  0.16322975  0.40320156 -0.66895362 -0.06796626
# View standard errors for item parameters:
dichot.retail_5000_60$se.beta
##  [1] 0.02970309 0.03015636 0.03167038 0.03812364 0.03831056 0.02864922
##  [7] 0.02854284 0.02873696 0.02937977 0.02938829 0.03909749 0.02851330
## [13] 0.02853399 0.02894393 0.03536187 0.02869992 0.03867949 0.02842647
## [19] 0.03247198 0.03081340 0.04017345 0.02844210 0.03004270 0.02843642
## [25] 0.04100300 0.02842172 0.04820033 0.02925135 0.02846025 0.03240657
## [31] 0.06119803 0.03907918 0.04224970 0.03009399 0.03533562 0.03077474
## [37] 0.03454467 0.03639665 0.03240665 0.03013553 0.02942489 0.03131089
## [43] 0.03999314 0.03079134 0.03446327 0.03098067 0.02840788 0.03052526
## [49] 0.02930754 0.03321149 0.03479432 0.03184029 0.02842092 0.03117918
## [55] 0.03185880 0.03276790 0.02893028 0.02976737 0.02903009 0.02849516
# Examine descriptive statistics for item parameters:
summary(difficulty.all)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## -2.1159 -0.7615  0.0509  0.0000  0.7518  2.6309
sd(difficulty.all)
## [1] 1.088567
summary(dichot.retail_5000_60$se.beta)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.02841 0.02894 0.03078 0.03275 0.03461 0.06120
sd(dichot.retail_5000_60$se.beta)
## [1] 0.005752056
hist(difficulty.all, main = "Histogram of Item Difficulty Estimates for the Retail Salespeople Data",
     xlab = "Item Difficulty Estimates in Logits")

### Inserted this from the book page 17
###items.to.plot <- c(1:3)
plotICC(dichot.retail_5000_60, ask = FALSE)

personnel.locations <- person.parameter(dichot.retail_5000_60)
achievement <- personnel.locations$theta.table
achievement$id <-rownames(achievement)
# Add standard errors to person achievement object:
se <- as.data.frame(personnel.locations$se.theta$NAgroup1)
se$id <- rownames(se)
names(se) <- c("person_se", "id")

achievement.with.se <- merge(achievement, se, by = "id" )
# Examine descriptive statistics for person parameters:
summary(achievement)
##  Person Parameter      NAgroup  Interpolated         id           
##  Min.   :-3.44748   Min.   :1   Mode :logical   Length:5000       
##  1st Qu.:-0.49516   1st Qu.:1   FALSE:5000      Class :character  
##  Median :-0.23915   Median :1                   Mode  :character  
##  Mean   :-0.24889   Mean   :1                                     
##  3rd Qu.: 0.01157   3rd Qu.:1                                     
##  Max.   : 2.83268   Max.   :1
hist(achievement$`Person Parameter`, main = "Histogram of Person Achievement Estimates for the Retail Salespersons Data",
     xlab = "Person Achievement Estimates in Logits")

# Examine item fit statistics:
### Why the switch to person locations?
person.locations <- person.parameter(dichot.retail_5000_60)
item.fit <- itemfit(personnel.locations)
item.fit
## 
## Itemfit Statistics: 
##        Chisq   df p-value Outfit MSQ Infit MSQ Outfit t Infit t Discrim
## q01 4741.977 4999   0.995      0.948     0.947   -4.476  -5.526   0.316
## q02 5089.216 4999   0.183      1.018     1.009    1.435   0.844   0.081
## q03 5089.245 4999   0.183      1.018     0.995    1.058  -0.336   0.111
## q04 4923.009 4999   0.776      0.985     0.971   -0.529  -1.153   0.146
## q05 4973.003 4999   0.600      0.995     0.982   -0.176  -0.712   0.119
## q06 5014.955 4999   0.434      1.003     1.002    0.385   0.248   0.140
## q07 5141.282 4999   0.078      1.028     1.024    4.018   4.094   0.069
## q08 4987.242 4999   0.544      0.997     0.994   -0.326  -0.831   0.146
## q09 4735.826 4999   0.996      0.947     0.951   -5.034  -5.698   0.316
## q10 5279.618 4999   0.003      1.056     1.043    5.437   4.781  -0.027
## q11 4471.482 4999   1.000      0.894     0.940   -3.711  -2.331   0.265
## q12 5068.031 4999   0.244      1.014     1.010    1.899   1.758   0.104
## q13 5094.452 4999   0.170      1.019     1.019    2.709   3.181   0.069
## q14 5159.002 4999   0.056      1.032     1.022    3.466   3.006   0.063
## q15 4904.417 4999   0.828      0.981     0.978   -0.789  -1.041   0.154
## q16 5009.707 4999   0.455      1.002     1.001    0.244   0.125   0.142
## q17 4925.513 4999   0.768      0.985     0.968   -0.510  -1.264   0.124
## q18 5288.021 4999   0.002      1.058     1.052    8.516   9.547  -0.026
## q19 4605.146 4999   1.000      0.921     0.947   -4.355  -3.417   0.285
## q20 5267.538 4999   0.004      1.054     1.031    3.731   2.474   0.009
## q21 5295.039 4999   0.002      1.059     0.995    1.871  -0.158   0.015
## q22 5064.900 4999   0.254      1.013     1.011    1.974   1.943   0.114
## q23 5060.920 4999   0.267      1.012     1.007    0.957   0.625   0.117
## q24 4895.754 4999   0.849      0.979     0.982   -3.211  -3.330   0.197
## q25 5295.367 4999   0.002      1.059     0.996    1.802  -0.126   0.001
## q26 4855.501 4999   0.925      0.971     0.973   -4.414  -5.004   0.238
## q27 4695.935 4999   0.999      0.939     0.963   -1.420  -0.977   0.148
## q28 4750.570 4999   0.994      0.950     0.963   -4.954  -4.470   0.253
## q29 5163.025 4999   0.052      1.033     1.031    4.713   5.581   0.045
## q30 4697.624 4999   0.999      0.940     0.954   -3.476  -2.981   0.261
## q31 4938.815 4999   0.725      0.988     0.963   -0.185  -0.688   0.085
## q32 4815.864 4999   0.968      0.963     0.972   -1.222  -1.054   0.140
## q33 4648.772 4999   1.000      0.930     0.961   -2.043  -1.284   0.176
## q34 5195.323 4999   0.026      1.039     1.024    3.160   2.161   0.023
## q35 4981.598 4999   0.567      0.996     0.979   -0.145  -0.998   0.127
## q36 4688.654 4999   0.999      0.938     0.952   -4.534  -3.915   0.279
## q37 4937.148 4999   0.731      0.987     0.989   -0.549  -0.571   0.105
## q38 4953.218 4999   0.675      0.991     0.978   -0.365  -0.992   0.121
## q39 4704.759 4999   0.999      0.941     0.962   -3.392  -2.409   0.246
## q40 5262.402 4999   0.005      1.052     1.035    3.972   3.213  -0.007
## q41 4753.368 4999   0.994      0.951     0.959   -4.628  -4.703   0.289
## q42 4597.421 4999   1.000      0.919     0.942   -5.161  -4.399   0.333
## q43 4733.648 4999   0.996      0.947     0.947   -1.749  -1.952   0.189
## q44 4871.450 4999   0.900      0.974     0.974   -1.840  -2.079   0.187
## q45 4717.307 4999   0.998      0.943     0.963   -2.552  -1.912   0.227
## q46 5026.462 4999   0.389      1.005     0.992    0.352  -0.593   0.139
## q47 5183.962 4999   0.033      1.037     1.035    5.588   6.503   0.027
## q48 4865.622 4999   0.910      0.973     0.982   -1.924  -1.506   0.168
## q49 4978.804 4999   0.578      0.996     0.996   -0.428  -0.499   0.140
## q50 4736.384 4999   0.996      0.947     0.963   -2.661  -2.194   0.217
## q51 4795.565 4999   0.980      0.959     0.974   -1.785  -1.309   0.162
## q52 5230.739 4999   0.011      1.046     1.025    2.643   1.698   0.003
## q53 4983.180 4999   0.560      0.997     1.000   -0.518  -0.087   0.144
## q54 5234.667 4999   0.010      1.047     1.023    2.947   1.691   0.019
## q55 5050.161 4999   0.303      1.010     1.003    0.610   0.202   0.082
## q56 5225.706 4999   0.013      1.045     1.004    2.320   0.236   0.057
## q57 4940.192 4999   0.720      0.988     0.995   -1.327  -0.708   0.136
## q58 5144.680 4999   0.074      1.029     1.024    2.408   2.371   0.027
## q59 4894.813 4999   0.851      0.979     0.982   -2.383  -2.353   0.208
## q60 5360.578 4999   0.000      1.072     1.059   10.004  10.172  -0.064
## Calculate reliability of item separation:
# Get Item scores
ItemScores <- colSums(retail_5000_labels)
ItemScores
## Position      Age   Gender  Marital      q01      q02      q03      q04 
##    12329    23363     9510     7944     6750     8344     6373     5813 
##      q05      q06      q07      q08      q09      q10      q11      q12 
##     5803     7159     7742     7877     6843     8143     9229     7268 
##      q13      q14      q15      q16      q17      q18      q19      q20 
##     7734     7003     5990     7127     9208     7388     6267     8475 
##      q21      q22      q23      q24      q25      q26      q27      q28 
##     9279     7624     6666     7614     9314     7399     5466     6885 
##      q29      q30      q31      q32      q33      q34      q35      q36 
##     7330     8712     5276     5764     5632     8330     5992     8468 
##      q37      q38      q39      q40      q41      q42      q43      q44 
##     6056     9074     8712     6645     6829     6427     9271     8471 
##      q45      q46      q47      q48      q49      q50      q51      q52 
##     6063     6481     7444     6564     8117     6183     6035     6349 
##      q53      q54      q55      q56      q57      q58      q59      q60 
##     7581     6448     8640     6232     7009     6733     8016     7287
# Get Item SD
ItemSD <- apply(retail_5000_labels,2,sd)
ItemSD
##  Position       Age    Gender   Marital       q01       q02       q03       q04 
## 0.5470742 1.6532259 0.2973444 0.4921006 0.4770173 0.4706919 0.4463571 0.3690372 
##       q05       q06       q07       q08       q09       q10       q11       q12 
## 0.3671983 0.4953765 0.4977017 0.4943316 0.4824734 0.4832274 0.3611765 0.4978922 
##       q13       q14       q15       q16       q17       q18       q19       q20 
## 0.4978547 0.4900690 0.3985320 0.4944530 0.3651522 0.4995479 0.4350015 0.4604535 
##       q21       q22       q23       q24       q25       q26       q27       q28 
## 0.3513275 0.4994345 0.4714045 0.4995298 0.3440928 0.4996418 0.2907416 0.4846834 
##       q29       q30       q31       q32       q33       q34       q35       q36 
## 0.4988926 0.4373563 0.2283931 0.3598306 0.3323329 0.4716869 0.3988349 0.4610440 
##       q37       q38       q39       q40       q41       q42       q43       q44 
## 0.4082008 0.3884986 0.4373563 0.4698970 0.4817019 0.4516499 0.3529409 0.4607915 
##       q45       q46       q47       q48       q49       q50       q51       q52 
## 0.4091879 0.4566260 0.4999245 0.4636800 0.4845817 0.4250371 0.4051960 0.4439002 
##       q53       q54       q55       q56       q57       q58       q59       q60 
## 0.4997875 0.4536221 0.4450344 0.4309573 0.4903110 0.4759346 0.4892828 0.4982318
# Calculate the se of the Item
ItemSE <- ItemSD/sqrt(length(ItemSD))
ItemSE
##   Position        Age     Gender    Marital        q01        q02        q03 
## 0.06838428 0.20665324 0.03716805 0.06151257 0.05962716 0.05883649 0.05579464 
##        q04        q05        q06        q07        q08        q09        q10 
## 0.04612965 0.04589979 0.06192206 0.06221271 0.06179145 0.06030918 0.06040343 
##        q11        q12        q13        q14        q15        q16        q17 
## 0.04514706 0.06223652 0.06223184 0.06125863 0.04981650 0.06180662 0.04564402 
##        q18        q19        q20        q21        q22        q23        q24 
## 0.06244349 0.05437518 0.05755668 0.04391594 0.06242932 0.05892556 0.06244123 
##        q25        q26        q27        q28        q29        q30        q31 
## 0.04301160 0.06245522 0.03634270 0.06058542 0.06236157 0.05466953 0.02854913 
##        q32        q33        q34        q35        q36        q37        q38 
## 0.04497882 0.04154161 0.05896086 0.04985436 0.05763050 0.05102510 0.04856232 
##        q39        q40        q41        q42        q43        q44        q45 
## 0.05466953 0.05873712 0.06021274 0.05645624 0.04411761 0.05759894 0.05114849 
##        q46        q47        q48        q49        q50        q51        q52 
## 0.05707824 0.06249057 0.05796000 0.06057271 0.05312964 0.05064951 0.05548752 
##        q53        q54        q55        q56        q57        q58        q59 
## 0.06247343 0.05670276 0.05562930 0.05386966 0.06128887 0.05949182 0.06116035 
##        q60 
## 0.06227897
# compute the Observed Variance (also known as Total Person Variability or Squared Standard Deviation)
SSD.ItemScores <- var(ItemScores)
SSD.ItemScores
## [1] 5626823
# compute the Mean Square Measurement error (also known as Model Error variance)
Item.MSE <- sum((ItemSE)^2) / length(ItemSE)
Item.MSE
## [1] 0.003738394
# compute the Item Separation Reliability
item.separation.reliability <- (SSD.ItemScores-Item.MSE) / SSD.ItemScores
item.separation.reliability
## [1] 1
###Item Separability matches the book. 
## Examine person fit statistics:
person.fit <- personfit(personnel.locations)
summary(person.fit$p.infitMSQ)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.6059  0.8768  0.9718  0.9944  1.0895  1.8874
summary(person.fit$p.outfitMSQ)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.5377  0.8225  0.9377  0.9933  1.1118  2.9633
# Examine person reliability:
person_rel <- SepRel(personnel.locations)
person_rel$sep.rel
## [1] 0.5219916
### Summarize the results in tables
summary.table.statistics <- c("Logit Scale Location Mean",
                              "Logit Scale Location SD",
                              "Standard Error Mean",
                              "Standard Error SD",
                              "Outfit MSE Mean",
                              "Outfit MSE SD",
                              "Infit MSE Mean",
                              "Infit MSE SD",
                              "Std. Outfit Mean",
                              "Std. Outfit SD",
                              "Std. Infit Mean",
                              "Std. Infit SD",
                              "Reliability of Separation")
item.summary.results <- rbind(mean(difficulty.all),
                              sd(difficulty.all),
                              mean(dichot.retail_5000_60$se.beta),
                              sd(dichot.retail_5000_60$se.beta),
                              mean(item.fit$i.outfitMSQ),
                              sd(item.fit$i.outfitMSQ),
                              mean(item.fit$i.infitMSQ),
                              sd(item.fit$i.infitMSQ),
                              mean(item.fit$i.outfitZ),
                              sd(item.fit$i.outfitZ),
                              mean(item.fit$i.infitMSQ),
                              sd(item.fit$i.infitZ),
                              item.separation.reliability)
person.summary.results <- rbind(mean(achievement.with.se$`Person Parameter`),
                                sd(achievement.with.se$`Person Parameter`),
                                mean(achievement.with.se$person_se, na.rm = TRUE),
                                sd(achievement.with.se$person_se, na.rm = TRUE),
                                mean(person.fit$p.outfitMSQ),
                                sd(person.fit$p.outfitMSQ),
                                mean(person.fit$p.infitMSQ),
                                sd(person.fit$p.infitMSQ),
                                mean(person.fit$p.outfitZ),
                                sd(person.fit$p.outfitZ),
                                mean(person.fit$p.infitZ),
                                sd(person.fit$p.infitZ),
                                person_rel$sep.rel)
# Round the values for presentation in a table:
item.summary.results_rounded <- round(item.summary.results, digits = 2)

person.summary.results_rounded <- round(person.summary.results, digits = 2)

Table1 <- cbind.data.frame(summary.table.statistics,
                           item.summary.results_rounded,
                           person.summary.results_rounded)
### Tables 1 & 2

# add descriptive column labels:
names(Table1) <- c("Statistic", "Items", "Persons")
print.data.frame(Table1, row.names = FALSE)
##                  Statistic Items Persons
##  Logit Scale Location Mean  0.00   -0.25
##    Logit Scale Location SD  1.09    0.43
##        Standard Error Mean  0.03    0.29
##          Standard Error SD  0.01    0.01
##            Outfit MSE Mean  0.99    0.99
##              Outfit MSE SD  0.04    0.25
##             Infit MSE Mean  0.99    0.99
##               Infit MSE SD  0.03    0.16
##           Std. Outfit Mean  0.02   -0.10
##             Std. Outfit SD  3.31    1.32
##            Std. Infit Mean  0.99   -0.08
##              Std. Infit SD  3.22    1.35
##  Reliability of Separation  1.00    0.52
## Item calibration table:

# Calculate the proportion correct for each task:
PropCorrect <- apply(retail_5000_60, 2, mean)

# Calculate the proportion correct for each task:
PropCorrect <- apply(retail_5000_60, 2, mean)

# Combine item calibration results in a table:
Table2 <- cbind.data.frame(colnames(retail_5000_60),
                           PropCorrect,
                           difficulty.all,
                           dichot.retail_5000_60$se.beta,
                           item.fit$i.outfitMSQ,
                           item.fit$i.outfitZ,
                           item.fit$i.infitMSQ,
                           item.fit$i.infitZ)
names(Table2) <- c("Task ID", "Proportion Correct", "Item Location","Item SE","Outfit MSE","Std. Outfit", "Infit MSE","Std. Infit")

# Sort Table 2 by Item difficulty:
Table2 <- Table2[order(-Table2$`Item Location`),]

# Round the numeric values (all columns except the first one) to 2 digits:
Table2[, -1] <- round(Table2[,-1], digits = 2)
print.data.frame(Table2, row.names = FALSE)
##  Task ID Proportion Correct Item Location Item SE Outfit MSE Std. Outfit
##      q31               1.06          2.63    0.06       0.99       -0.19
##      q27               1.09          2.06    0.05       0.94       -1.42
##      q33               1.13          1.72    0.04       0.93       -2.04
##      q32               1.15          1.50    0.04       0.96       -1.22
##      q05               1.16          1.44    0.04       0.99       -0.18
##      q04               1.16          1.42    0.04       0.98       -0.53
##      q15               1.20          1.18    0.04       0.98       -0.79
##      q35               1.20          1.18    0.04       1.00       -0.14
##      q51               1.21          1.12    0.03       0.96       -1.79
##      q37               1.21          1.10    0.03       0.99       -0.55
##      q45               1.21          1.09    0.03       0.94       -2.55
##      q50               1.24          0.95    0.03       0.95       -2.66
##      q56               1.25          0.89    0.03       1.05        2.32
##      q19               1.25          0.86    0.03       0.92       -4.35
##      q52               1.27          0.77    0.03       1.05        2.64
##      q03               1.27          0.75    0.03       1.02        1.06
##      q42               1.29          0.69    0.03       0.92       -5.16
##      q54               1.29          0.67    0.03       1.05        2.95
##      q46               1.30          0.64    0.03       1.01        0.35
##      q48               1.31          0.56    0.03       0.97       -1.92
##      q40               1.33          0.48    0.03       1.05        3.97
##      q23               1.33          0.46    0.03       1.01        0.96
##      q58               1.35          0.40    0.03       1.03        2.41
##      q01               1.35          0.39    0.03       0.95       -4.48
##      q41               1.37          0.32    0.03       0.95       -4.63
##      q09               1.37          0.31    0.03       0.95       -5.03
##      q28               1.38          0.27    0.03       0.95       -4.95
##      q14               1.40          0.17    0.03       1.03        3.47
##      q57               1.40          0.16    0.03       0.99       -1.33
##      q16               1.43          0.06    0.03       1.00        0.24
##      q06               1.43          0.04    0.03       1.00        0.38
##      q12               1.45         -0.05    0.03       1.01        1.90
##      q60               1.46         -0.07    0.03       1.07       10.00
##      q29               1.47         -0.10    0.03       1.03        4.71
##      q18               1.48         -0.15    0.03       1.06        8.52
##      q26               1.48         -0.16    0.03       0.97       -4.41
##      q47               1.49         -0.20    0.03       1.04        5.59
##      q53               1.52         -0.31    0.03       1.00       -0.52
##      q24               1.52         -0.33    0.03       0.98       -3.21
##      q22               1.52         -0.34    0.03       1.01        1.97
##      q13               1.55         -0.43    0.03       1.02        2.71
##      q07               1.55         -0.44    0.03       1.03        4.02
##      q08               1.58         -0.55    0.03       1.00       -0.33
##      q59               1.60         -0.67    0.03       0.98       -2.38
##      q49               1.62         -0.76    0.03       1.00       -0.43
##      q10               1.63         -0.78    0.03       1.06        5.44
##      q34               1.67         -0.95    0.03       1.04        3.16
##      q02               1.67         -0.96    0.03       1.02        1.44
##      q36               1.69         -1.08    0.03       0.94       -4.53
##      q44               1.69         -1.08    0.03       0.97       -1.84
##      q20               1.70         -1.08    0.03       1.05        3.73
##      q55               1.73         -1.25    0.03       1.01        0.61
##      q30               1.74         -1.32    0.03       0.94       -3.48
##      q39               1.74         -1.32    0.03       0.94       -3.39
##      q38               1.81         -1.75    0.04       0.99       -0.37
##      q17               1.84         -1.94    0.04       0.99       -0.51
##      q11               1.85         -1.98    0.04       0.89       -3.71
##      q43               1.85         -2.04    0.04       0.95       -1.75
##      q21               1.86         -2.06    0.04       1.06        1.87
##      q25               1.86         -2.12    0.04       1.06        1.80
##  Infit MSE Std. Infit
##       0.96      -0.69
##       0.96      -0.98
##       0.96      -1.28
##       0.97      -1.05
##       0.98      -0.71
##       0.97      -1.15
##       0.98      -1.04
##       0.98      -1.00
##       0.97      -1.31
##       0.99      -0.57
##       0.96      -1.91
##       0.96      -2.19
##       1.00       0.24
##       0.95      -3.42
##       1.02       1.70
##       1.00      -0.34
##       0.94      -4.40
##       1.02       1.69
##       0.99      -0.59
##       0.98      -1.51
##       1.04       3.21
##       1.01       0.63
##       1.02       2.37
##       0.95      -5.53
##       0.96      -4.70
##       0.95      -5.70
##       0.96      -4.47
##       1.02       3.01
##       0.99      -0.71
##       1.00       0.13
##       1.00       0.25
##       1.01       1.76
##       1.06      10.17
##       1.03       5.58
##       1.05       9.55
##       0.97      -5.00
##       1.03       6.50
##       1.00      -0.09
##       0.98      -3.33
##       1.01       1.94
##       1.02       3.18
##       1.02       4.09
##       0.99      -0.83
##       0.98      -2.35
##       1.00      -0.50
##       1.04       4.78
##       1.02       2.16
##       1.01       0.84
##       0.95      -3.91
##       0.97      -2.08
##       1.03       2.47
##       1.00       0.20
##       0.95      -2.98
##       0.96      -2.41
##       0.98      -0.99
##       0.97      -1.26
##       0.94      -2.33
##       0.95      -1.95
##       1.00      -0.16
##       1.00      -0.13
## Person calibration table:

# Calculate proportion correct for persons:
PersonPropCorrect <- apply(personnel.locations$X.ex, 1, mean)

# Combine person calibration results in a table:
PersonPropCorrect <- apply(personnel.locations$X.ex, 1, mean)

# Combine person calibration results in a table:
Table3 <- cbind.data.frame(achievement.with.se$id,
                           PersonPropCorrect,
                           achievement.with.se$`Person Parameter`,
                           achievement.with.se$person_se,
                           person.fit$p.outfitMSQ,
                           person.fit$p.outfitZ,
                           person.fit$p.infitMSQ,
                           person.fit$p.infitZ)

names(Table3) <- c("Person ID", "Proportion Correct", "Person Location","Person SE","Outfit MSE","Std. Outfit", "Infit MSE","Std. Infit")

# Round the numeric values (all columns except the first one) to 2 digits:
Table3[, -1] <- round(Table3[,-1], digits = 2)
print.data.frame(Table3 [1:6, ], row.names = FALSE)
##  Person ID Proportion Correct Person Location Person SE Outfit MSE Std. Outfit
##          1               0.55            0.26      0.29       1.62        3.21
##         10               0.40           -0.41      0.29       0.85       -0.85
##        100               0.40           -0.76      0.30       1.46        2.31
##       1000               0.42            0.09      0.29       0.68       -2.02
##       1001               0.25           -0.32      0.29       0.88       -0.32
##       1002               0.42           -0.16      0.29       0.96       -0.17
##  Infit MSE Std. Infit
##       1.41       3.34
##       0.90      -0.81
##       1.10       0.85
##       0.75      -2.24
##       1.01       0.11
##       1.00       0.04
write.csv(Table3, file = "Table3.CSV", row.names = FALSE)
write.csv(Table2, file = "Table2.CSV", row.names = FALSE)
write.csv(Table1, file = "Table1.CSV", row.names = FALSE)