# NOT RUN {
# }
# NOT RUN {
# Fit a Graded response model with two dimensions (free discrimination
# and difficulty parameters; three latent classes):
data(SF12_nomiss)
S = SF12_nomiss[,1:12]
X = SF12_nomiss[,13]
multi0 = rbind(c(1:5, 8), c(6:7,9:12))
k=3
out1 = est_multi_poly_between(S=S,k=k,X=X,link="global",disc=TRUE,
multi=multi0,fort=TRUE,disp=TRUE,out_se=TRUE)
# Display output:
summary(out1)
out1$lk
out1$Th
out1$piv
out1$De
# }
# NOT RUN {
# }
# NOT RUN {
## Fit the model under different external constraints on abilities and/or item parameters
# Fixed ability levels; all item parameters can be free
S1 = pmin(as.matrix(S),2) # all items have the same number of categories
Zth = matrix(0,nrow(multi0)*k,0)
zth = c(rep(-1, times=nrow(multi0)), rep(0, times=nrow(multi0)), rep(1, times=nrow(multi0)))
Zbe = diag(ncol(S1)*2) # free item difficulties: 12*2 = 24 (12 items with 3 categories)
Zga = diag(ncol(S1)); # free item discriminating parameters = 12 items loading on U
outc1 = est_multi_poly_between(S=S1,k=k,X=X,link="global",disc=TRUE, multi=multi0,disp=TRUE,
out_se=TRUE,Zth=Zth,zth=zth,Zbe=Zbe,Zga=Zga)
outc1$Th
outc1$tht
outc1$Bec
# Add equality constraints on item parameters
# Same difficulties for pairs of items 1-7, 2-8, 3-9, 4-10, 5-11, 6-12;
# same discriminating indices for items 2 and 3;
# free ability levels
Zbe = (matrix(1,2,1)%x%diag(12))[,-1]
Zga = as.matrix(rep(0, times=12)); Zga[2,1] = 1; Zga[3,1] = 1;
Zga1p1 = matrix(0, nrow=3, ncol=9); Zga1p2 = diag(9); Zga1p = rbind(Zga1p1, Zga1p2)
Zga = cbind(Zga, Zga1p)
# discriminating index of item 1 constrained to 1 for the model identifiability
zga = rep(0,nrow(Zga)); zga[1] = 1
outc2 = est_multi_poly_between(S=S1,k=k,X=X,link="global",disc=TRUE,
multi = multi0,disp=TRUE,tol=10^-4,
out_se=TRUE,Zbe=Zbe, Zga=Zga, zga=zga)
outc2$tht
outc2$Th
outc2$Ths
outc2$Bec
outc2$Becs
outc2$gac
outc2$gacs
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab