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.1359 0.1475
#>  0.2010 0.1505
#>  0.1019 0.1553
#>  0.1803 0.1386
#>  0.1374 0.1732
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.03377 0.02273 0.06769 0.10032 0.02721 0.04187 0.12018 0.09907 0.03339
#> [10] 0.06790 0.02792 0.05626 0.03239 0.16340 0.06596 0.03994
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1000
#> 0001  0.2000
#> 0010  0.1911
#> 0011  0.2063
#> 0100  0.1937
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 19187.11 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5208
#> M2:  0.49
#> total scores:  0.6267
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1358820
#> [2,] 0.2009651
#> [3,] 0.1018586
#> [4,] 0.1802944
#> [5,] 0.1373842
#> [6,] 0.1764624

(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.9278571 0.9378571 0.9671429 0.9785714 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.7428571 0.7742857 0.8857143 0.9200000 0.9457143

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

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