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.1002 0.1360
#>  0.2109 0.1346
#>  0.1426 0.2382
#>  0.1437 0.1595
#>  0.2224 0.1858
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.12581 0.07092 0.02269 0.03446 0.03317 0.04324 0.07168 0.03749 0.13466
#> [10] 0.01979 0.14928 0.03836 0.04290 0.04589 0.08799 0.04168
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1641
#> 0001  0.1558
#> 0010  0.1716
#> 0011  0.2127
#> 0100  0.2192
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18960.51 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5144
#> M2:  0.49
#> total scores:  0.623
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1001682
#> [2,] 0.2108582
#> [3,] 0.1426479
#> [4,] 0.1436923
#> [5,] 0.2224141
#> [6,] 0.1698310

(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.9321429 0.9514286 0.9771429 0.9842857 0.9907143

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.7771429 0.8314286 0.9257143 0.9428571 0.9628571

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

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