#' betaMCMC
#'
#' Extract the MCMC sample for the difficulty parameter of each category
#' @param obj An object from BPRM or BPRM.DIF.
#' @param g If it is a DIF model, specify the group in interest.
betaMCMC = function(obj, g = 1) {
if(obj$DIF == TRUE){
codaSamples = obj$mcmc[[g]]
}else{
codaSamples = obj$mcmc
}
data = obj$data
item = obj$item
betaMCMC.matrix = NULL
codaSamples.matrix = as.matrix(codaSamples)
item.variable = data[,item]
if(min(apply(item.variable, 2, min,na.rm = TRUE)) == 0){item.variable = item.variable + 1}
K = apply(item.variable, 2, max,na.rm = TRUE)
p = ncol(item.variable)
for(i in 1:p){
betaMean = c()
for(j in 1:nrow(codaSamples.matrix)){
betaMean = c(betaMean, mean(codaSamples.matrix[j, paste0("beta[", i,",", 2:K[i],"]")]))
}
betaMCMC.matrix = cbind(betaMCMC.matrix, betaMean)
}
colnames(betaMCMC.matrix) = item
betaMCMC.matrix
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.