tau <- numeric(K)
for(k in 1:K){
tau[k] <- runif(1,.2,.6)
}
R = matrix(0,K,K)
# Initial alphas
p_mastery <- c(.5,.5,.4,.4)
Alphas_0 <- matrix(0,N,K)
for(i in 1:N){
for(k in 1:K){
prereqs <- which(R[k,]==1)
if(length(prereqs)==0){
Alphas_0[i,k] <- rbinom(1,1,p_mastery[k])
}
if(length(prereqs)>0){
Alphas_0[i,k] <- prod(Alphas_0[i,prereqs])*rbinom(1,1,p_mastery)
}
}
}
Alphas <- sim_alphas(model="indept",taus=tau,N=N,L=L,R=R,alpha0=Alphas_0)
table(rowSums(Alphas[,,5]) - rowSums(Alphas[,,1])) # used to see how much transition has taken place
#>
#> 0 1 2 3 4
#> 23 111 139 64 13
Svec <- runif(K,.1,.3)
Gvec <- runif(K,.1,.3)
Y_sim <- sim_hmcdm(model="NIDA",Alphas,Q_matrix,Design_array,
Svec=Svec,Gvec=Gvec)
output_NIDA_indept = hmcdm(Y_sim, Q_matrix, "NIDA_indept", Design_array,
100, 30, R = R)
#> 0
output_NIDA_indept
#>
#> Model: NIDA_indept
#>
#> Sample Size: 350
#> Number of Items:
#> Number of Time Points:
#>
#> Chain Length: 100, burn-in: 50
summary(output_NIDA_indept)
#>
#> Model: NIDA_indept
#>
#> Item Parameters:
#> ss_EAP gs_EAP
#> 0.2344 0.2044
#> 0.1098 0.1313
#> 0.2169 0.2628
#> 0.2688 0.1426
#>
#> Transition Parameters:
#> taus_EAP
#> τ1 0.2394
#> τ2 0.2876
#> τ3 0.4735
#> τ4 0.5251
#>
#> Class Probabilities:
#> pis_EAP
#> 0000 0.05722
#> 0001 0.04660
#> 0010 0.07692
#> 0011 0.04191
#> 0100 0.10985
#> ... 11 more classes
#>
#> Deviance Information Criterion (DIC): 21825.83
#>
#> Posterior Predictive P-value (PPP):
#> M1: 0.5036
#> M2: 0.49
#> total scores: 0.6088
a <- summary(output_NIDA_indept)
head(a$ss_EAP)
#> [,1]
#> [1,] 0.2343828
#> [2,] 0.1097769
#> [3,] 0.2168630
#> [4,] 0.2688473
AAR_vec <- numeric(L)
for(t in 1:L){
AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.8771429 0.9107143 0.9492857 0.9642857 0.9735714
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.5942857 0.6828571 0.8171429 0.8657143 0.9057143
a$DIC
#> Transition Response_Time Response Joint Total
#> D_bar 2061.939 NA 17234.58 1890.680 21187.19
#> D(theta_bar) 1947.064 NA 16704.23 1897.271 20548.56
#> DIC 2176.815 NA 17764.92 1884.089 21825.83
head(a$PPP_total_scores)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.00 1.00 1.00 1.00 1.00
#> [2,] 0.78 0.34 0.72 0.48 0.42
#> [3,] 0.82 0.04 0.80 0.80 0.56
#> [4,] 0.58 0.42 0.74 0.78 0.00
#> [5,] 0.64 0.34 0.98 0.70 0.48
#> [6,] 0.58 0.44 0.96 0.94 0.06
head(a$PPP_item_means)
#> [1] 0.84 0.60 0.92 0.46 0.08 0.16
head(a$PPP_item_ORs)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] NA 0.82 0.76 0.14 0.70 0.96 0.72 0.62 0.52 0.70 0.12 0.20 0.76 0.72
#> [2,] NA NA 0.86 0.86 0.76 0.44 0.70 0.96 0.90 0.62 0.24 1.00 0.52 0.84
#> [3,] NA NA NA 0.62 0.68 0.36 0.74 0.34 0.96 0.82 0.22 0.16 0.22 0.24
#> [4,] NA NA NA NA 0.64 0.54 0.38 0.88 0.92 0.48 0.52 0.24 0.06 0.48
#> [5,] NA NA NA NA NA 0.42 0.90 0.94 0.52 0.82 0.96 0.86 0.98 0.94
#> [6,] NA NA NA NA NA NA 0.08 1.00 0.86 0.42 0.34 0.94 0.42 0.58
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,] 0.14 0.46 0.28 0.28 0.70 0.52 0.66 0.80 0.30 0.70 0.92 0.92
#> [2,] 0.58 0.58 0.90 0.06 0.12 0.50 0.54 0.52 0.32 0.38 0.32 1.00
#> [3,] 0.56 0.12 0.36 0.02 0.68 0.22 0.64 0.00 0.00 0.46 0.36 0.92
#> [4,] 0.28 0.60 0.60 0.44 0.22 0.30 0.76 0.38 0.50 0.94 0.76 0.32
#> [5,] 0.50 0.30 0.86 0.76 0.40 0.40 0.34 0.68 0.56 0.24 0.22 0.16
#> [6,] 0.36 0.46 0.62 0.02 0.24 0.16 0.28 0.40 0.02 0.56 0.94 0.94
#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
#> [1,] 0.92 0.20 0.62 0.14 0.22 0.58 0.02 0.04 0.28 0.04 0.40 0.64
#> [2,] 0.44 0.88 0.76 0.48 0.92 0.24 0.46 0.38 0.64 0.56 0.94 0.96
#> [3,] 0.06 0.22 0.38 0.04 0.92 0.96 0.80 0.56 0.66 0.42 0.86 0.06
#> [4,] 0.70 0.88 0.94 0.62 0.84 0.82 0.96 0.46 0.62 0.26 0.26 0.36
#> [5,] 0.82 1.00 0.58 0.42 0.78 0.10 0.90 0.26 0.32 0.62 0.54 0.44
#> [6,] 0.12 0.84 0.34 0.38 0.32 0.46 0.86 0.40 0.48 0.20 0.92 0.64
#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,] 0.34 0.86 0.90 0.96 0.14 0.22 0.50 0.82 0.52 0.98 0.64 0.98
#> [2,] 0.14 0.94 0.42 0.52 0.78 0.30 0.78 0.64 0.10 0.32 0.70 0.90
#> [3,] 0.30 0.76 0.98 0.22 0.32 0.50 0.82 0.16 0.70 0.66 0.38 0.30
#> [4,] 0.32 0.34 0.64 0.14 0.52 0.64 0.52 0.30 0.36 0.94 0.64 0.02
#> [5,] 0.08 0.88 0.74 0.70 0.12 0.56 0.86 0.88 0.20 1.00 0.98 0.88
#> [6,] 0.18 0.68 0.42 0.24 0.84 0.50 0.12 0.70 0.34 0.28 0.64 0.70