# NOT RUN {
# }
# NOT RUN {
# Fit the model under different within-item multidimensional structures
# for SF12_nomiss data
data(SF12_nomiss)
S = SF12_nomiss[,1:12]
X = SF12_nomiss[,13]
# Graded response model with two latent variables sharing six items (free
# discrimination and difficulty parameters; two latent classes for each
# latent variable; one covariate):
multi1 = c(1:5, 8:12)
multi2 = c(6:12, 1)
tol = 10^-6 # decrease tolerance to obtain more reliable results
out1 = est_multi_poly_within(S=S,k1=2,k2=2,X=X,link="global",disc=TRUE,
multi1=multi1,multi2=multi2,disp=TRUE,
out_se=TRUE,tol=tol)
# Partial credit model with two latent variables sharing eleven items
# (free discrimination and difficulty parameters; two latent classes for
# the 1st latent variable and three latent classes for the 2nd latent
# variable; one covariate):
multi1 = 1:12
multi2 = 2:12
out2 = est_multi_poly_within(S=S,k1=2,k2=3,X=X,link="local",disc=TRUE,
multi1=multi1,multi2=multi2,disp=TRUE,tol=tol)
# Display output:
summary(out2)
out2$lk
out2$Th1
out2$Th1s
out2$piv1
out2$Th2
out2$Th2s
out2$piv2
out2$De1
out2$De2
# }
# NOT RUN {
# }
# NOT RUN {
## Fit the model under different situations for RLMS data
# Example of use of the function to account for non-ignorable missing
# item responses
data(RLMS)
X = RLMS[,1:4]
Y = RLMS[,6:9]
YR = cbind(Y,1*(!is.na(Y)))
multi1 = 1:4
multi2 = 5:8
tol = 10^-6 # decrease tolerance to obtain more reliable results
# MAR model
out0 = est_multi_poly_within(YR,k1=3,k2=2,X=X,link="global",
disc=TRUE,multi1=multi1,multi2=multi2,disp=TRUE,
out_se=TRUE,glob=TRUE,tol=tol)
# NMAR model
multi1 = 1:8
out1 = est_multi_poly_within(YR,k1=3,k2=2,X=X,link="global",
disc=TRUE,multi1=multi1,multi2=multi2,disp=TRUE,
out_se=TRUE,glob=TRUE,tol=tol)
# testing effect of the latent trait on missingness
c(out0$bic,out1$bic)
(test1 = out1$ga1c[-1]/out1$sega1c[-1])
# }
# NOT RUN {
# }
# NOT RUN {
## Fit the model under different external constraints on abilities and/or item parameters
data(SF12_nomiss)
S = SF12_nomiss[,1:12]
X = SF12_nomiss[,13]
multi1m = rbind(1:5, 8:12) # two dimensions for the 1st latent variable
multi2m = rbind(6:9, c(10:12, 1)) # two dimensions for the 2nd latent variable
k1 = 2
k2 = 2
# Fixed ability levels; all item parameters can be free
Zth1 = matrix(0,nrow(multi1m)*k1,0)
zth1 = c(rep(-1, times=nrow(multi1m)), rep(1, times=nrow(multi1m)))
Zth2 = matrix(0,nrow(multi2m)*k2,0)
zth2 = c(rep(-1, times=nrow(multi2m)), rep(1, times=nrow(multi2m)))
# item difficulties: 10*4 + 2*2 = 44 (10 items with 5 categories plus 2 items with 3 categories)
Zbe = diag(44)
# item discriminating parameters = 10 items loading on the 1st latent variable plus 8 items loading
# on the 2nd latent variable
Zga1 = diag(10); Zga2 = diag(8)
zga1 = rep(0,nrow(Zga1)); zga1[1] = 1
zga2 = rep(0,nrow(Zga2)); zga2[1] = 1
out1c = est_multi_poly_within(S=S,k1=k1,k2=k2,X=X,link="global",disc=TRUE,multi1=multi1m,
multi2=multi2m,disp=TRUE,out_se=TRUE,Zth1=Zth1,zth1=zth1,Zth2=Zth2,
zth2=zth2,Zbe=Zbe,Zga1=Zga1,zga1=zga1,Zga2=Zga2,zga2=zga2)
summary(out1c)
out1c$Bec
# Constraint difficulties of the first threshold to be equal for all items
# and difficulties of the second threshold to be equal for all items;
# free ability levels
multi1u = c(1:3, 6:10) # one dimension for the 1st latent variable
multi2u = c(4:10, 1) # one dimension for the 2nd latent variable
S1 = pmin(as.matrix(S[, -c(2,3)]),2) # all items have the same number of categories
Zbe = as.matrix((matrix(1,10,1)%x%diag(2))[,-1])
out2c = est_multi_poly_within(S=S1,k1=2,k2=2,X=X,link="global",disc=TRUE,
multi1=multi1u,multi2=multi2u,disp=TRUE,
out_se=TRUE,Zbe=Zbe)
out2c$Bec
# Same difficulties for pairs of items 1-6, 2-7, 3-8, 4-9, 5-10;
# free ability levels
Zbe = (matrix(1,2,1)%x%diag(10))[,-1]
out3c = est_multi_poly_within(S=S1,k1=2,k2=2,X=X,link="global",disc=TRUE,
multi1=multi1u,multi2=multi2u,disp=TRUE,
out_se=TRUE,Zbe=Zbe)
out3c$Bec
# Add equality constraints on some discriminating indices for the 1st latent variable
Zbe = (matrix(1,2,1)%x%diag(10))[,-1]
Zga1 = diag(length(multi1u));
# discriminating index of item 1 constrained to 1 for the model identifiability
# discriminating index of item 3 equal to discriminating index of item 2
Zga1 = Zga1[, -c(1, 3)];
Zga1[3, 1] = 1
zga1 = rep(0,nrow(Zga1)); zga1[1] = 1
out4c = est_multi_poly_within(S=S1,k1=2,k2=2,X=X,link="global",disc=TRUE,
multi1=multi1u,multi2=multi2u,disp=TRUE,tol=10^-4,
out_se=TRUE,Zbe=Zbe, Zga1=Zga1, zga1=zga1)
out4c$Bec
out4c$ga1c
out4c$ga1t
# }
Run the code above in your browser using DataLab