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.1616 0.25202
#>  0.1202 0.05978
#>  0.1238 0.25618
#>  0.1728 0.15307
#>  0.1335 0.16406
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.03477 0.01776 0.08944 0.04919 0.08121 0.23572 0.05234 0.03160 0.02195
#> [10] 0.01816 0.07322 0.03396 0.09821 0.03977 0.03756 0.08513
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1463
#> 0001  0.1658
#> 0010  0.2283
#> 0011  0.1535
#> 0100  0.2175
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 19028.38 
#> 
#> Posterior Predictive P-value (PPP):
#> M1:  0.52
#> M2:  0.49
#> total scores:  0.626
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1615679
#> [2,] 0.1201676
#> [3,] 0.1237543
#> [4,] 0.1727939
#> [5,] 0.1334634
#> [6,] 0.1279697

(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.9178571 0.9521429 0.9700000 0.9800000 0.9800000

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.7228571 0.8428571 0.8942857 0.9285714 0.9285714

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

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