From gavin.simpson at ucl.ac.uk  Fri Jun  5 17:01:04 2009
From: gavin.simpson at ucl.ac.uk (Gavin Simpson)
Date: Fri, 05 Jun 2009 16:01:04 +0100
Subject: [Rd] Bug in print.Arima and patch
In-Reply-To: <alpine.LFD.2.00.0906051541210.13402@gannet.stats.ox.ac.uk>
References: <1244211187.2592.81.camel@desktop.localhost>
	<alpine.LFD.2.00.0906051541210.13402@gannet.stats.ox.ac.uk>
Message-ID: <1244214064.2592.88.camel@desktop.localhost>

On Fri, 2009-06-05 at 15:42 +0100, Prof Brian Ripley wrote:
> Why not use NROW?

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:
> 
> > Dear List,
> >
> > A posting to R-Help exposed this problem with the print method for
> > objects of class Arima:
> >
> >> set.seed(1)
> >> x <- arima.sim(n = 100, list(ar = 0.8897, ma = -0.2279))
> >> mod <- arima(x, order = c(1,0,1))
> >> coefs <- coef(mod)
> >> mod2 <- arima(x, order = c(1,0,1), fixed = coefs)
> >> mod2
> >
> > 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'
> >> print(mod2, se = FALSE)
> >
> > 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
> > -- 
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> > Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
> > ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
> > Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
> > Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
> > UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >
> >
> 
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

-------------- next part --------------
A non-text attachment was scrubbed...
Name: print.Arima.patch
Type: text/x-patch
Size: 667 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20090605/dff5180f/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20090605/dff5180f/attachment-0001.bin>


[Rd] Bug in print.Arima and patch
Gavin Simpson