Skip to content

ts.intersect bug?

5 messages · Antonio, Fabio Di Narzo, Gabor Grothendieck, Barry Rowlingson +1 more

#
---------- Forwarded message ----------
From: Antonio, Fabio Di Narzo <antonio.fabio at gmail.com>
Date: 21-set-2005 15.34
Subject: Re: [R] ts.intersect bug?
To: Martin Maechler <maechler at stat.math.ethz.ch>


2005/9/21, Martin Maechler <maechler at stat.math.ethz.ch>:
Ooops, bad example.
Try this instead:
a <- ts(runif(6500), start=0, freq=10)
b <- lag(a, 1)
c <- ts.intersect(a, b)

Gives an error from .cbind.ts
#
On 9/21/05, Antonio, Fabio Di Narzo <antonio.fabio at gmail.com> wrote:
A workaround would be to convert both a and b to zoo class,
intersect them using zoo's merge and convert back to ts:

library(zoo)
z <- as.ts(merge(as.zoo(a), as.zoo(b), all = FALSE))

Regarding your other question,

Sys.putenv(LANGUAGE="en")

will result in error messages in English.
#
2005/9/21, Gabor Grothendieck <ggrothendieck at gmail.com>:
Many tnx, and again sorry for the starting bad example.
Will the ts.intersect bug addressed in next R release?

Antonio, Fabio Di Narzo.

P.S. A little OT: shouldn't the "Sys.putenv(LANGUAGE="en")" tip be put
in the posting guide?
#
Antonio, Fabio Di Narzo wrote:

            
or even:

  > a=ts(numeric(2600),freq=10,start=0);b=lag(a,1);c=ts.intersect(a,b)
Error in "[<-"(`*tmp*`, , (1 + cs[i]):cs[i + 1], value = c(0, 0, 0, 0,  :
         number of items to replace is not a multiple of replacement length

  seems to be sensitive to the lengths of the time series:

  > a=ts(numeric(2601),freq=10,start=0);b=lag(a,1);c=ts.intersect(a,b)
  > (works fine)


  Digging into the code, the window() function is returning a different 
length time series for each one in these failing cases. I reckon its a 
floating-point precision situation, where the last time series point 
should be included but the arithmetic precision of a 2600-long series at 
separation of 1/10 is leaving it out.

  > st;en
  [1] 0
  [1] 259.8

  > a=ts(numeric(2600),freq=10,start=0);b=lag(a,1)
  > length(window(a,st,en))
  [1] 2599
  > length(window(b,st,en))
  [1] 2598

  - ts.intersect is trying to put these two time series together, and so 
fails. But:

  > a=ts(numeric(2601),freq=10,start=0);b=lag(a,1)
  > length(window(a,st,en))
  [1] 2599
  > length(window(b,st,en))
  [1] 2599

  - works.

  Note that en is not precisely 259.8:

  > en == 259.8
  [1] FALSE
  > en-259.8
  [1] -5.684342e-14

  I've computed 'en' as the .cbind.ts function does, and its not exactly 
259.8. If it were, then it would work... Perhaps .cbind.ts should round 
to the nearest true time point or something...

  Note that it fails in plenty of smaller cases too:

  > a=ts(numeric(13),freq=10,start=0);b=lag(a,1);c=ts.intersect(a,b)
Error in "[<-"(`*tmp*`, , (1 + cs[i]):cs[i + 1], value = c(0, 0, 0, 0,  :
         number of items to replace is not a multiple of replacement length

  Seems to not like 13s and 10s and integer products thereof (2600, 
6500). Are you superstitious?

Baz

PS without counting, how many letters are there in 'superstitious'?
#
The problem was that a tolerance in window.default was abs(start)*ts.eps, 
which is no tolerance at all if start = 0.

So the special feature here was that the intersection of the series 
started at zero. I had already tested and committed a fix.

window.default does use a tolerance for en, just as Baz suggests it 
should.  The code is there to be read ....  (That tolerance was inadequate 
if end = 0, but has been changed.)
On Wed, 21 Sep 2005, Barry Rowlingson wrote: