R/predict_adjust-print.R

Defines functions print.predict_adjust

Documented in print.predict_adjust

#' Print \code{predict_adjust} object
#'
#' Print an object of class \code{predict_adjust} produced
#' by the \code{\link[api2lm]{predict_adjust}} function.
#'
#' @param x An \code{predict_adjust} object produced by the
#'   \code{\link[api2lm]{predict_adjust}} function.
#' @param ... Additional arguments to the
#'   \code{\link[base]{print.default}} function, such as
#'   \code{digits}.
#' @return NULL
#' @author Joshua French
#' @export
#' @return Depending on the \code{interval} argument of
#' \code{\link[api2lm]{predict_adjust}}:
#'
#' A vector of predictions if \code{interval = "none"}.
#'
#' A matrix of predictions and bounds with column names
#' \code{fit}, \code{lwr}, and \code{upr} if
#' \code{interval} is set. For \code{type = "terms"} this
#' is a matrix with a column per term and may have an
#' attribute \code{"constant"}.
#'
#' If \code{se.fit} is \code{TRUE}, a
#' list with the following components is returned:
#' \itemize{
#'  \item{\code{fit}}{: vector or matrix as above}
#'  \item{\code{se.fit}}{: standard error of predicted means}
#'  \item{\code{residual.scale}}{: residual standard deviations}
#'  \item{\code{df}}{: degrees of freedom for residual}
#' }
#' @examples
#' fit <- lm(100/mpg ~ disp + hp + wt + am, data = mtcars)
#' (cia <- predict_adjust(fit))
#' print(cia, digits = 3)
print.predict_adjust = function(x, ...) {
  method <- attr(x, "method")
  interval <- attr(x, "interval")
  if(interval != "none") {
    if (method == "none") {
      cat(paste("\nUnadjusted", interval, "intervals\n"))
    } else if (method == "scheffe") {
      cat(paste("\nScheffe-adjusted", interval, "intervals\n"))
    } else if (method == "bonferroni") {
      cat(paste("\nBonferroni-adjusted", interval, "intervals\n"))
    } else if (method == "wh") {
      cat(paste("\nWorking-Hotelling-adjusted", interval, "intervals\n"))
    }
    cat(paste("\nFamily-wise confidence level of at least",
              attr(x, "adj_level")),"\n\n")
  }

  if (is.element("matrix", class(x))) {
    print.default(x[seq_len(nrow(x)),], ...)
  } else {
    print.default(x[seq_along(x)], ...)
  }
}

Try the api2lm package in your browser

Any scripts or data that you put into this service are public.

api2lm documentation built on July 9, 2023, 5:52 p.m.