set.seed(1)
n <- 1e6 #number of pupils
k <- 20 #number of items
b <- runif (k, -1, 1) #item difficulties
x <- 9 #target test score
#Simulation for m = 5 proposals
m <- 5 #number of samples
px1 <- rep (0, k + 1) #mixture distribution for m = 5 proposals
for (i in 1:n) {
#Generate m = 5 proposals
t <- rnorm (m) #proposal values
x.ast <- rep (0, m) #proposal test scores
for (i in 1:k)
x.ast <- x.ast + 1*(rlogis (m) <= (t - b[i]))
#Select one for which x.ast is most like x (target test score)
x.ast <- x.ast[which (abs(x.ast-x) == min(abs(x.ast-x)))]
#Update mixture distribution (scores range from 0 to k)
px1[x.ast+1] <- px1[x.ast+1] + 1/n
}
#Simulation for m = 20 proposals
m <- 20 #number of samples
px2 <- rep (0, k + 1) #mixture distribution for m = 5 proposals
for (i in 1:n) {
#Generate m = 20 proposals
t <- rnorm (m) #proposal values
x.ast <- rep (0, m) #proposal test scores
for (i in 1:k)
x.ast <- x.ast + 1*(rlogis (m) <= (t - b[i]))
#Select one for which x.ast is most like x (target test score)
x.ast <- x.ast[which (abs(x.ast-x) == min(abs(x.ast-x)))]
#Update mixture distribution (scores range from 0 to k)
px2[x.ast+1] <- px2[x.ast+1] + 1/n
}
#Figure 2
par (mfrow = c(1, 2), cex.main = 1.5, mar = c(4, 5, 0, 1) + 0.1,
mgp = c(3.5, 1, 0), cex.lab = 1.5, font.lab = 2, cex.axis = 1.3,
bty = "n", las = 1)
plot(0:k, px1, ylim = c(0,1) , xlim = c(0,20), lwd = 2, lty = 1,
xlab = " ", ylab = " ", pch = 20)
mtext(expression(x["+"]),1, line = 3, cex = 1.5, font = 2)
mtext(expression(paste(pi,"(",x["+"],")")), 2, line = 3.5, cex = 1.5,
font = 2, las = 0)
segments (0,0.2,20,0.2,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.4,20,0.4,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.6,20,0.6,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.8,20,0.8,lty = 2, col = "gray", lwd = 0.5)
points (x, px1[x+1], pch = 19, col = "blue") #scores range from 0 to k
plot(0:k, px2, ylim = c(0,1) , xlim = c(0,20), lwd = 2, lty = 1,
xlab = " ", ylab = " ", pch = 20)
mtext(expression(x["+"]),1, line = 3, cex = 1.5, font = 2)
mtext(expression(paste(pi,"(",x["+"],")")), 2, line = 3.5, cex = 1.5,
font = 2, las = 0)
segments (0,0.2,20,0.2,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.4,20,0.4,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.6,20,0.6,lty = 2, col = "gray", lwd = 0.5)
segments (0,0.8,20,0.8,lty = 2, col = "gray", lwd = 0.5)
points (x, px2[x+1], pch = 19, col = "blue") #scores range from 0 to k