全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 IRT理论相关软件
5554 13
2016-07-17
与上一节类似,这几次专栏分别上传回家修整几天的学习的一些实践代码。特此分享,供大家学习:
#loading package
library(ltm)

# the three parameter model
tpm1 <- tpm(LSAT)

# use 'nlminb' as optimizer
tpm2 <- tpm(LSAT, control = list(optimizer = "nlminb"))


# the three parameter model with equal
# discrimination parameter across items
# fix the guessing parameter for the third item to zero
tpm3 <- tpm(LSAT, type = "rasch", constraint = cbind(3, 1, 0))


## Factor Scores for the two-parameter logistic model
factor.scores(tpm1)

#coef
coef(tpm1)

#fitted
fitted(tpm1)

#annova
annova(tpm1,tpm2)

#vcov
vcov(tpm1)
sqrt(diag(vcov(tpm1))) # standard errors under additive parameterization

#item-fit statistics for the three parameter model
item.fit(tpm1)

#person-fit statistics for the three parameter model
person.fit(tpm1)

#margins
margins(tpm1)
margins(tpm1, "three")

#factor score
factor.scores(tpm1)

#summary
summary(tpm1)

#Computes the residuals for vectors of response patterns
residuals(tpm1)
residuals(tpm1, order = FALSE)

# Cronbach's alpha for the LSAT data-set
# with a Bootstrap 95% CI
cronbach.alpha(LSAT, CI = TRUE)   #without bootsrap
cronbach.alpha(LSAT, CI = TRUE, B = 500)

#plot tpm

## Compare the Item Characteristic Curves for the LSAT data,
## under the constraint Rasch model, the unconstraint Rasch model,
## and the three 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(tpm(LSAT, type = "rasch", max.guessing = 1))
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")



大家在实际运行中只要把数据替换为自己的格式,并在之后的代码做相应的调整即可。
附件是我已经写好并可以运行的代码,有R格式的源文件也有txt文件。
附件列表

three parameter model-3PL.zip

大小:2.04 KB

只需: 1 个论坛币  马上下载

3PL

本附件包括:

  • tpm-three parameter model.R
  • 3PL.txt

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-7-17 21:55:50
感谢分享哟!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-17 22:41:34
虽然看不懂,但是看起来很高端的样子。加油!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-17 22:47:11
确实不容易,赞
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-18 10:02:17
好专业的样子,支持一下
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-7-18 11:43:54
zishengzheqiang 发表于 2016-7-18 10:02
好专业的样子,支持一下
自己琢磨,可能还有一点欠缺
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群