#
# only binary items
#
# data sim with 1000 subjects and 20 binary items
# according to 2 dimensional latent space model (R=2)
set.seed(1111)
N=1000
nit=20
ndim_z=2
dat_obj=LSMsim(N,nit,ndim_z)
X=dat_obj$X
zt=dat_obj$par$zt # rotated true z, see ?LSMsim and ?LSMrotate
wt=dat_obj$par$wt # rotated true w
#fit model
results=LSMfit(X,2)
#plot the parameter recovery results
oldpar=par(mfrow=c(2,2))
s_p=sign(cor(results$z,zt)) # to correct for sign switches in the plots
s_i=sign(cor(results$w,wt))
plot(s_p[1,1]*zt[,1],results$z[,1]); abline(0,1)
plot(s_p[2,2]*zt[,2],results$z[,2]); abline(0,1)
plot(s_i[1,1]*wt[,1],results$w[,1]); abline(0,1)
plot(s_i[2,2]*wt[,2],results$w[,2]); abline(0,1)
par(oldpar)
# \donttest{
#
# mixed scale items
#
# data sim with 1000 subjects and 20 mixed scale items
# according to 2 dimensional latent space model (R=2)
set.seed(1111)
N=1000
nit=20
ndim_z=2
nc=rpois(nit,2)+2 # number of response categories
# (between 2 and 7 for this seed)
dat_obj=LSMsim(N,nit,ndim_z,nc=nc)
X=dat_obj$X
zt=dat_obj$par$zt # rotated true z, see ?LSMsim and ?LSMrotate
wt=dat_obj$par$wt # rotated true w
#fit model
results=LSMfit(X,2)
#plot the parameter recovery results
oldpar=par(mfrow=c(2,2))
s_p=sign(cor(results$z,zt)) # to correct for sign switches in the plots
s_i=sign(cor(results$w,wt))
plot(s_p[1,1]*zt[,1],results$z[,1]); abline(0,1)
plot(s_p[2,2]*zt[,2],results$z[,2]); abline(0,1)
plot(s_i[1,1]*wt[,1],results$w[,1]); abline(0,1)
plot(s_i[2,2]*wt[,2],results$w[,2]); abline(0,1)
par(oldpar)
# }
Run the code above in your browser using DataLab