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.1369 0.2268
#>  0.2132 0.2908
#>  0.1339 0.1419
#>  0.1484 0.1346
#>  0.1863 0.1567
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.10168 0.01314 0.06210 0.07096 0.08859 0.10141 0.03469 0.03558 0.02111
#> [10] 0.02222 0.05346 0.04525 0.19128 0.01743 0.10695 0.03414
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1714
#> 0001  0.1600
#> 0010  0.1977
#> 0011  0.2338
#> 0100  0.1449
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18089.61 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5364
#> M2:  0.49
#> total scores:  0.6287
a <- summary(output_FOHM)
head(a$ss_EAP)
#>            [,1]
#> [1,] 0.13692917
#> [2,] 0.21323673
#> [3,] 0.13392995
#> [4,] 0.14843723
#> [5,] 0.18632729
#> [6,] 0.09796671

(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.9250000 0.9492857 0.9721429 0.9935714 0.9964286

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.7457143 0.8200000 0.9028571 0.9742857 0.9857143

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

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