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

ETAs <- ETAmat(K, J, Q_matrix)
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 <- simulate_alphas_FOHM(Omega_true, Alphas_0,L)
itempars_true <- array(runif(Jt*2*L,.1,.2), dim = c(Jt,2,L))

Y_sim <- simDINA(Alphas,itempars_true,ETAs,Test_order,Test_versions)

(2) Run the MCMC to sample parameters from the posterior distribution

output_FOHM = hmcdm(Y_sim,Q_matrix,"DINA_FOHM",Test_order,Test_versions,100,30)
#> 0
output_FOHM
#> 
#> Model: DINA_FOHM 
#> 
#> Sample Size: 350
#> Number of Items: 50
#> Number of Time Points: 5 
#> 
#> Chain Length: 100, burn-in: 30
summary(output_FOHM)
#> 
#> Model: DINA_FOHM 
#> 
#> Item Parameters:
#>  ss_EAP gs_EAP
#>  0.1491 0.1875
#>  0.1937 0.1098
#>  0.1435 0.1585
#>  0.1168 0.2532
#>  0.1800 0.2040
#>    ... 45 more items
#> 
#> Transition Parameters:
#>  [1] 0.05756 0.13175 0.07080 0.06527 0.03116 0.08509 0.04863 0.06259 0.08105
#> [10] 0.03903 0.08223 0.03949 0.03009 0.06103 0.07169 0.04254
#>    ... 15 more rows
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000 0.05851
#> 0001 0.08656
#> 0010 0.03820
#> 0011 0.06244
#> 0100 0.06745
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 18499.01 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.4994
#> M2:  0.49
#> total scores:  0.6265
a <- summary(output_FOHM)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.1490695
#> [2,] 0.1937310
#> [3,] 0.1434801
#> [4,] 0.1167605
#> [5,] 0.1799664
#> [6,] 0.2142550

(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.9150000 0.9664286 0.9842857 0.9878571 0.9914286

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.7228571 0.8885714 0.9457143 0.9571429 0.9685714

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

a$DIC
#>              Transition Response_Time Response    Joint    Total
#> D_bar          1381.299            NA 14677.62 1922.947 17981.86
#> D(theta_bar)   1288.928            NA 14267.00 1908.789 17464.72
#> DIC            1473.669            NA 15088.24 1937.106 18499.01
head(a$PPP_total_scores)
#>           [,1]      [,2]      [,3]      [,4]      [,5]
#> [1,] 0.7857143 0.5571429 0.2857143 0.4285714 1.0000000
#> [2,] 0.6714286 0.6142857 0.8285714 1.0000000 0.8571429
#> [3,] 0.9714286 0.7571429 0.9571429 0.9000000 0.2857143
#> [4,] 1.0000000 0.2428571 0.8142857 0.8571429 0.1285714
#> [5,] 1.0000000 0.4000000 0.1714286 0.8285714 1.0000000
#> [6,] 0.8571429 0.9142857 0.6714286 0.0000000 0.2000000
head(a$PPP_item_means)
#> [1] 0.4857143 0.6142857 0.5714286 0.3571429 0.5714286 0.5428571
head(a$PPP_item_ORs)
#>      [,1]      [,2]      [,3]      [,4]      [,5]      [,6]      [,7]      [,8]
#> [1,]   NA 0.6285714 0.7571429 0.1571429 0.8142857 0.6857143 0.3571429 0.4714286
#> [2,]   NA        NA 0.5714286 0.6428571 0.4285714 0.3857143 1.0000000 0.8428571
#> [3,]   NA        NA        NA 0.4714286 0.1857143 0.4285714 0.2142857 0.7428571
#> [4,]   NA        NA        NA        NA 0.4428571 0.5142857 0.1714286 0.8714286
#> [5,]   NA        NA        NA        NA        NA 0.2000000 0.4714286 0.1857143
#> [6,]   NA        NA        NA        NA        NA        NA 0.3000000 0.3000000
#>           [,9]      [,10]      [,11]      [,12]     [,13]      [,14]      [,15]
#> [1,] 0.9142857 0.52857143 0.40000000 0.84285714 0.7857143 0.48571429 0.41428571
#> [2,] 0.4142857 0.82857143 0.00000000 0.01428571 0.3571429 0.68571429 0.40000000
#> [3,] 0.3857143 0.01428571 0.35714286 0.60000000 0.8000000 0.34285714 0.01428571
#> [4,] 0.4000000 0.50000000 0.25714286 0.90000000 0.8714286 0.04285714 0.78571429
#> [5,] 0.4571429 0.60000000 0.04285714 0.51428571 0.6000000 0.44285714 0.07142857
#> [6,] 0.3857143 0.68571429 0.92857143 0.07142857 0.9714286 0.15714286 0.87142857
#>          [,16]     [,17]      [,18]     [,19]     [,20]     [,21]      [,22]
#> [1,] 0.7714286 0.9142857 0.40000000 0.6000000 0.6571429 0.1714286 0.04285714
#> [2,] 0.3142857 0.8142857 0.05714286 0.6571429 0.1857143 0.9142857 0.64285714
#> [3,] 0.4142857 0.2714286 0.21428571 0.2000000 0.8714286 0.4857143 0.77142857
#> [4,] 0.5000000 0.8000000 0.54285714 0.8428571 0.2428571 0.1857143 0.58571429
#> [5,] 0.7428571 0.6571429 0.17142857 0.4571429 0.5571429 0.8857143 0.22857143
#> [6,] 0.8142857 0.8714286 0.35714286 0.8428571 0.8142857 0.7000000 0.28571429
#>           [,23]     [,24]     [,25]     [,26]      [,27]      [,28]     [,29]
#> [1,] 0.65714286 0.3142857 0.1000000 0.6285714 0.48571429 0.58571429 0.5857143
#> [2,] 0.07142857 0.4000000 0.4000000 0.7428571 0.57142857 0.85714286 0.1142857
#> [3,] 0.10000000 0.6428571 0.4428571 0.1571429 0.71428571 0.04285714 0.8000000
#> [4,] 0.24285714 0.5142857 0.1857143 0.3285714 0.98571429 0.24285714 0.5285714
#> [5,] 0.25714286 0.9285714 0.9285714 0.9000000 0.67142857 0.97142857 0.5285714
#> [6,] 0.01428571 0.2285714 0.6428571 0.2428571 0.02857143 0.41428571 0.9000000
#>           [,30]      [,31]     [,32]     [,33]     [,34]     [,35]     [,36]
#> [1,] 0.08571429 0.41428571 0.9857143 0.4714286 0.6285714 0.3428571 0.8714286
#> [2,] 0.21428571 0.92857143 0.9285714 1.0000000 0.6714286 0.8714286 0.6571429
#> [3,] 0.51428571 0.58571429 0.8714286 0.2571429 0.8000000 0.5714286 0.1571429
#> [4,] 0.75714286 0.50000000 0.8428571 1.0000000 0.1000000 0.8714286 0.9142857
#> [5,] 0.87142857 0.08571429 0.9142857 0.5714286 0.8142857 1.0000000 0.7857143
#> [6,] 0.52857143 0.58571429 0.7714286 0.2428571 0.2714286 0.8142857 0.6571429
#>           [,37]     [,38]     [,39]     [,40]     [,41]      [,42]     [,43]
#> [1,] 0.14285714 0.1000000 0.3428571 0.1142857 0.7571429 0.98571429 0.4285714
#> [2,] 0.77142857 0.8000000 0.3428571 0.9857143 0.8571429 0.11428571 0.9428571
#> [3,] 0.22857143 0.3428571 0.6142857 0.9142857 0.2428571 0.04285714 0.7571429
#> [4,] 0.02857143 0.7714286 0.4285714 0.7571429 0.7428571 0.94285714 0.8000000
#> [5,] 0.58571429 0.4285714 0.2428571 0.7000000 0.5428571 0.75714286 0.6714286
#> [6,] 0.12857143 0.8428571 0.2714286 0.4571429 0.7142857 0.51428571 0.2285714
#>          [,44]     [,45]     [,46]     [,47]     [,48]     [,49]     [,50]
#> [1,] 0.3142857 0.8142857 0.9285714 0.1571429 0.8428571 0.7142857 0.9000000
#> [2,] 0.9000000 0.9285714 0.5428571 0.2428571 0.3428571 0.5000000 0.3428571
#> [3,] 0.6142857 0.7285714 0.3142857 0.8714286 0.9285714 0.6000000 0.5000000
#> [4,] 0.7142857 0.4571429 0.8142857 0.9857143 0.1428571 0.9428571 0.8571429
#> [5,] 0.6000000 0.8428571 0.6142857 0.1142857 0.8571429 0.5571429 0.6000000
#> [6,] 0.3571429 0.7142857 0.3000000 0.5714286 0.8714286 0.4142857 0.4571429