R/autocor.plot.R

Defines functions autocor.plot autocorPlot

Documented in autocor.plot autocorPlot

#' Autocorrelation Plot
#'
#' Plots current vs lagged residuals along with quadrants dividing these
#' residuals about the value zero.
#'
#'
#' @param fit output from the function 'lm()'.
#' @param main the plot title.
#' @param \ldots extra parameters to be passed to the \code{plot} function.
#' @return Plots current vs lagged residuals along with quadrants dividing
#' these residuals about the value zero.
#' @keywords hplot
#' @examples
#'
#' data(airpass.df)
#' time = 1:144
#' airpass.fit = lm(passengers ~ time, data = airpass.df)
#' autocorPlot(airpass.fit)
#'
#' @export autocorPlot
#' @note \code{autocor.plot} is deprecated and no longer exported.
#'   Use \code{autocorPlot()} in new code.
autocorPlot = function(fit, main = "Current vs Lagged residuals", ...) {
  currentRes = fit$residuals[-1]
  residualCount = length(fit$residuals)
  laggedRes = fit$residuals[-residualCount]
  plot(currentRes ~ laggedRes, main = main, ...)
  ab = lm(currentRes ~ laggedRes)$coeff
  ## abline(ab[1],ab[2],lty=2)
  abline(v = 0, lty = 3)
  abline(h = 0, lty = 3)
}


#' Deprecated autocorrelation plot alias
#'
#' Provides a deprecated compatibility alias for `autocorPlot()`.
#'
#' @param fit output from the function `lm()`.
#' @param main the plot title.
#' @param ... extra parameters passed to `autocorPlot()`.
#' @return Invisibly returns the result of `autocorPlot()`, called for its
#' plotting side effect.
#' @keywords internal
autocor.plot = function(fit, main = "Current vs Lagged residuals", ...) {
  .Deprecated(
    new = "autocorPlot",
    msg = "autocor.plot() is deprecated and is no longer exported; use autocorPlot() instead."
  )
  autocorPlot(fit = fit, main = main, ...)
}

Try the s20x package in your browser

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

s20x documentation built on July 1, 2026, 9:06 a.m.