R/ggtestinfo_se.R

Defines functions ggtestinfo_se

Documented in ggtestinfo_se

#' A Function for Creating  Publication Quality Item Response Theory based test information plot with standard error.
#'
#' This function will create publication worthy Item Response Theory based Test information plot with standard error using ggplot2 from objects created from
#' mirt pack.
#' Using ggplot2 will enable the user to modify the Item plot.
#'
#' @param  dataframe your data.
#' @param  model A mirt package fitted object.
#'@examples
#'data <- tabledown::Rotter[, 11:31]
#'model <- mirt::mirt(data, model = 1, itemtype = '2PL')
#'
#'plot <- ggtestinfo(data, model)
#'@return
#'A publication quality Test information plot with standard error (dashed line). Output object is a ggplot object.


#'@importFrom mirt extract.item iteminfo
#'
#' @export
ggtestinfo_se <- function(dataframe,model){
  Theta <- matrix(seq(-6,6, by = .1))
  T1 <- 0

  for(i in 1:ncol(dataframe)){
    T1 <- T1 + mirt::iteminfo(extract.item(model, i), Theta)
    se <- 1/(sqrt(T1))
  }

  data <- as.data.frame(cbind(Theta, T1, se))
  p1 <- ggplot2::ggplot(data, ggplot2::aes(x=Theta, y=T1)) +
    ggplot2::geom_line()+
    ggplot2::geom_line(data = data,linetype = "dashed",color = "red", ggplot2::aes(x=Theta, y=se))+
    ggplot2::xlab(expression(theta)) +
    ggplot2::ylab(expression(I(theta)))+ ggplot2::theme(legend.title=ggplot2::element_blank())

  return(p1)
}
m-a-siraji/BAAP documentation built on May 7, 2024, 12:54 p.m.