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.12390 0.1499
#>  0.14780 0.1670
#>  0.16995 0.0651
#>  0.12693 0.2036
#>  0.09291 0.1924
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.16294 0.08651 0.04871 0.04056 0.05977 0.04583 0.06815 0.05837 0.05224
#> [10] 0.03457 0.04096 0.01659 0.06674 0.02979 0.08535 0.10291
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.2074
#> 0001  0.2033
#> 0010  0.2186
#> 0011  0.1643
#> 0100  0.1148
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18014.98 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.544
#> M2:  0.49
#> total scores:  0.636
a <- summary(output_FOHM)
head(a$ss_EAP)
#>            [,1]
#> [1,] 0.12390140
#> [2,] 0.14780260
#> [3,] 0.16995006
#> [4,] 0.12693376
#> [5,] 0.09291198
#> [6,] 0.15086377

(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.9392857 0.9364286 0.9700000 0.9935714 0.9978571

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.7971429 0.7800000 0.8885714 0.9742857 0.9914286

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

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