R/methods_sta_cmr.R

Defines functions summary.sta_cmr

#' @export
print.sta_cmr <- function (x, 
                          digits = max(3, getOption("digits") - 3), 
                          varnames = TRUE,
                          ...) {
  cat("\n", toupper(deparse(x$call[[1]])), 
      " fit to ", nrow(x$estimate), " data points with call:\n", 
      paste(deparse(x$call), sep = "\n", collapse = "\n"), "\n\n",
      sep = "")
  
  if (varnames) {
    cat("DVs:", paste0(names(x$data_list[[1]]), collapse = " & "), "\n")
    cat("Within:",  attr(x$data_list, "varnames")["within"], "\n")
    cat("Between:",  attr(x$data_list, "varnames")["between"], "\n\n") 
  }
  
  cat("Fit value (", attr(x, "value_fit"), "): ", 
      format(x$fit, digits = digits), 
      "\n", 
      sep = "")
  if (deparse(x$call[[1]]) == "cmr") {
    cat("Fit difference to MR model (", attr(x, "value_fit"), "): ", 
      format(x$fit_diff, digits = digits), 
      "\n", 
      sep = "")
  }
  cat("p-value (based on", attr(x, "nsample"), "samples):",  
      x$p, "\n")
  cat("\n")
  invisible(x)
}

#' @export
summary.sta_cmr <- function(object, 
                           digits = max(3, getOption("digits") - 3), 
                           ...) {
  
  print(object, digits = digits, varnames = FALSE)
  
  cat("Estimated cell means:\n")
  print.data.frame(object$estimate, digits = digits)
  cat("\n")
  invisible(object$estimate)
}
monotonicity/stacmr documentation built on Jan. 28, 2020, 3:29 a.m.