R/beta.R

Defines functions beta

Documented in beta

#' Beta
#'
#' Get the difficulty of each item from a BPRM object.
#'
#'
#' @param obj An object from BPRM or BPRM.DIF.
#' @param g If the object is from BPRM.DIF, g is the group of subject
#' @export beta

beta = function(obj, g = 1) {
  if(obj$DIF == TRUE){
    codaSamples = obj$mcmc[[g]]
  }else{
    codaSamples = obj$mcmc
  }
  item = obj$item
  if(class(obj) == "BPCM"){
    out = t(HDInterval::hdi(betaMCMC(obj, g)))
    out = cbind(out, apply(betaMCMC(obj, g), 2, mean))
    round(out, 2)
  }else if (class(obj) == "BRSM"){
    matrix = t(HDInterval::hdi(codaSamples[,paste0("beta[", 1:length(item), "]")]))
    out = c()
    for(i in 1:length(item)){out = c(out, mean(codaSamples[,paste0("beta[", i, "]")]))}
    round(cbind(matrix, mean = out), 2)
  }
}
changxiulee/BayesianRasch documentation built on Nov. 18, 2019, 6:54 a.m.