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.11392 0.1509
#>  0.15264 0.1265
#>  0.14103 0.2159
#>  0.12370 0.1917
#>  0.09824 0.1247
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.03612 0.04023 0.08724 0.06184 0.02024 0.03171 0.02305 0.15487 0.08500
#> [10] 0.11492 0.03781 0.08584 0.05697 0.03249 0.04251 0.08916
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.2068
#> 0001  0.1451
#> 0010  0.2370
#> 0011  0.1836
#> 0100  0.1632
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18511.88 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5016
#> M2:  0.49
#> total scores:  0.6248
a <- summary(output_FOHM)
head(a$ss_EAP)
#>            [,1]
#> [1,] 0.11392417
#> [2,] 0.15264000
#> [3,] 0.14103456
#> [4,] 0.12370413
#> [5,] 0.09824396
#> [6,] 0.16858381

(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.9257143 0.9485714 0.9757143 0.9785714 0.9785714

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.7371429 0.8171429 0.9114286 0.9314286 0.9228571

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

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