[Rd] ar on a constant series

Patrick Burns pburns at pburns.seanet.com
Thu Feb 21 11:02:40 CET 2008


Apparently it is quite rare to be as stupid as me and
want to predict a constant time series with 'ar'.

 > ar(rep(4, 60))
Error in if (order > 0) coefs[order, 1:order] else numeric(0) :
  missing value where TRUE/FALSE needed
In addition: Warning message:
In if (order > 0) coefs[order, 1:order] else numeric(0) :
  the condition has length > 1 and only the first element will be used


A fix for the multivariate case looks quite daunting, but
the univariate case can be improved (in my opinion at least)
with not much effort.

The definition of 'order' in 'ar.yw.default' can be changed from:

         order <- if (aic)
             (0:order.max)[xaic == 0]
         else order.max

to:

      if(any(var.pred <= 0)) {
        order <- which(var.pred <= 0)[1] - 1
      } else {
            order <- if (aic)
                (0:order.max)[xaic == 0]
            else order.max
      }

I presume something similar can be done in 'ar.burg',
but I haven't looked.  'ar.ols' and 'ar.mle' look problematic
for fixes.


Patrick Burns
patrick at burns-stat.com
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")



More information about the R-devel mailing list