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.18304 0.09208
#>  0.14468 0.15086
#>  0.17622 0.12710
#>  0.08337 0.12312
#>  0.18497 0.14397
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.05971 0.05791 0.02139 0.16509 0.14554 0.06073 0.03663 0.06160 0.06242
#> [10] 0.06351 0.07429 0.02456 0.02406 0.02457 0.10133 0.01665
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1725
#> 0001  0.1701
#> 0010  0.2225
#> 0011  0.1724
#> 0100  0.1929
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18005.44 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5072
#> M2:  0.49
#> total scores:  0.6298
a <- summary(output_FOHM)
head(a$ss_EAP)
#>            [,1]
#> [1,] 0.18303846
#> [2,] 0.14468492
#> [3,] 0.17622153
#> [4,] 0.08336539
#> [5,] 0.18497283
#> [6,] 0.13634927

(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.9314286 0.9392857 0.9714286 0.9850000 0.9850000

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.7685714 0.7942857 0.8914286 0.9428571 0.9400000

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

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