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.1637 0.23295
#>  0.1911 0.15358
#>  0.1579 0.05773
#>  0.1314 0.14615
#>  0.1470 0.16953
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.03639 0.02771 0.02830 0.02970 0.05623 0.03238 0.06047 0.02735 0.06835
#> [10] 0.02241 0.02637 0.02298 0.07005 0.02879 0.30544 0.15707
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1451
#> 0001  0.2199
#> 0010  0.1797
#> 0011  0.2112
#> 0100  0.1787
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18428.24 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5084
#> M2:  0.49
#> total scores:  0.6251
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1636797
#> [2,] 0.1910649
#> [3,] 0.1578661
#> [4,] 0.1313579
#> [5,] 0.1469931
#> [6,] 0.1325141

(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.9357143 0.9450000 0.9778571 0.9885714 0.9942857

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.7542857 0.8114286 0.9200000 0.9571429 0.9771429

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

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