Over a million developers have joined DZone.

Plotting the characteristic roots for ARIMA models

· Big Data Zone

Read this eGuide to discover the fundamental differences between iPaaS and dPaaS and how the innovative approach of dPaaS gets to the heart of today’s most pressing integration problems, brought to you in partnership with Liaison.

When modelling data with ARIMA models, it is sometimes useful to plot the inverse characteristic roots. The following functions will compute and plot the inverse roots for any fitted ARIMA model (including seasonal models).

# Compute AR roots
arroots <- function(object)
  if(class(object) != "Arima" & class(object) != "ar")
    stop("object must be of class Arima or ar")
  if(class(object) == "Arima")
    parvec <- object$model$phi
    parvec <- object$ar
  if(length(parvec) > 0)
    last.nonzero <- max(which(abs(parvec) > 1e-08))
    if (last.nonzero > 0)
      type="AR"), class='armaroots'))
# Compute MA roots
maroots <- function(object)
  if(class(object) != "Arima")
    stop("object must be of class Arima")
  parvec <- object$model$theta
  if(length(parvec) > 0)
    last.nonzero <- max(which(abs(parvec) > 1e-08))
    if (last.nonzero > 0)
      type="MA"), class='armaroots'))
plot.armaroots <- function(x, xlab="Real",ylab="Imaginary",
    main=paste("Inverse roots of",x$type,"characteristic polynomial"),
  oldpar <- par(pty='s')
       type="n",bty="n",xaxt="n",yaxt="n", main=main, ...)
  circx <- seq(-1,1,l=501)
  circy <- sqrt(1-circx^2)
  if(length(x$roots) > 0) {
    inside <- abs(x$roots) > 1
    if(sum(!inside) > 0)

The arroots function will return the autoregressive roots from the AR characteristic polynomial while the maroots function will return the moving average roots from the MA characteristic polynomial. Both functions take an Arima object as their only argument. If a seasonal ARIMA model is passed, the roots from both polynomials are computed in each case.

The plot.armaroots function will plot the inverse of the roots on the complex unit circle. A causal invertible model should have all the roots outside the unit circle. Equivalently, the inverse roots should like inside the unit circle.

Here are a couple of examples demonstrating their use.

A simple example with three AR roots:


A more complicated example with ten AR roots and four MA roots. (This is not actually the best model for these data.)

fit <- Arima(woolyrnq,order=c(2,0,0),seasonal=c(2,1,1))
plot(arroots(fit),main="Inverse AR roots")
plot(maroots(fit),main="Inverse MA roots")

Finally, here is an example where two inverse roots lie outside the unit circle (shown in red).


Note that the Arima function will never return a model with inverse roots outside the unit circle. The auto.arima function is even stricter and will not select a model with roots close to the unit circle either, as such models are unlikely to be good for forecasting.

I won’t add these functions to the forecast package as I don’t think enough people would use them, and the package is big enough as it is. So I’m making them available here instead for anyone who wants to use them.

Discover the unprecedented possibilities and challenges, created by today’s fast paced data climate and why your current integration solution is not enough, brought to you in partnership with Liaison


Published at DZone with permission of Rob J Hyndman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}