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.1588 0.08957
#>  0.1255 0.10213
#>  0.1009 0.28485
#>  0.1843 0.07412
#>  0.1292 0.14805
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.04490 0.03351 0.03287 0.03484 0.22233 0.04617 0.05987 0.07380 0.01871
#> [10] 0.04103 0.20063 0.02458 0.04459 0.01738 0.04311 0.06169
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000  0.1543
#> 0001  0.1838
#> 0010  0.1741
#> 0011  0.2066
#> 0100  0.2159
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18497.99 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.504
#> M2:  0.49
#> total scores:  0.6258
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1587920
#> [2,] 0.1254657
#> [3,] 0.1009401
#> [4,] 0.1843072
#> [5,] 0.1292339
#> [6,] 0.2074895

(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.9457143 0.9428571 0.9728571 0.9914286 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.8114286 0.8028571 0.9028571 0.9657143 0.9771429

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

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