如何在包ltm中使用rmvlogis来模拟rasch模型数据?
我试着如何在包ltm中使用rmvlogis来模拟rasch模型数据?,r,R,我试着 使用rmvlogis(包内ltm)模拟40个rasch项目和n名受试者的数据 使用上述数据和rasch(在包ltm中),修复已知的前14项参数,以估计剩余26项的参数 我的代码是: library(ltm) test<-function(n,m) { # for reproducible set.seed(12345) # generate 40 rasch item parameters b<-rbeta(40,1.2,1.5)*4-2 # genera
library(ltm)
test<-function(n,m) {
# for reproducible
set.seed(12345)
# generate 40 rasch item parameters
b<-rbeta(40,1.2,1.5)*4-2
# generate abilities of n examinees
latents<-rnorm(n,1.5,1.5)
# construct thetas for rmvlogis, rasch model with discrimination =1
thetas<-cbind(b,1)
# generate response data of m examinees with latents
data<-rmvlogis(m,thetas=thetas,z.vals=latents,IRT=FALSE,link="logit")
# estimate parameters of items 15-40, use items 1-10 as anchor
model<-rasch(data=data,constraint=cbind(c(1:14,41),c(b[1:14],1)),IRT=FALSE,start="random")
# compare b and model$coef[,1]
plot(b[1:14],model$coef[1:14,1],xlab="b",ylab="bhat")
abline(a=0,b=1)
points(b[15:40],model$coef[15:40,1])
}
库(ltm)
测试当m=n
是因为当z.vals
和n
(您称之为m
)的长度不相等时,rmvlogis
函数忽略z.vals
。查看函数rmvlogis
内部,您将看到这一行:
z <- if (is.null(z.vals) || length(z.vals) != n) {
switch(distr,
normal = rnorm(n), # Your case.
logistic = sqrt(3)/pi *
rlogis(n), `log-normal` = (rlnorm(n) - exp(0.5))/sqrt(exp(2) -
exp(1)), uniform = runif(n, -3.5, 3.5)/sqrt(7^2/12))
}
正如预期的那样,根据潜在分布的平均值,将响应向上或向下推。也许你想把平均值设置为零?@hjyanghj我不明白你的意思。你的意思是你希望潜在平均值为零吗?如果是这样的话,最新的情况是:表格A有40个项目,其中14个项目是旧项目,它们的难度以前已经过校准。现在,管理表格A,希望校准这26个新项目。参加中A考试的考生的能力水平未知,也需要进行评估。所以我需要校准这26项,即使是最晚。平均值等于1.2或其他。谢谢你的回复。非常感谢。对不起,我不熟悉项目响应和测试中使用的统计数据。我想我的回答会帮助你理解函数的输出。对于与编程无关的问题,您需要在其他地方寻求帮助。
# Modified function
test<-function(n,m,latent.mean) {
set.seed(12345)
b<-rbeta(40,1.2,1.5)*4-2
latents<-rnorm(n,latent.mean,1.5)
thetas<-cbind(b,1)
data<-rmvlogis(m,thetas=thetas,z.vals=latents,IRT=FALSE,link="logit")
model<-rasch(data=data,constraint=cbind(c(1:14,41),c(b[1:14],1)),IRT=FALSE,start="random")
plot(b[1:14],model$coef[1:14,1],xlab="b",ylab="bhat", col='blue',main=paste('Latent mean:',latent.mean))
abline(a=0,b=1)
points(b[15:40],model$coef[15:40,1],col='red')
}
# PLot the three
par(mfrow=c(1,3))
test(300,300,latent.mean=1)
test(300,300,latent.mean=0)
test(300,300,latent.mean=-1)
par(mfrow=c(1,1))