#' Convert raw score to logit score
#'
#' This function convert the raw score to logit score using RSM model assuming zero uncertainty
#' with beta and thres parameter
#'
#' @param data A data frame containing the data
#' @param item Item to be converted to logit score
#' @param beta beta parameter of RSM
#' @param thres Andrich threshold
#' @param n.chains Number of chains to be used in MCMC
#' @export raw2logit
raw2logit = function(data, item, beta, thres, n.chains){
item.variable = data[, item]
p = ncol(item.variable)
N = c(nrow(item.variable))
group = cbind(rep(1, N), seq(1, N, 1))
if(min(apply(item.variable, 2, min,na.rm = TRUE)) == 0){
item.variable = item.variable + 1
}
K = max(apply(item.variable, 2, max,na.rm = TRUE))
N = nrow(item.variable)
G = 1
model = runjags::run.jags(model = system.file("JAGS","R2L.txt", package = "BayesianRasch" ), monitor = c("beta", "theta", "thres"),
data = list(Y = as.matrix(item.variable), Gr = group, G = G, N = N, K = K, p = p,
beta = beta, thres = thres), n.chains = n.chains,
burnin = 0, adapt = 1000, sample = round(2100 / 3), method = "rjparallel")
mcmc = coda::as.mcmc.list(model)
n.chains = length(mcmc)
mcmc.matrix = NULL
for(i in 1:n.chains){mcmc.matrix = rbind(mcmc.matrix, mcmc[[i]][,])}
mcmc.matrix = BRSM.transform(mcmc.matrix, item, max(K))
obj = list(mcmc = mcmc.matrix, data = data, item = item, N = N, DIF = FALSE)
class(obj) = "BRSM"
obj
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.