如题,今天就分享给大家基于R软件下的项目反应理论的两参数模型的实践代码。大家可以下载下来看看,具体操作就是把数据替换成自己的数据就可以,详细代码如下:library(ltm)
# the two parameter model
opm1 <- ltm(LSAT~z1)
opm2 <- ltm(LSAT~z1,control = list(optimizer = "nlminb"))
## Factor Scores for the two-parameter logistic model
factor.scores(opm1)
#Computes the residuals for vectors of response patterns
residuals(opm1)
residuals(opm1, order = FALSE)
#Computes the expected frequencies for vectors of response patterns
fitted(opm1, type = "conditional-probabilities")
#related ouput setting
coef(opm1)
vcov(opm1)
item.fit(opm1)
person.fit(opm1)
margins(opm1)
margins(opm1, "three")
anova(opm1,opm2)
summary(opm1)
# Cronbach's alpha for the LSAT data-set
# with a Bootstrap 95% CI
cronbach.alpha(LSAT, CI = TRUE) #without bootsrapping
cronbach.alpha(LSAT, CI = TRUE, B = 500)
#plot opm
## Compare the Item Characteristic Curves for the LSAT data,
## under the constraint Rasch model, the unconstraint Rasch model,
## and the two parameter model assuming equal discrimination
## across items
par(mfrow = c(2, 2))
pl1 <- plot(rasch(LSAT, constr = cbind(length(LSAT) + 1, 1)))
text(2, 0.35, "Rasch model\nDiscrimination = 1")
pl2 <- plot(rasch(LSAT))
text(2, 0.35, "Rasch model")
pl3 <- plot(ltm(LSAT~z1))
text(2, 0.35, "Rasch model\nwith Guessing parameter")
## Compare the Item Characteristic Curves for Item 4
## (you have to run the above first)
plot(range(pl1[, "z"]), c(0, 1), type = "n", xlab = "Ability",
ylab = "Probability", main = "Item Characteristic Curves - Item 4")
lines(pl1[, c("z", "Item 4")], lwd = 2, col = "black")
lines(pl2[, c("z", "Item 4")], lwd = 2, col = "red")
lines(pl3[, c("z", "Item 4")], lwd = 2, col = "blue")
legend("right", c("Rasch model Discrimination = 1", "Rasch model",
"Rasch model with\nGuessing parameter"), lwd = 2, col = c("black",
"red", "blue"), bty = "n")
附件列表