R/summary.dmcfit.R

Defines functions summary.dmcfit

Documented in summary.dmcfit

#' @title summary.dmcfit
#'
#' @description Summary of the simulation results from dmcFitAgg/dmcFitVPs.
#'
#' @param object Output from dmcFit
#' @param ... pars
#'
#' @return tibble
#'
#' @examples
#' \dontrun{
#' library(DMCfun)
#'
#' # Example 1
#' fitAgg <- dmcFitAgg(flankerData, nTrl = 1000)
#' summary(fitAgg)
#' plot(fitAgg, flankerData)
#'
#' # Example 2
#' fitVPs <- dmcFitVPs(flankerData, nTrl = 1000)
#' summary(fitVPs)
#' fit <- mean(fitVPs)
#' plot(fit, flankerData)
#' }
#'
#' @export
summary.dmcfit <- function(object, ...) {

  if ("par" %in% names(object[[2]])) {

    out           <- tibble::as_tibble(cbind(t(object[[2]][[1]]), object[[2]][[2]]))
    colnames(out) <- c("amp", "tau", "mu", "bnds", "resMean", "resSD", "aaShape", "spShape", "sigma", "rmse")

  } else {

    outVP <- tibble::as_tibble(cbind(VP = which(!unlist(lapply(object, is.null))),
                                     do.call(rbind, lapply(lapply(object, `[[`, 2), `[[`, 1)),
                                     do.call(rbind, lapply(lapply(object, `[[`, 2), `[[`, 2))))
    outAvg <- tibble::as_tibble(t(c(VP = NA,  colMeans(outVP[,c(2:10)]))))

    out <- rbind(outVP, outAvg)
    colnames(out) <- c("VP", "amp", "tau", "mu", "bnds", "resMean", "resSD", "aaShape", "spShape", "sigma", "rmse")

  }

  return(out)

}
igmmgi/DMCfun documentation built on March 25, 2020, 3:20 p.m.