用R写了一下计算item characteristic curve和画item characteristic curve的代码代码,代码如下:
##R function for item characteristic curve calculations
icccal <- function(b, a, c) {
if (missing(c)) c <- 0#对是否输入c进行判断,没有则赋值0
if (missing(a)) a <- 1#对是否输入a进行判断,没有则赋值1
theta <- seq(-3, 3, 1)
L <- a * (theta - b)
expnl <- exp(-L)
opexpnl <- 1 + expnl
P <- c + (1 - c) / opexpnl#三参数模型
data.frame(theta, L, expnl, opexpnl, P)
}
#R function for plotting an item characteristic curve
icc <- function(b, a, c) {
if (missing(c)) c <- 0 #对是否输入c进行判断,没有则赋值0
if (missing(a)) a <- 1#对是否有输入a进行判断,没有则赋值1
par(lab=c(7,3,3))
theta <- seq(-3, 3, .1)
P <- c + (1 - c) / (1 + exp(-a * (theta - b)))#三参数模型
plot(theta, P, type="l", xlim=c(-3,3), ylim=c(0,1),
xlab="Ability", ylab="Probability of Correct Response")
thetai <- b
pthetai <- c + (1 - c) / (1 + exp(-a * (thetai - b)))
vliney <- seq(0, pthetai, .01)
vlinex <- b + vliney * 0
lines(vlinex, vliney, lty=2)
}
计算的结果如下:
> icccal(-1,1.7)
theta L expnl opexpnl P
1 -3 -3.4 29.964100047 30.964100 0.03229546
2 -2 -1.7 5.473947392 6.473947 0.15446527
3 -1 0.0 1.000000000 2.000000 0.50000000
4 0 1.7 0.182683524 1.182684 0.84553473
5 1 3.4 0.033373270 1.033373 0.96770454
6 2 5.1 0.006096747 1.006097 0.99394020
7 3 6.8 0.001113775 1.001114 0.99888746
画图的结果如下:
> icc(-1,1.7)