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.15091 0.1186
#>  0.09976 0.1687
#>  0.13653 0.1912
#>  0.12616 0.1300
#>  0.22355 0.1186
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.11541 0.09023 0.01944 0.02660 0.09548 0.14690 0.11938 0.04858 0.02726
#> [10] 0.08884 0.02123 0.03550 0.03984 0.02208 0.07279 0.03042
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1808
#> 0001  0.2076
#> 0010  0.1828
#> 0011  0.1943
#> 0100  0.1778
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18889.16 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.506
#> M2:  0.49
#> total scores:  0.6253
a <- summary(output_FOHM)
head(a$ss_EAP)
#>            [,1]
#> [1,] 0.15091221
#> [2,] 0.09976265
#> [3,] 0.13652700
#> [4,] 0.12616417
#> [5,] 0.22354562
#> [6,] 0.20190698

(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.9414286 0.9392857 0.9742857 0.9857143 0.9921429

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.8028571 0.7857143 0.9057143 0.9457143 0.9685714

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

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