# Install required R package: ## install.packages("PerFit") ## install.packages("xtable") # Load R packages: library("PerFit") library("xtable") library("mirt") library("ltm") # Load data: data("IntelligenceData", package = "PerFit") data("PhysFuncData", package = "PerFit") # Reproduce the manuscript results by section/page: ############################## # Section 2.2, p. 4: Table 1 # ############################## p.vals <- order(apply(IntelligenceData, 2, mean), decreasing = TRUE) scores <- IntelligenceData[c(6, 584, 832, 772), p.vals] rownames(scores) <- c("Test taker A", "Test taker B", "Test taker C", "Test taker D") # print(xtable(scores, digits=0, caption = "Item score patterns corresponding to the PRFs displayed in Figure~\\ref{PRFs}. Items are in increasing order of difficulty.", label = "PRFscores"), include.colnames = FALSE, hline.after = c(0, nrow(scores)), table.placement = c("t")) scores ############################### # Section 2.2, p. 5: Figure 1 # ############################### par(mfrow = c(2, 2)) x1 <- PRFplot(IntelligenceData, 6, VarBands = FALSE, title = "Test Taker A", Xlabel = "", Ycex = 1, Tcex = 1, message = FALSE) x2 <- PRFplot(IntelligenceData, 584, VarBands = FALSE, title = "Test Taker B", Ylabel = "", Xlabel = "", Tcex = 1, message = FALSE) x3 <- PRFplot(IntelligenceData, 832, VarBands = FALSE, title = "Test Taker C", Xcex = 1, Ycex = 1, Tcex = 1, Xlabel = "Item difficulty", message = FALSE) x4 <- PRFplot(IntelligenceData, 772, VarBands = FALSE, title = "Test Taker D", Ylabel = "", Xcex = 1, Tcex = 1, Xlabel = "Item difficulty", message = FALSE) par(mfrow=c(1,1)) ############################################################# # Section 3.1, p. 10: The 'Ht' PFS on the intelligence data # ############################################################# Ht(IntelligenceData) ############################################################################### # Section 3.1, pp. 12: The 'lz' PFS with item parameters estimated in mirt # ############################################################################### mod <- mirt(IntelligenceData, 1) ip.mirt <- coef(mod, IRTpars = TRUE, simplify = TRUE, digits = Inf)$items[, c("a", "b", "g")] lz.out <- lz(IntelligenceData, IP = ip.mirt) ######################################################################### # Section 3.1, p. 13: The 'U3poly' PFS on the physical functioning data # ######################################################################### U3poly.out <- U3poly(PhysFuncData, Ncat = 3) U3poly.out$PFscores ######################################################################### # Section 3.1, p. 13: The 'lzpoly' PFS on the physical functioning data # ######################################################################### IP.est <- coef(grm(PhysFuncData, constrained = FALSE, IRT.param = TRUE)) lzpoly.out <- lzpoly(PhysFuncData, Ncat = 3, IP = IP.est) lzpoly.out$PFscores ######################################################################## # Section 3.2, p. 14: The PerFit.PFS function on the intelligence data # ######################################################################## PFS.out <- PerFit.PFS(IntelligenceData, method = c("U3", "lzstar", "Ht"), simplified = TRUE) PFS.out ####################################################################### # Section 3.2, p. 14: The PerFit.SE function on the intelligence data # ####################################################################### Ht.out <- Ht(IntelligenceData) Ht.SE <- PerFit.SE(Ht.out) Ht.SE ##################################################################### # Section 3.2, p. 16: The 'cutoff' function on the intelligence data # ##################################################################### set.seed(123) cutoff(Ht.out, Blvl = 0.10) ########################################################################### # Section 3.2, p. 17: The 'flagged.resp' function on the intelligence data# ########################################################################### U3.out <- U3(IntelligenceData) set.seed(72) U3.cutoff <- cutoff(U3.out, Blvl = .01) flagged.resp(U3.out, cutoff.obj = U3.cutoff, ord = TRUE) ###################################################### # Section 3.2, p. 18: The 'summary' method for PerFit# ###################################################### summary(U3.out, cutoff.obj = U3.cutoff) ################################ # Section 3.2, p. 20: Figure 2 # ################################ PRFplot(IntelligenceData, 832, VarBands = TRUE, VarBands.area = TRUE, message = FALSE) ################################ # Section 3.2, p. 22: Figure 3 # ################################ set.seed(54) plot(U3poly(PhysFuncData, Ncat = 3), Blvl = 0.01)