Load the spatial rotation data

N = dim(Design_array)[1]
J = nrow(Q_matrix)
K = ncol(Q_matrix)
L = dim(Design_array)[3]

(1) Simulate responses and response times based on the rRUM model

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 
#>  30 125 113  72  10
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)

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

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.1281       0.6022       0.6140       0.5372       0.7864
#>        0.6159       0.1664       0.5707       0.6832       0.8402
#>        0.5312       0.6961       0.6581       0.1755       0.7684
#>        0.5795       0.6583       0.2989       0.5328       0.8023
#>        0.3074       0.1266       0.6589       0.5704       0.7047
#>    ... 45 more items
#> 
#> Transition Parameters:
#>    taus_EAP
#> τ1   0.2907
#> τ2   0.5182
#> τ3   0.4751
#> τ4   0.2705
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000 0.10465
#> 0001 0.03145
#> 0010 0.03940
#> 0011 0.05401
#> 0100 0.09308
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 22844.89 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.5032
#> M2:  0.49
#> total scores:  0.6134
a <- summary(output_rRUM_indept)
head(a$r_stars_EAP)
#>           [,1]      [,2]      [,3]      [,4]
#> [1,] 0.1280841 0.6022223 0.6139969 0.5371909
#> [2,] 0.6159241 0.1663760 0.5707260 0.6831840
#> [3,] 0.5311502 0.6960942 0.6581206 0.1754828
#> [4,] 0.5795478 0.6583230 0.2989036 0.5327879
#> [5,] 0.3074269 0.1266272 0.6589252 0.5704463
#> [6,] 0.5237355 0.4366900 0.2256707 0.6139193

(3) Check for parameter estimation accuracy

(cor_pistars <- cor(as.vector(pi_stars),as.vector(a$pi_stars_EAP)))
#> [1] 0.9549489
(cor_rstars <- cor(as.vector(r_stars*Q_matrix),as.vector(a$r_stars_EAP*Q_matrix)))
#> [1] 0.9452464

AAR_vec <- numeric(L)
for(t in 1:L){
  AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.8707143 0.9021429 0.9357143 0.9492857 0.9585714

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.5771429 0.6628571 0.7600000 0.8142857 0.8485714

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

a$DIC
#>              Transition Response_Time Response    Joint    Total
#> D_bar          2116.166            NA 18144.13 1840.431 22100.73
#> D(theta_bar)   2025.948            NA 17513.28 1817.330 21356.56
#> DIC            2206.384            NA 18774.97 1863.532 22844.89
head(a$PPP_total_scores)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.26 0.04 0.02 0.26 0.00
#> [2,] 0.52 0.70 0.46 0.66 0.44
#> [3,] 0.84 0.96 0.28 0.10 0.84
#> [4,] 0.62 0.06 0.62 0.62 0.84
#> [5,] 0.76 0.58 0.40 0.76 0.78
#> [6,] 0.70 0.26 0.84 0.54 0.58
head(a$PPP_item_means)
#> [1] 0.34 0.66 0.50 0.56 0.54 0.58
head(a$PPP_item_ORs)
#>      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14]
#> [1,]   NA 0.62  0.3 0.98 0.92 0.34 0.70 0.72 0.94  0.64  0.02  0.30  0.84  0.52
#> [2,]   NA   NA  1.0 0.42 0.68 0.60 0.46 0.90 0.40  0.52  0.06  0.96  0.06  0.98
#> [3,]   NA   NA   NA 0.78 0.96 0.74 0.08 0.74 0.10  0.00  0.24  1.00  0.06  0.56
#> [4,]   NA   NA   NA   NA 0.22 0.36 0.08 0.80 0.76  0.30  0.20  0.04  0.86  0.42
#> [5,]   NA   NA   NA   NA   NA 0.72 0.52 0.94 0.90  0.52  0.28  0.62  0.26  0.44
#> [6,]   NA   NA   NA   NA   NA   NA 0.16 0.94 0.80  0.24  0.90  0.34  0.02  0.02
#>      [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25] [,26]
#> [1,]  0.92  0.26  0.28  0.12  0.74  0.48  0.56  0.06  0.82  0.50  0.56  0.02
#> [2,]  0.30  0.38  0.88  0.22  0.48  0.70  0.78  0.72  0.34  0.84  0.16  0.94
#> [3,]  0.70  0.22  0.76  0.66  0.76  0.62  0.92  0.66  0.22  0.06  0.30  0.24
#> [4,]  0.96  0.56  0.12  0.82  0.76  0.68  0.46  0.78  0.82  0.40  0.86  0.52
#> [5,]  0.72  0.28  0.36  0.14  0.84  0.06  0.88  0.62  0.62  0.46  0.48  0.74
#> [6,]  0.00  0.04  0.20  0.72  0.66  0.28  0.66  0.26  0.90  0.22  0.00  0.34
#>      [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37] [,38]
#> [1,]  0.86  0.80  0.72  0.98  0.40  0.66  0.52  0.30  0.88  0.88  0.74  0.34
#> [2,]  0.64  0.62  0.74  0.96  0.86  0.84  0.70  0.32  0.68  0.72  0.92  0.74
#> [3,]  0.52  0.32  0.76  0.60  0.12  0.02  0.28  0.90  0.08  0.96  0.70  0.90
#> [4,]  1.00  0.74  0.16  0.68  0.52  0.82  0.60  0.94  0.34  0.06  0.98  0.54
#> [5,]  0.84  0.70  0.40  0.74  0.40  0.42  0.40  0.16  0.96  0.68  0.74  0.30
#> [6,]  0.20  0.44  0.60  0.08  0.22  0.38  0.88  0.28  0.72  0.74  0.20  0.46
#>      [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49] [,50]
#> [1,]  0.64  0.40  0.52  0.56  0.72  0.84  0.74  0.90  0.82  0.72  0.40  0.86
#> [2,]  0.82  0.84  0.70  0.24  0.84  0.96  0.66  0.94  0.56  0.56  0.38  0.58
#> [3,]  0.78  0.12  0.44  0.04  0.30  1.00  0.32  0.18  0.82  0.42  0.46  0.54
#> [4,]  0.98  0.68  0.78  0.54  0.86  0.94  0.84  0.16  0.16  0.00  0.00  0.30
#> [5,]  0.84  0.92  0.50  0.72  0.84  0.32  0.74  0.48  0.96  0.78  1.00  0.60
#> [6,]  0.30  0.84  0.90  0.12  0.12  0.90  0.28  0.04  0.44  0.20  0.38  0.70