Skip to content

Bug in print.Arima and patch

4 messages · Gavin Simpson, Brian Ripley

#
Dear List,

A posting to R-Help exposed this problem with the print method for
objects of class Arima:
Call:
arima(x = x, order = c(1, 0, 1), fixed = coefs)

Coefficients:
Error in se && nrow(x$var.coef) : invalid 'y' type in 'x && y'
Call:
arima(x = x, order = c(1, 0, 1), fixed = coefs)

Coefficients:
      ar1        ma1  intercept  
   0.9323    -0.2940    -0.0353  

sigma^2 estimated as 0.8339:  log likelihood = -133.55,  aic = 269.11

The print methods raises an error in this case, where all coefficients
are fixed, because x$var.coef is of length(0), which in turn results in
NULL being used in the && comparison, resulting in the error.

A potential fix is to just include a check for length(x$var.coef) > 0 in
the if statement. This fix, when applied to:

R version 2.10.0 Under development (unstable) (2009-06-05 r48712)

fixes this particular problem and passes make check-devel. A patch
against r48712 is attached, and included here in-line:

[gavin at desktop build]$ svn diff ../src/library/stats/R/arima.R
Index: ../src/library/stats/R/arima.R
===================================================================
--- ../src/library/stats/R/arima.R	(revision 48712)
+++ ../src/library/stats/R/arima.R	(working copy)
@@ -355,7 +355,7 @@
     if (length(x$coef)) {
         cat("Coefficients:\n")
         coef <- round(x$coef, digits = digits)
-        if (se && nrow(x$var.coef)) {
+        if (se && length(x$var.coef) > 0 && nrow(x$var.coef)) {
             ses <- rep(0, length(coef))
             ses[x$mask] <- round(sqrt(diag(x$var.coef)), digits = digits)
             coef <- matrix(coef, 1L, dimnames = list(NULL, names(coef)))

HTH

G
#
Why not use NROW?
On Fri, 5 Jun 2009, Gavin Simpson wrote:

            

  
    
#
On Fri, 2009-06-05 at 15:42 +0100, Prof Brian Ripley wrote:
No reason - had forgotten this existed.

So here is another patch:

[gavin at desktop ~]$ svn diff ~/R/devel/src/
Index: /home/gavin/R/devel/src/library/stats/R/arima.R
===================================================================
--- /home/gavin/R/devel/src/library/stats/R/arima.R	(revision 48712)
+++ /home/gavin/R/devel/src/library/stats/R/arima.R	(working copy)
@@ -355,7 +355,7 @@
     if (length(x$coef)) {
         cat("Coefficients:\n")
         coef <- round(x$coef, digits = digits)
-        if (se && nrow(x$var.coef)) {
+        if (se && NROW(x$var.coef)) {
             ses <- rep(0, length(coef))
             ses[x$mask] <- round(sqrt(diag(x$var.coef)), digits =
digits)
             coef <- matrix(coef, 1L, dimnames = list(NULL,
names(coef)))

And the same is attached, that implements your suggested change rather
than the one I sent earlier.

Cheers,

G
#
On Fri, 5 Jun 2009, Gavin Simpson wrote:

            
I was testing NROW after having seen the R-help message, so will go 
ahead with that solution.  But as I was doing so, something urgent 
came up locally ....

Thank you for looking into the issue.