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.

NIDA_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 NIDA 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  96 156  65  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)

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

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.2655 0.2242
#>  0.2151 0.2383
#>  0.1901 0.2788
#>  0.1296 0.3105
#> 
#> Transition Parameters:
#>    taus_EAP
#> τ1   0.4003
#> τ2   0.3330
#> τ3   0.5419
#> τ4   0.4910
#> 
#> Class Probabilities:
#>      pis_EAP
#> 0000 0.07875
#> 0001 0.11993
#> 0010 0.06023
#> 0011 0.01711
#> 0100 0.06114
#>    ... 11 more classes
#> 
#> Deviance Information Criterion (DIC): 23468.5 
#> 
#> Posterior Predictive P-value (PPP):
#> M1: 0.478
#> M2:  0.49
#> total scores:  0.6039
a <- summary(output_NIDA_indept)
head(a$ss_EAP)
#>           [,1]
#> [1,] 0.2655415
#> [2,] 0.2151101
#> [3,] 0.1900912
#> [4,] 0.1295927

(3) Check for parameter estimation accuracy

AAR_vec <- numeric(L)
for(t in 1:L){
  AAR_vec[t] <- mean(Alphas[,,t]==a$Alphas_est[,,t])
}
AAR_vec
#> [1] 0.8178571 0.8892857 0.9257143 0.9535714 0.9628571

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.4657143 0.6371429 0.7400000 0.8314286 0.8628571

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

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

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.