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
#> 32 109 116 79 14
Smats <- matrix(runif(J*K,.1,.3),c(J,K))
Gmats <- matrix(runif(J*K,.1,.3),c(J,K))
# Simulate rRUM parameters
r_stars <- Gmats / (1-Smats)
pi_stars <- apply((1-Smats)^Q_matrix, 1, prod)
Y_sim <- sim_hmcdm(model="rRUM",Alphas,Q_matrix,Design_array,
r_stars=r_stars,pi_stars=pi_stars)
output_rRUM_indept = hmcdm(Y_sim,Q_matrix,"rRUM_indept",Design_array,
100,30,R = R)
#> 0
output_rRUM_indept
#>
#> Model: rRUM_indept
#>
#> Sample Size: 350
#> Number of Items:
#> Number of Time Points:
#>
#> Chain Length: 100, burn-in: 50
summary(output_rRUM_indept)
#>
#> Model: rRUM_indept
#>
#> Item Parameters:
#> r_stars1_EAP r_stars2_EAP r_stars3_EAP r_stars4_EAP pi_stars_EAP
#> 0.1885 0.6379 0.6926 0.5159 0.7307
#> 0.6714 0.3421 0.6172 0.5216 0.8714
#> 0.5984 0.5195 0.5161 0.3664 0.7284
#> 0.6309 0.6800 0.1704 0.6354 0.7295
#> 0.4450 0.3415 0.5388 0.6559 0.5081
#> ... 45 more items
#>
#> Transition Parameters:
#> taus_EAP
#> τ1 0.5000
#> τ2 0.2471
#> τ3 0.4094
#> τ4 0.3552
#>
#> Class Probabilities:
#> pis_EAP
#> 0000 0.03431
#> 0001 0.05942
#> 0010 0.08289
#> 0011 0.04864
#> 0100 0.13797
#> ... 11 more classes
#>
#> Deviance Information Criterion (DIC): 22371.21
#>
#> Posterior Predictive P-value (PPP):
#> M1: 0.516
#> M2: 0.49
#> total scores: 0.6098
a <- summary(output_rRUM_indept)
head(a$r_stars_EAP)
#> [,1] [,2] [,3] [,4]
#> [1,] 0.1885316 0.6379182 0.6925637 0.5159390
#> [2,] 0.6714242 0.3421459 0.6172373 0.5215577
#> [3,] 0.5983920 0.5195033 0.5160622 0.3664128
#> [4,] 0.6309239 0.6800379 0.1703724 0.6354255
#> [5,] 0.4449957 0.3414551 0.5387607 0.6559391
#> [6,] 0.6125392 0.3225775 0.2526698 0.6368034
(cor_pistars <- cor(as.vector(pi_stars),as.vector(a$pi_stars_EAP)))
#> [1] 0.9621922
(cor_rstars <- cor(as.vector(r_stars*Q_matrix),as.vector(a$r_stars_EAP*Q_matrix)))
#> [1] 0.950812
AAR_vec <- numeric(L)
for(t in 1:L){
AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.8621429 0.8985714 0.9285714 0.9514286 0.9657143
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.5428571 0.6685714 0.7514286 0.8200000 0.8714286
a$DIC
#> Transition Response_Time Response Joint Total
#> D_bar 2183.959 NA 17550.77 1879.046 21613.77
#> D(theta_bar) 2100.143 NA 16872.74 1883.459 20856.34
#> DIC 2267.776 NA 18228.80 1874.634 22371.21
head(a$PPP_total_scores)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.16 0.74 1.00 1.00 0.94
#> [2,] 0.66 0.40 0.90 0.76 0.56
#> [3,] 0.56 0.42 0.56 0.30 0.50
#> [4,] 0.70 0.78 0.62 0.26 0.86
#> [5,] 0.54 0.60 0.10 0.30 0.78
#> [6,] 0.70 0.96 0.16 0.42 0.64
head(a$PPP_item_means)
#> [1] 0.52 0.56 0.52 0.48 0.54 0.44
head(a$PPP_item_ORs)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,] NA 0.7 0.44 0.72 0.74 0.94 0.46 0.78 0.38 0.78 0.20 0.92 0.90 0.78
#> [2,] NA NA 0.90 0.04 0.24 0.62 0.86 0.94 0.44 0.62 0.72 0.80 0.78 0.76
#> [3,] NA NA NA 0.56 0.18 0.28 0.20 0.94 0.64 0.56 0.18 0.20 0.20 0.30
#> [4,] NA NA NA NA 0.92 0.58 0.84 0.72 0.46 0.62 0.24 0.90 0.66 0.82
#> [5,] NA NA NA NA NA 0.54 0.90 0.18 0.84 0.86 0.68 0.76 0.70 0.04
#> [6,] NA NA NA NA NA NA 0.76 0.80 0.88 0.42 0.86 0.58 0.32 0.98
#> [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,] 0.30 0.30 0.52 0.92 0.66 0.90 0.66 0.58 0.70 0.20 0.26 0.22
#> [2,] 0.56 0.98 0.50 0.78 0.28 0.22 0.54 0.34 0.62 0.88 0.60 0.04
#> [3,] 0.46 0.88 0.34 0.70 0.14 0.72 0.54 0.10 0.20 0.56 0.26 0.20
#> [4,] 0.58 0.38 0.74 0.00 0.26 0.14 0.16 0.40 0.68 0.36 0.14 0.54
#> [5,] 0.92 0.68 0.76 0.78 0.62 0.88 0.56 0.70 0.38 0.96 0.44 0.08
#> [6,] 0.48 0.54 0.76 0.80 0.74 0.74 0.26 0.48 0.54 0.70 0.84 0.24
#> [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
#> [1,] 0.98 1.00 0.76 0.50 0.22 0.14 0.82 1.00 0.00 0.62 0.16 0.20
#> [2,] 0.00 0.18 0.70 0.76 0.68 0.26 0.88 0.72 0.04 0.30 0.10 0.74
#> [3,] 0.40 0.06 0.52 0.08 0.50 0.10 0.52 0.08 0.20 0.70 0.50 0.82
#> [4,] 0.26 0.24 0.52 0.56 0.74 0.02 0.96 0.58 0.70 0.14 0.10 0.72
#> [5,] 0.84 0.58 0.24 0.74 0.72 0.16 0.40 0.86 0.74 0.08 0.10 0.30
#> [6,] 0.36 0.88 0.02 0.72 0.34 0.44 0.74 0.94 0.56 0.42 0.46 0.22
#> [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,] 0.64 0.94 0.38 0.52 0.86 0.58 0.04 0.62 0.60 0.26 0.48 0.16
#> [2,] 0.86 0.46 0.92 0.70 0.70 0.44 0.44 0.30 0.50 0.60 0.46 0.68
#> [3,] 0.32 0.80 0.86 0.74 0.64 0.04 0.64 0.34 0.38 0.94 0.44 0.68
#> [4,] 0.10 0.62 0.54 0.56 0.08 0.02 0.14 0.76 0.86 0.64 0.64 0.32
#> [5,] 0.76 0.92 0.40 0.86 0.66 0.42 0.20 0.58 0.34 0.68 0.82 0.34
#> [6,] 0.68 0.22 0.58 0.98 0.64 0.62 0.38 0.30 0.86 0.54 0.04 0.78