[R] ts.intersect() not working
Giorgio Garziano
giorgio.garziano at ericsson.com
Tue Nov 10 17:47:51 CET 2015
It appears to be a numerical precision issue introduced while computing the "end" value of a time series,
if not already specified at ts() input parameter level.
You may want to download the R source code:
https://cran.r-project.org/src/base/R-3/R-3.2.2.tar.gz
and look into R-3.2.2\src\library\stats\R\ts.R, specifically at code block lines 52..64,
where "end" is handled.
Then look at block code 140-142 ts.R, where a comparison is performed in order to determine if
the time series are overlapping.
In your second scenario (b2, b3) it happens that:
> tsps
[,1] [,2]
[1,] 2009.5833333333333 2009.6666666666667
[2,] 2009.6666666666665 2009.6666666666667
[3,] 12.0000000000000 12.0000000000000
> st <- max(tsps[1,])
> en <- min(tsps[2,])
> st
[1] 2009.6666666666667
> en
[1] 2009.6666666666665
And (st > en) triggers the "non-intersecting series" warning.
That issue has origin inside the ts() function in the "end" computation based on start, ndata and frequency.
What basically happens can be so replicated:
start = c(2009, 8)
end = c(2009,9)
frequency=12
ndata=2
start <- start[1L] + (start[2L] - 1)/frequency
start
[1] 2009.5833333333333
end <- end[1L] + (end[2L] - 1)/frequency
end
[1] 2009.6666666666667
end <- start + (ndata - 1)/frequency
end
[1] 2009.6666666666665
Note the difference between the two "end" values above.
As workaround, you can specify the "end" parameter in the ts() call.
> b2 <- ts(data = c(10, 20), start = c(2009, 8), end = c(2009,9), frequency = 12);
> b2
Aug Sep
2009 10 20
>
> b3 <- ts(data = matrix(data = 4:6, nrow = 1), start = c(2009, 9), end = c(2009,9), frequency = 12);
> b3
Series 1 Series 2 Series 3
Sep 2009 4 5 6
>
> bb <- ts.intersect(b2, b3);
> bb
b2 b3.Series 1 b3.Series 2 b3.Series 3
Sep 2009 20 4 5 6
Hope this helps
--
GG
[[alternative HTML version deleted]]
More information about the R-help
mailing list