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.1721 0.1608
#>  0.1334 0.1304
#>  0.1198 0.1202
#>  0.1700 0.1100
#>  0.1809 0.2009
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.02918 0.04589 0.04775 0.03683 0.10190 0.09985 0.02737 0.17992 0.04933
#> [10] 0.01499 0.08852 0.05059 0.05741 0.05162 0.02851 0.09034
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1423
#> 0001  0.2368
#> 0010  0.1637
#> 0011  0.1823
#> 0100  0.2079
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18862.42 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5076
#> M2:  0.49
#> total scores:  0.6201
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1720878
#> [2,] 0.1334220
#> [3,] 0.1198056
#> [4,] 0.1699956
#> [5,] 0.1808838
#> [6,] 0.1377618

(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.9157143 0.9428571 0.9771429 0.9907143 0.9928571

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.7085714 0.8028571 0.9171429 0.9628571 0.9742857

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

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