DINA_FOHM

library(hmcdm)

Load the spatial rotation data

N = length(Test_versions)
J = nrow(Q_matrix)
K = ncol(Q_matrix)
L = nrow(Test_order)
Jt = J/L

(1) Simulate responses and response times based on the DINA_FOHM model

TP <- TPmat(K)
Omega_true <- rOmega(TP)
class_0 <- sample(1:2^K, N, replace = L)
Alphas_0 <- matrix(0,N,K)
for(i in 1:N){
 Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1))
}
Alphas <- sim_alphas(model="FOHM", Omega = Omega_true, N=N, L=L)
itempars_true <- matrix(runif(J*2,.1,.2), ncol=2)

Y_sim <- sim_hmcdm(model="DINA",Alphas,Q_matrix,Design_array,
                   itempars=itempars_true)

(2) Run the MCMC to sample parameters from the posterior distribution

output_FOHM = hmcdm(Y_sim,Q_matrix,"DINA_FOHM",Design_array,100,30)
#> 0
output_FOHM
#> 
#> Model: DINA_FOHM 
#> 
#> Sample Size: 350
#> Number of Items: 
#> Number of Time Points: 
#> 
#> Chain Length: 100, burn-in: 50
summary(output_FOHM)
#> 
#> Model: DINA_FOHM 
#> 
#> Item Parameters:
#>  ss_EAP gs_EAP
#>  0.1256 0.1441
#>  0.1083 0.1644
#>  0.1314 0.1692
#>  0.2290 0.2099
#>  0.1292 0.1744
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.03180 0.03704 0.03043 0.05406 0.11653 0.06258 0.18154 0.03575 0.10875
#> [10] 0.02576 0.04896 0.06315 0.04625 0.03907 0.03889 0.07944
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.2648
#> 0001  0.1232
#> 0010  0.2053
#> 0011  0.2094
#> 0100  0.1091
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18777.83 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5172
#> M2:  0.49
#> total scores:  0.6276
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1255921
#> [2,] 0.1083184
#> [3,] 0.1314095
#> [4,] 0.2290003
#> [5,] 0.1291794
#> [6,] 0.1647838

(3) Check for parameter estimation accuracy

AAR_vec <- numeric(L)
for(t in 1:L){
  AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.9328571 0.9385714 0.9678571 0.9871429 0.9878571

PAR_vec <- numeric(L)
for(t in 1:L){
  PAR_vec[t] <- mean(rowSums((Alphas[,,t]-a$Alphas_est[,,t])^2)==0)
}
PAR_vec
#> [1] 0.7571429 0.7828571 0.8885714 0.9514286 0.9542857

(4) Evaluate the fit of the model to the observed response

a$DIC
#>              Transition Response_Time Response    Joint    Total
#> D_bar          2159.823            NA 14782.86 1265.688 18208.37
#> D(theta_bar)   2096.739            NA 14313.48 1228.689 17638.91
#> DIC            2222.907            NA 15252.23 1302.687 18777.83
head(a$PPP_total_scores)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.32 0.86 0.00 0.98 0.42
#> [2,] 0.44 0.34 0.42 0.52 0.70
#> [3,] 0.68 0.78 0.92 0.18 0.86
#> [4,] 0.36 0.26 0.20 0.32 0.76
#> [5,] 0.10 0.80 0.62 0.92 0.74
#> [6,] 0.28 0.70 0.88 0.54 0.54
head(a$PPP_item_means)
#> [1] 0.42 0.50 0.50 0.54 0.64 0.48
head(a$PPP_item_ORs)
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,]   NA  0.9 0.14 0.84 0.54 0.58 0.84 0.20 0.60  0.36  0.04  0.62  1.00  0.28
#> [2,]   NA   NA 0.82 0.18 0.66 0.66 0.52 0.86 0.16  0.28  0.80  0.76  0.88  0.94
#> [3,]   NA   NA   NA 0.28 0.42 0.52 0.38 0.74 0.18  0.34  0.48  0.98  0.70  0.82
#> [4,]   NA   NA   NA   NA 0.30 0.38 0.90 0.46 0.58  0.72  0.98  0.40  0.80  0.30
#> [5,]   NA   NA   NA   NA   NA 0.74 0.40 0.66 0.62  0.20  0.52  0.44  0.82  0.98
#> [6,]   NA   NA   NA   NA   NA   NA 0.12 0.82 0.92  0.24  0.34  0.48  0.64  0.76
#>      [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]  0.06  0.58  0.34  0.42  0.74  0.64  0.00  0.78  0.58  0.88  0.30  0.24
#> [2,]  0.38  0.36  0.88  0.90  0.96  0.80  0.82  0.96  0.84  0.86  0.64  0.88
#> [3,]  0.98  0.84  0.88  0.96  1.00  0.80  0.36  0.50  0.60  0.96  0.62  0.86
#> [4,]  0.58  0.48  0.20  0.60  0.76  0.64  0.56  0.76  0.36  0.12  0.44  0.12
#> [5,]  0.62  0.44  0.60  0.82  0.80  0.92  0.40  0.54  0.96  1.00  0.84  0.84
#> [6,]  0.02  0.10  0.72  0.84  0.36  0.40  0.32  0.32  1.00  0.82  0.44  0.72
#>      [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
#> [1,]  0.76  0.08  0.20  0.28  0.70  0.42  0.68  0.36  0.64  0.50  0.82  0.66
#> [2,]  0.48  0.88  0.66  0.98  0.94  0.10  0.62  0.76  0.54  0.50  0.44  0.68
#> [3,]  0.54  0.36  0.88  0.42  0.36  0.54  0.88  0.94  0.42  0.76  0.60  0.38
#> [4,]  0.24  0.04  0.14  0.10  0.24  0.90  0.96  0.28  0.28  0.44  0.10  0.66
#> [5,]  0.74  0.70  0.72  0.96  0.80  0.42  0.60  0.40  0.76  0.16  0.32  0.68
#> [6,]  0.18  0.72  0.56  0.14  0.60  0.76  0.88  0.80  0.96  0.52  0.80  0.92
#>      [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,]  0.10  0.28  0.20  0.90  0.42  0.06  0.18  0.36  0.30  0.80  0.80  0.50
#> [2,]  0.48  0.46  0.52  0.76  0.58  0.20  0.18  0.96  0.84  0.56  0.54  0.62
#> [3,]  1.00  0.36  0.42  0.42  0.60  0.90  0.12  0.62  0.18  0.38  0.04  0.80
#> [4,]  0.62  0.20  0.56  0.82  0.36  0.40  0.02  0.50  0.34  0.66  0.00  0.08
#> [5,]  0.28  0.72  0.20  0.92  0.30  0.00  0.48  0.74  0.28  0.56  0.34  0.40
#> [6,]  0.50  0.62  0.30  0.28  0.74  0.22  0.46  0.74  0.22  0.22  0.10  0.36