Title: | Hidden Markov Cognitive Diagnosis Models for Learning |
---|---|
Description: | Fitting hidden Markov models of learning under the cognitive diagnosis framework. The estimation of the hidden Markov diagnostic classification model, the first order hidden Markov model, the reduced-reparameterized unified learning model, and the joint learning model for responses and response times. |
Authors: | Susu Zhang [aut], Shiyu Wang [aut], Yinghan Chen [aut], Sunbeom Kwon [aut, cre] |
Maintainer: | Sunbeom Kwon <[email protected]> |
License: | GPL (>= 2) |
Version: | 2.1.1 |
Built: | 2024-10-29 02:48:56 UTC |
Source: | https://github.com/tmsalab/hmcdm |
Fitting hidden Markov models of learning under the cognitive diagnosis framework. The estimation of the hidden Markov diagnostic classification model, the first order hidden Markov model, the reduced-reparameterized unified learning model, and the joint learning model for responses and response times.
Maintainer: Sunbeom Kwon [email protected]
Authors:
Susu Zhang [email protected]
Shiyu Wang [email protected]
Yinghan Chen [email protected]
Wang, S., Yang, Y., Culpepper, S. A., & Douglas, J. A. (2018) doi:10.3102/1076998617719727 "Tracking Skill Acquisition With Cognitive Diagnosis Models: A Higher-Order, Hidden Markov Model With Covariates."
Chen, Y., Culpepper, S. A., Wang, S., & Douglas, J. (2018) doi:10.1177/0146621617721250 "A hidden Markov model for learning trajectories in cognitive diagnosis with application to spatial rotation skills."
Wang, S., Zhang, S., Douglas, J., & Culpepper, S. (2018) doi:10.1080/15366367.2018.1435105 "Using Response Times to Assess Learning Progress: A Joint Model for Responses and Response Times."
Zhang, S., Douglas, J. A., Wang, S. & Culpepper, S. A. (2019) doi:10.1007/978-3-030-05584-4_24 "Reduced Reparameterized Unified Model Applied to Learning Spatial Rotation Skills."
Useful links:
Design_array
contains item administration information at all time points in the Spatial
Rotation Learning Program.
Design_array
Design_array
An array of dimension N-by-J-by-L, containing each subject's item administration.
The data object "Design_array"
contains an array of dimension N-by-J-by-L
indicating the items assigned (1/0) to each subject at each time point.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.
Based on the Q matrix and the latent attribute space, generate the ideal response matrix for each skill pattern
ETAmat(K, J, Q)
ETAmat(K, J, Q)
K |
An |
J |
An |
Q |
A J-by-K Q |
A J-by-2^K ideal response matrix
Q = random_Q(15,4) ETA = ETAmat(4,15,Q)
Q = random_Q(15,4) ETA = ETAmat(4,15,Q)
Runs MCMC to estimate parameters of any of the listed learning models.
hmcdm( Response, Q_matrix, model, Design_array = NULL, Test_order = NULL, Test_versions = NULL, chain_length = 100L, burn_in = 50L, G_version = NA_integer_, theta_propose = 0, Latency_array = NULL, deltas_propose = NULL, R = NULL )
hmcdm( Response, Q_matrix, model, Design_array = NULL, Test_order = NULL, Test_versions = NULL, chain_length = 100L, burn_in = 50L, G_version = NA_integer_, theta_propose = 0, Latency_array = NULL, deltas_propose = NULL, R = NULL )
Response |
An |
Q_matrix |
A J-by-K Q-matrix. |
model |
A |
Design_array |
An |
Test_order |
Optional. A |
Test_versions |
Optional. A |
chain_length |
An |
burn_in |
An |
G_version |
Optional. An |
theta_propose |
Optional. A |
Latency_array |
Optional. A |
deltas_propose |
Optional. A |
R |
Optional. A reachability |
A list
of parameter samples and Metropolis-Hastings acceptance rates (if applicable).
Susu Zhang
output_FOHM = hmcdm(Y_real_array, Q_matrix, "DINA_FOHM", Design_array, 100, 30)
output_FOHM = hmcdm(Y_real_array, Q_matrix, "DINA_FOHM", Design_array, 100, 30)
Based on the bijective relationship between natural numbers and sum of powers of two, convert integer between 0 and 2^K-1 to K-dimensional attribute pattern.
inv_bijectionvector(K, CL)
inv_bijectionvector(K, CL)
K |
An |
CL |
An |
A vec
of the K-dimensional attribute pattern corresponding to CL.
inv_bijectionvector(4,0)
inv_bijectionvector(4,0)
L_real_array
contains the observed latencies of responses of all subjects to all questions in the Spatial Rotation
Learning Program.
L_real_array
L_real_array
An array of dimensions N-by-J-by-L. Each slice of the array is an N-by-J matrix, containing the subjects' response times in seconds to each item at time point l.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.
Based on a response matrix, calculate the item pairwise odds-ratio according do (n11n00)/(n10n01), where nij is the number of people answering both item i and item j correctly
OddsRatio(N, J, Yt)
OddsRatio(N, J, Yt)
N |
An |
J |
An |
Yt |
An N-by-J response |
A J-by-J upper-triangular matrix
of the item pairwise odds ratios
N = dim(Y_real_array)[1] J = nrow(Q_matrix) OddsRatio(N,J,Y_real_array[,,1])
N = dim(Y_real_array)[1] J = nrow(Q_matrix) OddsRatio(N,J,Y_real_array[,,1])
pp_check
method for class hmcdm
.
## S3 method for class 'hmcdm' pp_check(object, plotfun = "dens_overlay", type = "total_score", ...)
## S3 method for class 'hmcdm' pp_check(object, plotfun = "dens_overlay", type = "total_score", ...)
object |
a fitted model object of class " |
plotfun |
A character string naming the type of plot. The list of available
plot functions include |
type |
A character string naming the statistic to be used for obtaining posterior predictive distribution plot.
The list of available types include |
... |
Additional arguments |
Plots for checking the posterior predictive distributions. The default Plotfun
"dens_overlay"
plots density of each dataset are overlaid with the distribution of the observed values.
Zhang, S., Douglas, J. A., Wang, S. & Culpepper, S. A. (2019) <doi:10.1007/978-3-030-05584-4_24>
bayesplot::ppc_dens_overlay()
bayesplot::ppc_stat()
bayesplot::ppc_stat_2d()
bayesplot::ppc_scatter_avg()
bayesplot::ppc_error_scatter_avg()
output_FOHM = hmcdm(Y_real_array,Q_matrix,"DINA_FOHM",Design_array,1000,500) library(bayesplot) pp_check(output_FOHM) pp_check(output_FOHM, plotfun="hist", type="item_mean")
output_FOHM = hmcdm(Y_real_array,Q_matrix,"DINA_FOHM",Design_array,1000,500) library(bayesplot) pp_check(output_FOHM) pp_check(output_FOHM, plotfun="hist", type="item_mean")
summary
method for class "hmcdm
" or "summary.hmcdm
".
## S3 method for class 'summary.hmcdm' print(x, ...) ## S3 method for class 'hmcdm' summary(object, ...)
## S3 method for class 'summary.hmcdm' print(x, ...) ## S3 method for class 'hmcdm' summary(object, ...)
x |
an object of class " |
... |
further arguments passed to or from other methods. |
object |
a fitted model object of class " |
The function summary.hmcdm
computes and returns a list
of point estimates of model parameters and model fit measures including DIC and PPP-values.
output_FOHM = hmcdm(Y_real_array,Q_matrix,"DINA_FOHM",Design_array,1000,500) summary(output_FOHM)
output_FOHM = hmcdm(Y_real_array,Q_matrix,"DINA_FOHM",Design_array,1000,500) summary(output_FOHM)
Generate a list of length N. Each element of the list is a JxK Q_matrix of all items administered across all time points to the examinee, in the order of administration.
Q_list_g(Q_matrix, Design_array)
Q_list_g(Q_matrix, Design_array)
Q_matrix |
A J-by-K matrix, indicating the item-skill relationship. |
Design_array |
An N-by-J-by-L array indicating whether examinee n has taken item j at l time point. |
A list length of N. Each element of the list is a JxK Q_matrix for each examinee.
Q_examinee = Q_list_g(Q_matrix, Design_array)
Q_examinee = Q_list_g(Q_matrix, Design_array)
Q_matrix
contains the Q matrix of the items in the Spatial Rotation Learning Program.
Q_matrix
Q_matrix
A J-by-K matrix, indicating the item-skill relationship.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.
Creates a random Q matrix containing three identity matrices after row permutation
random_Q(J, K)
random_Q(J, K)
J |
An |
K |
An |
A dichotomous matrix
for Q.
random_Q(15,4)
random_Q(15,4)
Generate a random transition matrix under nondecreasing learning trajectory assumption
rOmega(TP)
rOmega(TP)
TP |
A 2^K-by-2^K dichotomous matrix of indicating possible transitions under the monotonicity assumption, created with the TPmat function |
A 2^K-by-2^K transition matrix, the (i,j)th element indicating the transition probability of transitioning from i-th class to j-th class.
K = ncol(Q_matrix) TP = TPmat(K) Omega_sim = rOmega(TP)
K = ncol(Q_matrix) TP = TPmat(K) Omega_sim = rOmega(TP)
Based on the learning model parameters, create cube of attribute patterns of all subjects across time. Currently available learning models are Higher-order hidden Markov DCM('HO_sep'), Higher-order hidden Markov DCM with learning ability as a random effect('HO_joint'), the simple independent-attribute learning model('indept'), and the first order hidden Markov model('FOHM').
sim_alphas( model, lambdas = NULL, thetas = NULL, Q_matrix = NULL, Design_array = NULL, taus = NULL, Omega = NULL, N = NA_integer_, L = NA_integer_, R = NULL, alpha0 = NULL )
sim_alphas( model, lambdas = NULL, thetas = NULL, Q_matrix = NULL, Design_array = NULL, taus = NULL, Omega = NULL, N = NA_integer_, L = NA_integer_, R = NULL, alpha0 = NULL )
model |
The learning model under which the attribute trajectories are generated. Available options are: 'HO_joint', 'HO_sep', 'indept', 'FOHM'. |
lambdas |
A |
thetas |
A length N |
Q_matrix |
A J-by-K Q-matrix |
Design_array |
A N-by-J-by-L array indicating items administered to examinee n at time point l. |
taus |
A length K |
Omega |
A 2^K-by-2^K |
N |
An |
L |
An |
R |
A K-by-K dichotomous reachability |
alpha0 |
Optional. An N-by-K |
An N-by-K-by-L array
of attribute patterns of subjects at each time point.
## HO_joint ## N = nrow(Design_array) J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = TRUE) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } thetas_true = rnorm(N, 0, 1.8) lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) ## HO_sep ## N = dim(Design_array)[1] J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = L) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } thetas_true = rnorm(N) lambdas_true = c(-1, 1.8, .277, .055) Alphas <- sim_alphas(model="HO_sep", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) ## indept ## N = dim(Design_array)[1] K = dim(Q_matrix)[2] L = dim(Design_array)[3] tau <- numeric(K) for(k in 1:K){ tau[k] <- runif(1,.2,.6) } R = matrix(0,K,K) 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) ## FOHM ## N = dim(Design_array)[1] K = ncol(Q_matrix) L = dim(Design_array)[3] TP <- TPmat(K) Omega_true <- rOmega(TP) class_0 <- sample(1:2^K, N, replace = L) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } Alphas <- sim_alphas(model="FOHM", Omega = Omega_true, N=N, L=L)
## HO_joint ## N = nrow(Design_array) J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = TRUE) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } thetas_true = rnorm(N, 0, 1.8) lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) ## HO_sep ## N = dim(Design_array)[1] J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = L) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } thetas_true = rnorm(N) lambdas_true = c(-1, 1.8, .277, .055) Alphas <- sim_alphas(model="HO_sep", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) ## indept ## N = dim(Design_array)[1] K = dim(Q_matrix)[2] L = dim(Design_array)[3] tau <- numeric(K) for(k in 1:K){ tau[k] <- runif(1,.2,.6) } R = matrix(0,K,K) 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) ## FOHM ## N = dim(Design_array)[1] K = ncol(Q_matrix) L = dim(Design_array)[3] TP <- TPmat(K) Omega_true <- rOmega(TP) class_0 <- sample(1:2^K, N, replace = L) Alphas_0 <- matrix(0,N,K) for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } Alphas <- sim_alphas(model="FOHM", Omega = Omega_true, N=N, L=L)
Simulate a cube of responses from the specified model for all persons on items across all time points.
Currently available models are DINA
, rRUM
, and NIDA
.
sim_hmcdm( model, alphas, Q_matrix, Design_array, itempars = NULL, r_stars = NULL, pi_stars = NULL, Svec = NULL, Gvec = NULL )
sim_hmcdm( model, alphas, Q_matrix, Design_array, itempars = NULL, r_stars = NULL, pi_stars = NULL, Svec = NULL, Gvec = NULL )
model |
The cognitive diagnostic model under which the item responses are generated |
alphas |
An N-by-K-by-L |
Q_matrix |
A J-by-K of Q-matrix |
Design_array |
A N-by-J-by-L array indicating whether item j is administered to examinee i at l time point. |
itempars |
A J-by-2 |
r_stars |
A J-by-K |
pi_stars |
A length J |
Svec |
A length K |
Gvec |
A length K |
An array
of item responses from the specified model of examinees across all time points.
## DINA ## N = nrow(Design_array) J = nrow(Q_matrix) thetas_true = rnorm(N, 0, 1.8) lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) itempars_true <- matrix(runif(J*2,.1,.2), ncol=2) Y_sim <- sim_hmcdm(model="DINA",Alphas,Q_matrix,Design_array, itempars=itempars_true) ## rRUM ## J = nrow(Q_matrix) K = ncol(Q_matrix) Smats <- matrix(runif(J*K,.1,.3),c(J,K)) Gmats <- matrix(runif(J*K,.1,.3),c(J,K)) 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) ## NIDA ## K = ncol(Q_matrix) 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)
## DINA ## N = nrow(Design_array) J = nrow(Q_matrix) thetas_true = rnorm(N, 0, 1.8) lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) itempars_true <- matrix(runif(J*2,.1,.2), ncol=2) Y_sim <- sim_hmcdm(model="DINA",Alphas,Q_matrix,Design_array, itempars=itempars_true) ## rRUM ## J = nrow(Q_matrix) K = ncol(Q_matrix) Smats <- matrix(runif(J*K,.1,.3),c(J,K)) Gmats <- matrix(runif(J*K,.1,.3),c(J,K)) 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) ## NIDA ## K = ncol(Q_matrix) 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)
Simulate a cube of subjects' response times across time points according to a variant of the logNormal model
sim_RT(alphas, Q_matrix, Design_array, RT_itempars, taus, phi, G_version)
sim_RT(alphas, Q_matrix, Design_array, RT_itempars, taus, phi, G_version)
alphas |
An N-by-K-by-T |
Q_matrix |
A J-by-K Q-matrix for the test |
Design_array |
A N-by-J-by-L array indicating whether item j is administered to examinee i at l time point. |
RT_itempars |
A J-by-2 |
taus |
A length N |
phi |
A |
G_version |
An |
A cube
of response times of subjects on each item across time
N = dim(Design_array)[1] J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = TRUE) Alphas_0 <- matrix(0,N,K) mu_thetatau = c(0,0) Sig_thetatau = rbind(c(1.8^2,.4*.5*1.8),c(.4*.5*1.8,.25)) Z = matrix(rnorm(N*2),N,2) thetatau_true = Z%*%chol(Sig_thetatau) thetas_true = thetatau_true[,1] taus_true = thetatau_true[,2] G_version = 3 phi_true = 0.8 for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) RT_itempars_true <- matrix(NA, nrow=J, ncol=2) RT_itempars_true[,2] <- rnorm(J,3.45,.5) RT_itempars_true[,1] <- runif(J,1.5,2) ETAs <- ETAmat(K,J,Q_matrix) L_sim <- sim_RT(Alphas,Q_matrix,Design_array,RT_itempars_true,taus_true,phi_true,G_version)
N = dim(Design_array)[1] J = nrow(Q_matrix) K = ncol(Q_matrix) L = dim(Design_array)[3] class_0 <- sample(1:2^K, N, replace = TRUE) Alphas_0 <- matrix(0,N,K) mu_thetatau = c(0,0) Sig_thetatau = rbind(c(1.8^2,.4*.5*1.8),c(.4*.5*1.8,.25)) Z = matrix(rnorm(N*2),N,2) thetatau_true = Z%*%chol(Sig_thetatau) thetas_true = thetatau_true[,1] taus_true = thetatau_true[,2] G_version = 3 phi_true = 0.8 for(i in 1:N){ Alphas_0[i,] <- inv_bijectionvector(K,(class_0[i]-1)) } lambdas_true <- c(-2, .4, .055) Alphas <- sim_alphas(model="HO_joint", lambdas=lambdas_true, thetas=thetas_true, Q_matrix=Q_matrix, Design_array=Design_array) RT_itempars_true <- matrix(NA, nrow=J, ncol=2) RT_itempars_true[,2] <- rnorm(J,3.45,.5) RT_itempars_true[,1] <- runif(J,1.5,2) ETAs <- ETAmat(K,J,Q_matrix) L_sim <- sim_RT(Alphas,Q_matrix,Design_array,RT_itempars_true,taus_true,phi_true,G_version)
Test_order
contains the item block ordering corresponding to each test module.
Test_order
Test_order
A L-by-L matrix, each row is the order of item blocks for that test version.
Each row represents the test module number and shows the order of item blocks administered to a subject with the test module. For example, the first row is the order of item block administration (1-2-3-4-5) to subjects with test module 1.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.
Test_versions
contains each subject's test module in the Spatial Rotation Learning Program.
Test_versions
Test_versions
A vector of length N, containing each subject's assigned test module.
The data object "Test_versions"
contains a vector of length N indicating the test module assigned to each subject.
Each test module consists of multiple item blocks with different orders over L time points.
The order of item blocks corresponding to each test module is presented in the data object "Test_order"
.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.
Based on the latent attribute space, generate a matrix indicating whether it is possible to transition from pattern cc to cc' under the monotonicity learning assumption.
TPmat(K)
TPmat(K)
K |
An |
A 2^K-by-2^K dichotomous matrix
of whether it is possible to transition between two patterns
TP = TPmat(4)
TP = TPmat(4)
Y_real_array
contains each subject's observed response accuracy (0/1) at all time points in the Spatial
Rotation Learning Program.
Y_real_array
Y_real_array
An array of dimensions N-by-J-by-L. Each slice of the array is an N-by-J matrix, containing the subjects' response accuracy to each item at time point l.
Shiyu Wang, Yan Yang, Jeff Douglas, and Steve Culpepper
Spatial Rotation Learning Experiment at UIUC between Fall 2015 and Spring 2016.