The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

rRUM_indept

library(hmcdm)

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 
#>  20  83 142  84  21
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.1345       0.5643       0.6930       0.5490       0.7087
#>        0.6633       0.2065       0.6031       0.5260       0.7942
#>        0.5607       0.5467       0.6871       0.2240       0.8623
#>        0.6092       0.5071       0.2707       0.5366       0.8333
#>        0.2328       0.2660       0.6640       0.5080       0.7193
#>    ... 45 more items
#> 
#> Transition Parameters:
#>    taus_EAP
#> τ1   0.4279
#> τ2   0.4181
#> τ3   0.5759
#> τ4   0.5375
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000 0.08429
#> 0001 0.08398
#> 0010 0.04602
#> 0011 0.01500
#> 0100 0.13739
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 22929.56 
#> 
#> Posterior Predictive P-value (PPP):
#> M1:   0.5
#> M2:  0.49
#> total scores:  0.6105
a <- summary(output_rRUM_indept)
head(a$r_stars_EAP)
#>           [,1]      [,2]      [,3]      [,4]
#> [1,] 0.1344617 0.5643205 0.6929589 0.5490303
#> [2,] 0.6633021 0.2064912 0.6030876 0.5260488
#> [3,] 0.5606544 0.5467405 0.6871179 0.2240308
#> [4,] 0.6092055 0.5070976 0.2707032 0.5365697
#> [5,] 0.2328241 0.2660043 0.6640119 0.5080245
#> [6,] 0.5585330 0.3077579 0.3372768 0.5225505

(3) Check for parameter estimation accuracy

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

AAR_vec <- numeric(L)
for(t in 1:L){
  AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.8478571 0.9007143 0.9357143 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.5257143 0.6714286 0.7828571 0.8685714 0.8971429

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

a$DIC
#>              Transition Response_Time Response    Joint    Total
#> D_bar          2090.404            NA 18302.17 1783.206 22175.78
#> D(theta_bar)   2037.153            NA 17630.88 1753.971 21422.00
#> DIC            2143.655            NA 18973.47 1812.440 22929.56
head(a$PPP_total_scores)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.00 0.92 1.00 0.90 1.00
#> [2,] 0.58 0.46 0.54 0.52 0.46
#> [3,] 0.64 0.58 0.54 0.76 1.00
#> [4,] 0.36 0.60 0.78 0.86 0.48
#> [5,] 0.44 0.56 0.48 0.66 0.60
#> [6,] 0.44 0.72 0.84 0.72 0.52
head(a$PPP_item_means)
#> [1] 0.42 0.54 0.42 0.50 0.50 0.54
head(a$PPP_item_ORs)
#>      [,1] [,2] [,3] [,4] [,5] [,6]      [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,]   NA 0.36 0.46 0.38 0.74 0.82 0.8979592 0.34 0.70  0.34  0.52  0.34  0.80
#> [2,]   NA   NA 0.80 0.20 0.64 0.46 0.6734694 0.32 0.16  0.12  0.90  0.32  0.48
#> [3,]   NA   NA   NA 0.68 0.88 0.76 0.4285714 0.62 0.92  0.54  0.06  0.50  0.44
#> [4,]   NA   NA   NA   NA 0.04 0.52 0.5102041 0.54 0.38  0.92  0.72  0.88  0.42
#> [5,]   NA   NA   NA   NA   NA 0.50 0.2040816 0.48 0.32  0.60  0.06  0.58  0.44
#> [6,]   NA   NA   NA   NA   NA   NA 0.7755102 0.96 0.80  0.72  0.50  0.80  0.24
#>      [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#> [1,]  0.42  0.12  0.44  0.20  0.84  0.74  0.60  0.72  0.28  0.12  0.24  0.76
#> [2,]  0.38  0.34  0.62  0.48  0.42  0.52  0.70  0.32  1.00  0.92  0.92  1.00
#> [3,]  0.56  0.34  0.08  0.28  0.00  0.02  0.66  0.26  0.24  0.12  0.42  0.56
#> [4,]  0.60  0.04  0.08  0.76  0.06  0.48  0.86  0.16  0.26  0.86  0.48  0.06
#> [5,]  0.06  0.22  0.42  0.16  0.56  0.16  0.90  0.80  0.22  0.54  0.88  0.90
#> [6,]  0.78  0.38  0.40  0.74  0.16  0.38  0.32  0.14  0.50  0.28  0.02  0.20
#>      [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34] [,35] [,36] [,37]
#> [1,]  0.04  0.44  0.22  0.44  0.84  0.14  0.82  0.58  0.80  0.44  0.40  0.38
#> [2,]  0.12  0.50  0.72  0.40  0.68  0.92  0.94  1.00  0.42  0.10  0.70  0.16
#> [3,]  0.12  0.52  0.76  0.74  0.26  0.76  0.54  0.22  0.64  0.90  0.84  0.18
#> [4,]  0.30  0.02  0.42  0.20  0.32  0.66  0.06  0.46  0.22  0.00  0.08  0.08
#> [5,]  0.16  0.30  0.22  0.70  0.60  0.50  0.96  0.32  0.38  0.74  0.92  0.04
#> [6,]  0.62  0.04  0.12  0.10  0.02  0.82  0.20  0.04  0.08  0.34  0.26  0.08
#>      [,38] [,39] [,40] [,41] [,42] [,43] [,44] [,45] [,46] [,47] [,48] [,49]
#> [1,]  0.06  0.38  0.36  0.72  0.32  0.54  0.74  0.08  0.54  0.84  0.40  0.10
#> [2,]  0.34  0.56  0.48  0.86  0.44  0.48  0.74  0.72  0.16  0.84  0.66  0.18
#> [3,]  0.46  0.54  0.72  0.10  0.50  0.78  0.98  0.52  0.84  0.94  0.84  0.74
#> [4,]  0.22  0.86  0.12  0.36  0.88  0.60  0.26  0.32  0.18  0.38  0.04  0.52
#> [5,]  0.08  0.30  0.86  0.94  0.62  0.80  0.88  0.18  0.52  0.62  1.00  0.36
#> [6,]  0.22  0.26  0.68  0.56  0.94  0.96  0.76  0.48  0.64  0.92  0.54  0.98
#>      [,50]
#> [1,]  0.64
#> [2,]  0.10
#> [3,]  0.46
#> [4,]  0.56
#> [5,]  0.28
#> [6,]  0.96

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.