# data sim with 1000 subjects and 20 items according to 2 dimensional
# latent space model (R=2) with both binary and ordinal items
set.seed(1111)
N=1000
nit=20
ndim_z=2
nc=sample(c(2,3,5),nit,replace=TRUE) # mix of 2, 3, and 5 point scales
dat_obj=LSMsim(N,nit,ndim_z,nc=nc)
X=dat_obj$X
zt=dat_obj$par$zt # rotated z
wt=dat_obj$par$wt # rotated 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