library(hmcdm)
= length(Test_versions)
N = nrow(Q_matrix)
J = ncol(Q_matrix)
K = nrow(Test_order)
L = J/L Jt
<- ETAmat(K, J, Q_matrix)
ETAs <- Q_list(Q_matrix, Test_order, Test_versions)
Q_examinee <- sample(1:2^K, N, replace = L)
class_0 <- matrix(0,N,K)
Alphas_0 = c(0,0)
mu_thetatau = rbind(c(1.8^2,.4*.5*1.8),c(.4*.5*1.8,.25))
Sig_thetatau = matrix(rnorm(N*2),N,2)
Z = Z%*%chol(Sig_thetatau)
thetatau_true = thetatau_true[,1]
thetas_true = thetatau_true[,2]
taus_true = 3
G_version = 0.8
phi_true for(i in 1:N){
<- inv_bijectionvector(K,(class_0[i]-1))
Alphas_0[i,]
}<- c(-2, .4, .055) # empirical from Wang 2017
lambdas_true <- simulate_alphas_HO_joint(lambdas_true,thetas_true,Alphas_0,Q_examinee,L,Jt)
Alphas table(rowSums(Alphas[,,5]) - rowSums(Alphas[,,1])) # used to see how much transition has taken place
#>
#> 0 1 2 3 4
#> 94 90 102 49 15
<- array(runif(J*2,0.1,0.3), dim = c(Jt,2,L))
itempars_true <- array(NA, dim = c(Jt,2,L))
RT_itempars_true 2,] <- rnorm(Jt*L,3.45,.5)
RT_itempars_true[,1,] <- runif(Jt*L,1.5,2)
RT_itempars_true[,
<- simDINA(Alphas,itempars_true,ETAs,Test_order,Test_versions)
Y_sim <- sim_RT(Alphas,RT_itempars_true,Q_matrix,taus_true,phi_true,ETAs,G_version,Test_order,Test_versions) L_sim
= hmcdm(Y_sim,Q_matrix,"DINA_HO_RT_joint",Test_order,Test_versions,100,30,
output_HMDCM_RT_joint Latency_array = L_sim, G_version = G_version,
theta_propose = 2,deltas_propose = c(.45,.25,.06))
#> 0
output_HMDCM_RT_joint#>
#> Model: DINA_HO_RT_joint
#>
#> Sample Size: 350
#> Number of Items: 50
#> Number of Time Points: 5
#>
#> Chain Length: 100, burn-in: 30
summary(output_HMDCM_RT_joint)
#>
#> Model: DINA_HO_RT_joint
#>
#> Item Parameters:
#> ss_EAP gs_EAP
#> 0.2609 0.1541
#> 0.1938 0.1606
#> 0.3169 0.1208
#> 0.2002 0.1844
#> 0.3437 0.1880
#> ... 45 more items
#>
#> Transition Parameters:
#> lambdas_EAP
#> λ0 -2.1692
#> λ1 0.1646
#> λ2 0.3077
#>
#> Class Probabilities:
#> pis_EAP
#> 0000 0.01697
#> 0001 0.07685
#> 0010 0.03202
#> 0011 0.08080
#> 0100 0.04105
#> ... 11 more classes
#>
#> Deviance Information Criterion (DIC): 56450.01
#>
#> Posterior Predictive P-value (PPP):
#> M1: 0.4969
#> M2: 0.49
#> total scores: 0.6107
<- summary(output_HMDCM_RT_joint)
a
a#>
#> Model: DINA_HO_RT_joint
#>
#> Item Parameters:
#> ss_EAP gs_EAP
#> 0.2609 0.1541
#> 0.1938 0.1606
#> 0.3169 0.1208
#> 0.2002 0.1844
#> 0.3437 0.1880
#> ... 45 more items
#>
#> Transition Parameters:
#> lambdas_EAP
#> λ0 -2.1692
#> λ1 0.1646
#> λ2 0.3077
#>
#> Class Probabilities:
#> pis_EAP
#> 0000 0.01697
#> 0001 0.07685
#> 0010 0.03202
#> 0011 0.08080
#> 0100 0.04105
#> ... 11 more classes
#>
#> Deviance Information Criterion (DIC): 56450.01
#>
#> Posterior Predictive P-value (PPP):
#> M1: 0.5031
#> M2: 0.49
#> total scores: 0.6098
$ss_EAP
a#> [,1]
#> [1,] 0.2608571
#> [2,] 0.1938461
#> [3,] 0.3169085
#> [4,] 0.2002168
#> [5,] 0.3437420
#> [6,] 0.3319179
#> [7,] 0.3230553
#> [8,] 0.3342684
#> [9,] 0.2000913
#> [10,] 0.2190167
#> [11,] 0.2892406
#> [12,] 0.3282929
#> [13,] 0.2650876
#> [14,] 0.2005377
#> [15,] 0.2629640
#> [16,] 0.2845765
#> [17,] 0.2465752
#> [18,] 0.1591626
#> [19,] 0.2635778
#> [20,] 0.2674567
#> [21,] 0.1426407
#> [22,] 0.2875529
#> [23,] 0.2196070
#> [24,] 0.1948727
#> [25,] 0.2386156
#> [26,] 0.2942763
#> [27,] 0.2626946
#> [28,] 0.1866310
#> [29,] 0.1460074
#> [30,] 0.2755745
#> [31,] 0.1204809
#> [32,] 0.2561404
#> [33,] 0.2603083
#> [34,] 0.3070815
#> [35,] 0.1406004
#> [36,] 0.3665638
#> [37,] 0.3936804
#> [38,] 0.2757108
#> [39,] 0.1626052
#> [40,] 0.1244808
#> [41,] 0.2982005
#> [42,] 0.2267180
#> [43,] 0.2297538
#> [44,] 0.2889095
#> [45,] 0.2122710
#> [46,] 0.2677706
#> [47,] 0.3405588
#> [48,] 0.2574021
#> [49,] 0.2836954
#> [50,] 0.2663117
head(a$ss_EAP)
#> [,1]
#> [1,] 0.2608571
#> [2,] 0.1938461
#> [3,] 0.3169085
#> [4,] 0.2002168
#> [5,] 0.3437420
#> [6,] 0.3319179
<- cor(thetas_true,a$thetas_EAP))
(cor_thetas #> [,1]
#> [1,] 0.709698
<- cor(taus_true,a$response_times_coefficients$taus_EAP))
(cor_taus #> [,1]
#> [1,] 0.9861156
<- cor(as.vector(itempars_true[,1,]),a$ss_EAP))
(cor_ss #> [,1]
#> [1,] 0.8721559
<- cor(as.vector(itempars_true[,2,]),a$gs_EAP))
(cor_gs #> [,1]
#> [1,] 0.6675134
<- numeric(L)
AAR_vec for(t in 1:L){
<- mean(Alphas[,,t]==a$Alphas_est[,,t])
AAR_vec[t]
}
AAR_vec#> [1] 0.8371429 0.8928571 0.9142857 0.9264286 0.9450000
<- numeric(L)
PAR_vec for(t in 1:L){
<- mean(rowSums((Alphas[,,t]-a$Alphas_est[,,t])^2)==0)
PAR_vec[t]
}
PAR_vec#> [1] 0.5171429 0.6485714 0.7085714 0.7600000 0.8171429
$DIC
a#> Transition Response_Time Response Joint Total
#> D_bar 1046.5421 31976.68 18381.57 4248.518 55653.30
#> D(theta_bar) 815.4667 32072.50 17869.49 4099.150 54856.60
#> DIC 1277.6175 31880.85 18893.65 4397.886 56450.01
head(a$PPP_total_scores)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.6571429 1.0000000 0.9571429 0.9571429 0.9000000
#> [2,] 0.3857143 0.6571429 0.3000000 0.8285714 1.0000000
#> [3,] 0.4285714 0.7000000 0.9714286 1.0000000 1.0000000
#> [4,] 0.5714286 0.5142857 0.3285714 0.1857143 0.8714286
#> [5,] 0.7285714 0.2428571 0.6285714 0.7000000 0.9571429
#> [6,] 0.6285714 0.6285714 0.7714286 0.1428571 0.7000000
head(a$PPP_total_RTs)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.51428571 0.3285714 0.5142857 0.2857143 0.7285714
#> [2,] 0.75714286 0.9000000 0.0000000 0.8000000 0.1571429
#> [3,] 0.55714286 0.3857143 0.1571429 0.9285714 0.5857143
#> [4,] 0.25714286 0.6142857 0.6285714 0.3714286 0.2714286
#> [5,] 0.01428571 0.9428571 0.4000000 0.5285714 0.5142857
#> [6,] 0.62857143 0.7000000 0.4428571 0.3571429 0.3714286
head(a$PPP_item_means)
#> [1] 0.5571429 0.4857143 0.5285714 0.4571429 0.4142857 0.4714286
head(a$PPP_item_mean_RTs)
#> [1] 0.4142857 0.4857143 0.6428571 0.1571429 0.3142857 0.5857143
head(a$PPP_item_ORs)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#> [1,] NA 0.6571429 0.7285714 0.5000000 0.6285714 0.1857143 0.5142857 0.4714286
#> [2,] NA NA 0.9428571 0.4000000 0.8428571 0.7285714 0.9428571 0.4714286
#> [3,] NA NA NA 0.1142857 0.1428571 0.4714286 0.8857143 0.7857143
#> [4,] NA NA NA NA 0.4857143 0.5857143 0.6571429 0.9142857
#> [5,] NA NA NA NA NA 0.2000000 0.8571429 0.5428571
#> [6,] NA NA NA NA NA NA 0.8000000 0.7428571
#> [,9] [,10] [,11] [,12] [,13] [,14] [,15]
#> [1,] 0.7285714 0.2142857 0.2571429 0.57142857 0.9571429 0.8000000 0.9857143
#> [2,] 0.7857143 0.5428571 0.6000000 0.75714286 0.9142857 0.4571429 0.7714286
#> [3,] 0.2000000 0.3428571 0.3000000 0.07142857 0.3285714 0.3000000 0.8857143
#> [4,] 0.7000000 0.6428571 0.9285714 0.42857143 0.9142857 0.8428571 0.7142857
#> [5,] 0.1285714 0.4571429 0.5857143 0.82857143 0.7857143 0.6000000 0.9142857
#> [6,] 0.7857143 0.9428571 0.8285714 0.44285714 0.9714286 0.4428571 0.7428571
#> [,16] [,17] [,18] [,19] [,20] [,21] [,22]
#> [1,] 0.7714286 0.8428571 0.6428571 0.3000000 0.2857143 0.5000000 0.2000000
#> [2,] 0.8142857 0.6285714 0.3142857 0.8571429 0.8428571 0.8571429 0.6571429
#> [3,] 0.6142857 0.4571429 0.4428571 0.7857143 0.8285714 0.1000000 0.8000000
#> [4,] 0.5000000 0.9857143 0.5857143 0.9000000 0.8000000 0.2000000 0.2142857
#> [5,] 0.9857143 0.9428571 0.8714286 0.9285714 0.7714286 0.9142857 0.8285714
#> [6,] 0.7714286 0.8000000 0.2428571 0.6428571 0.9000000 0.4571429 0.9428571
#> [,23] [,24] [,25] [,26] [,27] [,28] [,29]
#> [1,] 0.9285714 0.8000000 0.6571429 0.2285714 0.4142857 0.9714286 0.7142857
#> [2,] 0.8000000 0.8000000 1.0000000 0.3428571 0.8428571 1.0000000 0.7714286
#> [3,] 0.1857143 0.3428571 0.5428571 0.6571429 0.8000000 0.9285714 0.8571429
#> [4,] 0.3285714 0.4428571 0.9285714 0.6142857 0.6285714 0.7571429 0.1285714
#> [5,] 0.6714286 0.9714286 0.6571429 0.6857143 0.6285714 0.6285714 0.7714286
#> [6,] 0.5000000 0.3428571 1.0000000 0.5857143 0.8000000 0.8714286 0.8142857
#> [,30] [,31] [,32] [,33] [,34] [,35] [,36]
#> [1,] 0.4000000 0.3000000 0.6714286 0.1428571 0.15714286 0.5857143 0.6285714
#> [2,] 0.6571429 0.8000000 0.5285714 0.4714286 0.68571429 1.0000000 0.6571429
#> [3,] 0.2142857 0.3857143 0.4857143 0.1000000 0.90000000 0.9428571 0.6142857
#> [4,] 0.7000000 0.8142857 0.9285714 0.2571429 0.01428571 0.4428571 0.3428571
#> [5,] 0.2714286 0.9142857 0.4857143 0.1428571 0.10000000 0.8714286 0.5000000
#> [6,] 0.8571429 0.8285714 0.2000000 0.5571429 0.60000000 0.9142857 0.9857143
#> [,37] [,38] [,39] [,40] [,41] [,42] [,43]
#> [1,] 0.67142857 0.02857143 0.05714286 0.8285714 0.4857143 0.4428571 0.3285714
#> [2,] 0.55714286 0.65714286 0.82857143 0.6428571 0.7000000 0.4142857 1.0000000
#> [3,] 0.81428571 0.51428571 0.38571429 0.4714286 0.2571429 0.3142857 0.8000000
#> [4,] 0.68571429 0.21428571 0.12857143 0.5857143 0.9000000 0.3142857 0.8000000
#> [5,] 0.22857143 0.65714286 0.60000000 0.9000000 0.4000000 0.8714286 0.8142857
#> [6,] 0.02857143 0.95714286 0.80000000 0.8000000 0.7714286 0.5285714 0.9857143
#> [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,] 0.6000000 0.1857143 0.7428571 0.3428571 0.8857143 0.70000000 0.7285714
#> [2,] 0.5000000 0.6285714 0.6000000 0.8285714 0.8714286 0.07142857 0.5285714
#> [3,] 0.7142857 0.7142857 0.7571429 0.2857143 0.3142857 0.68571429 0.7571429
#> [4,] 0.3142857 0.5142857 0.0000000 0.1000000 0.1571429 0.80000000 0.4571429
#> [5,] 0.6714286 0.1857143 0.8571429 0.7857143 0.9142857 0.75714286 0.6285714
#> [6,] 0.7714286 0.8000000 0.3571429 0.6142857 0.7571429 0.90000000 0.9000000