[R] Arima bug?

rkevinburton at charter.net rkevinburton at charter.net
Fri Feb 20 00:26:22 CET 2009


I was looking at the 'R' code associated with arima. I see the following:

    upARIMA <- function(mod, phi, theta) {
        p <- length(phi)
        q <- length(theta)
        mod$phi <- phi
        mod$theta <- theta
        r <- max(p, q + 1)
        if (p > 0) 
            mod$T[1:p, 1] <- phi
        if (r > 1) 
            mod$Pn[1:r, 1:r] <- .Call(R_getQ0, phi, theta)
        else if (p > 0) 
            mod$Pn[1, 1] <- 1/(1 - phi^2)
        else mod$Pn[1, 1] <- 1
        mod$a[] <- 0
        mod
    }
 

In particular the statement:

       else if (p > 0) 
            mod$Pn[1, 1] <- 1/(1 - phi^2)

If p (the length of the phi vector) is greater than one then it looks like the code is trying to assign a vector to a single element which will generate an error in 'R'. Much like

x <- 1:3
x[1] <- 1:3

So I was wondering if there is something that I am missing that will "guarantee" that the length of the phi vector in this case is always 1. If this is not the case then it seems that this is a bug in the arima code.

Comments?

Kevin




More information about the R-help mailing list