[Rd] bug in aggregate.ts

Felix Andrews felix at nfrac.org
Tue Apr 20 02:51:10 CEST 2010


Sorry, I didn't notice Patrick Aboyoun's email reporting the same
issue just some minutes ago.


On 20 April 2010 10:41, Felix Andrews <felix at nfrac.org> wrote:
> Hi,
>
> I am getting unexpected behaviour from aggregate.ts(). The 'ndeltat'
> argument is effectively being reduced by 1 in some cases, even when it
> is an integer, with the result that the blocks to be aggregated are
> not of the expected size, and also that the end() of the aggregated
> series is much later than the end() of the original series.
>
> rawts <- ts(rep(1:10, each = 5), start = 1)
>
> ## ndeltat = 5, but splits into blocks of 4 rather than 5:
>
> agts <- aggregate(rawts, ndeltat = 5,
>             FUN = function(x) {str(x);mean(x)})
>  int [1:4] 1 1 1 1
>  int [1:4] 1 2 2 2
>  int [1:4] 2 2 3 3
>  int [1:4] 3 3 3 4
>  int [1:4] 4 4 4 4
>  int [1:4] 5 5 5 5
>  int [1:4] 5 6 6 6
>  int [1:4] 6 6 7 7
>  int [1:4] 7 7 7 8
>  int [1:4] 8 8 8 8
>  int [1:4] 9 9 9 9
>  int [1:4] 9 10 10 10
>
> ## Adding a small amount onto ndeltat bumps it up to blocks of 5:
>
> agts2 <- aggregate(rawts, ndeltat = 5 + getOption("ts.eps") / 2,
>             FUN = function(x) {str(x);mean(x)})
>  int [1:5] 1 1 1 1 1
>  int [1:5] 2 2 2 2 2
>  int [1:5] 3 3 3 3 3
>  int [1:5] 4 4 4 4 4
>  int [1:5] 5 5 5 5 5
>  int [1:5] 6 6 6 6 6
>  int [1:5] 7 7 7 7 7
>  int [1:5] 8 8 8 8 8
>  int [1:5] 9 9 9 9 9
>  int [1:5] 10 10 10 10 10
>
> ## Compare start / end / deltat / length for the two series.
>
> sapply(list(`ndeltat=5` = agts, `ndeltat=5+` = agts2),
>  function(x) c(start = start(x)[1], end = end(x)[1],
>                   deltat = deltat(x), length = length(x)))
>
> #        ndeltat=5 ndeltat=5+
> # start          1   1.000000
> # end           56  46.000045         ## `rawts` ends at 50
> # deltat         5   5.000005
> # length        12  10.000000
>
>
> sessionInfo()
> R version 2.11.0 RC (2010-04-18 r51771)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_Australia.1252  LC_CTYPE=English_Australia.1252
> [3] LC_MONETARY=English_Australia.1252 LC_NUMERIC=C
> [5] LC_TIME=English_Australia.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
>
>
> --
> Felix Andrews / 安福立
> Postdoctoral Fellow
> Integrated Catchment Assessment and Management (iCAM) Centre
> Fenner School of Environment and Society [Bldg 48a]
> The Australian National University
> Canberra ACT 0200 Australia
> M: +61 410 400 963
> T: + 61 2 6125 4670
> E: felix.andrews at anu.edu.au
> CRICOS Provider No. 00120C
> --
> http://www.neurofractal.org/felix/
>



-- 
Felix Andrews / 安福立
Postdoctoral Fellow
Integrated Catchment Assessment and Management (iCAM) Centre
Fenner School of Environment and Society [Bldg 48a]
The Australian National University
Canberra ACT 0200 Australia
M: +61 410 400 963
T: + 61 2 6125 4670
E: felix.andrews at anu.edu.au
CRICOS Provider No. 00120C
-- 
http://www.neurofractal.org/felix/



More information about the R-devel mailing list