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.1282 0.20423
#>  0.1086 0.17414
#>  0.1191 0.02048
#>  0.1517 0.15895
#>  0.1348 0.15900
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.01688 0.03449 0.07457 0.04617 0.03842 0.05245 0.21759 0.03177 0.02586
#> [10] 0.09798 0.02500 0.03090 0.02939 0.03689 0.14328 0.09837
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1939
#> 0001  0.2021
#> 0010  0.1775
#> 0011  0.1965
#> 0100  0.1768
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18466.15 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5208
#> M2:  0.49
#> total scores:  0.6319
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1282209
#> [2,] 0.1085553
#> [3,] 0.1190727
#> [4,] 0.1516780
#> [5,] 0.1348142
#> [6,] 0.1479279

(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.9471429 0.9707143 0.9900000 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.7600000 0.8142857 0.8885714 0.9628571 0.9771429

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

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