library(hmcdm)
= length(Test_versions)
N = nrow(Q_matrix)
J = ncol(Q_matrix)
K = nrow(Test_order) L
<- sample(1:2^K, N, replace = L)
class_0 <- matrix(0,N,K)
Alphas_0 for(i in 1:N){
<- inv_bijectionvector(K,(class_0[i]-1))
Alphas_0[i,]
}= rnorm(N,0,1)
thetas_true =0.5
tausd_true= rnorm(N,0,tausd_true)
taus_true = 3
G_version = 0.8
phi_true <- c(-2, 1.6, .4, .055) # empirical from Wang 2017
lambdas_true <- sim_alphas(model="HO_sep",
Alphas lambdas=lambdas_true,
thetas=thetas_true,
Q_matrix=Q_matrix,
Design_array=Design_array)
table(rowSums(Alphas[,,5]) - rowSums(Alphas[,,1])) # used to see how much transition has taken place
#>
#> 0 1 2 3 4
#> 40 73 95 110 32
<- matrix(runif(J*2,.1,.2), ncol=2)
itempars_true <- matrix(NA, nrow=J, ncol=2)
RT_itempars_true 2] <- rnorm(J,3.45,.5)
RT_itempars_true[,1] <- runif(J,1.5,2)
RT_itempars_true[,
<- sim_hmcdm(model="DINA",Alphas,Q_matrix,Design_array,
Y_sim itempars=itempars_true)
<- sim_RT(Alphas,Q_matrix,Design_array,RT_itempars_true,taus_true,phi_true,G_version) L_sim
= hmcdm(Y_sim,Q_matrix,"DINA_HO_RT_sep",Design_array,
output_HMDCM_RT_sep 100, 30,
Latency_array = L_sim, G_version = G_version,
theta_propose = 2,deltas_propose = c(.45,.35,.25,.06))
#> 0
output_HMDCM_RT_sep#>
#> Model: DINA_HO_RT_sep
#>
#> Sample Size: 350
#> Number of Items:
#> Number of Time Points:
#>
#> Chain Length: 100, burn-in: 50
summary(output_HMDCM_RT_sep)
#>
#> Model: DINA_HO_RT_sep
#>
#> Item Parameters:
#> ss_EAP gs_EAP
#> 0.11573 0.1369
#> 0.15050 0.1028
#> 0.18653 0.1675
#> 0.18032 0.1421
#> 0.09694 0.1593
#> ... 45 more items
#>
#> Transition Parameters:
#> lambdas_EAP
#> λ0 -1.8414
#> λ1 1.7226
#> λ2 0.1516
#> λ3 0.1101
#>
#> Class Probabilities:
#> pis_EAP
#> 0000 0.1626
#> 0001 0.1878
#> 0010 0.2201
#> 0011 0.1570
#> 0100 0.1879
#> ... 11 more classes
#>
#> Deviance Information Criterion (DIC): 162808.8
#>
#> Posterior Predictive P-value (PPP):
#> M1: 0.4928
#> M2: 0.49
#> total scores: 0.6243
<- summary(output_HMDCM_RT_sep)
a head(a$ss_EAP)
#> [,1]
#> [1,] 0.11573008
#> [2,] 0.15050268
#> [3,] 0.18653017
#> [4,] 0.18031809
#> [5,] 0.09694252
#> [6,] 0.09862388
<- cor(thetas_true,a$thetas_EAP))
(cor_thetas #> [,1]
#> [1,] 0.7794956
<- cor(taus_true,a$response_times_coefficients$taus_EAP))
(cor_taus #> [,1]
#> [1,] 0.9859861
<- cor(as.vector(itempars_true[,1]),a$ss_EAP))
(cor_ss #> [,1]
#> [1,] 0.6335389
<- cor(as.vector(itempars_true[,2]),a$gs_EAP))
(cor_gs #> [,1]
#> [1,] 0.7792111
<- numeric(L)
AAR_vec for(t in 1:L){
<- mean(Alphas[,,t]==a$Alphas_est[,,t])
AAR_vec[t]
}
AAR_vec#> [1] 0.9357143 0.9335714 0.9478571 0.9535714 0.9514286
<- 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.7828571 0.7628571 0.8171429 0.8314286 0.8314286
$DIC
a#> Transition Response_Time Response Joint Total
#> D_bar 2408.026 141251.5 15053.72 3207.787 161921.1
#> D(theta_bar) 2142.419 140813.8 14870.89 3206.226 161033.3
#> DIC 2673.634 141689.3 15236.55 3209.349 162808.8
head(a$PPP_total_scores)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.62 0.56 1.00 0.90 0.84
#> [2,] 0.36 0.78 0.76 0.20 0.76
#> [3,] 0.96 0.06 0.22 0.78 0.96
#> [4,] 0.98 0.64 0.52 0.42 0.58
#> [5,] 0.34 0.90 0.66 0.66 0.40
#> [6,] 0.98 0.48 0.28 1.00 0.92
head(a$PPP_item_means)
#> [1] 0.52 0.52 0.52 0.48 0.58 0.62
head(a$PPP_item_ORs)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] NA 0.5 0.98 0.74 0.66 0.72 0.84 0.72 0.78 0.42 0.84 1.00 0.96 0.68
#> [2,] NA NA 0.12 0.84 0.44 0.24 0.42 0.34 0.98 0.80 0.60 0.90 0.38 0.34
#> [3,] NA NA NA 0.56 0.36 0.22 0.14 0.24 0.94 0.68 0.54 0.56 0.66 0.70
#> [4,] NA NA NA NA 0.64 0.78 0.62 0.86 0.58 0.68 0.50 0.46 0.60 0.38
#> [5,] NA NA NA NA NA 0.22 0.62 0.86 0.46 0.12 0.16 1.00 0.92 0.68
#> [6,] NA NA NA NA NA NA 0.80 0.96 0.78 0.56 0.74 0.74 0.46 0.78
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,] 0.86 0.36 0.92 0.78 0.74 0.98 0.76 0.46 0.80 0.94 0.66 0.72
#> [2,] 0.16 0.28 0.64 0.20 0.32 0.28 0.70 0.44 0.62 0.34 0.14 0.88
#> [3,] 0.66 0.24 0.60 0.62 0.16 0.98 0.70 0.18 0.24 0.48 0.40 0.08
#> [4,] 0.64 0.12 0.90 0.74 0.38 0.54 0.40 0.26 0.50 0.66 0.28 0.32
#> [5,] 0.42 0.98 0.98 0.20 0.88 0.88 0.28 0.40 0.56 0.66 0.24 0.72
#> [6,] 0.32 0.24 0.94 0.60 0.26 0.80 0.36 0.38 0.86 0.96 0.66 0.54
#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
#> [1,] 0.30 0.36 0.38 0.66 0.96 0.62 0.62 0.90 0.22 1.00 0.62 0.82
#> [2,] 0.58 0.06 0.86 0.50 0.80 0.92 0.50 0.92 0.54 0.46 0.92 0.96
#> [3,] 0.36 0.56 0.26 0.30 0.96 0.58 0.54 0.96 0.62 0.80 0.70 0.18
#> [4,] 0.72 0.66 0.78 0.54 0.56 0.54 0.84 0.34 0.90 0.98 0.52 0.94
#> [5,] 0.88 0.46 0.64 0.64 0.62 0.70 0.30 0.30 0.10 0.34 0.54 0.54
#> [6,] 0.80 0.88 0.56 0.38 0.36 0.62 0.90 0.12 0.32 0.28 0.08 0.50
#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,] 0.92 0.58 0.86 0.98 0.82 0.36 0.88 0.38 0.54 0.76 0.88 0.44
#> [2,] 0.46 0.00 0.66 0.80 0.90 0.94 0.80 0.72 0.12 0.62 0.88 0.46
#> [3,] 0.74 0.34 0.54 0.74 0.80 0.76 0.76 0.02 0.78 0.32 0.44 0.40
#> [4,] 0.78 0.56 0.70 0.40 0.98 0.58 0.72 0.40 0.92 0.26 0.26 0.72
#> [5,] 0.16 0.46 0.44 0.92 0.84 0.82 0.74 0.26 0.26 0.28 0.32 0.14
#> [6,] 0.22 0.12 0.70 0.82 0.26 0.30 0.84 0.64 0.34 0.06 0.22 0.18
library(bayesplot)
#> This is bayesplot version 1.9.0
#> - Online documentation and vignettes at mc-stan.org/bayesplot
#> - bayesplot theme set to bayesplot::theme_default()
#> * Does _not_ affect other ggplot2 plots
#> * See ?bayesplot_theme_set for details on theme setting
pp_check(output_HMDCM_RT_sep, type="total_latency")