[R] Time Series Decomposition On Zoo Objects: Errors

Rich Shepard rshepard at appl-ecosys.com
Thu Apr 3 22:55:17 CEST 2014


   I have irregular time series as zoo objects; one example:

structure(c(6, 5, 14, 9, 8, 9, 8, 5, 5, 5, 3, 3, 4, 3, 9, 6.94, 
7.44, 3.09, 0.84, 5.35, 4.76, 4.21, 1.58, 2.6, 3.41, 9.59, 7.1, 
5, 5, 5, 3, 1.5, 2.4, 3.9, 5.8, 2.3, 3.6, 4.1, 15.4, 7.8, 4.2, 
5.8, 3, 4.5, 8.1, 9.6, 9.3, 7.9, 3.8, 3.2, 3.6, 8.4, 10.5, 8.7, 
7.9, 3.1, 2.7, 3.7, 3.7, 2.9, 3.6, 2.3, 2, 1), index = structure(c(8147, 
8177, 8345, 8428, 8449, 8462, 8474, 8498, 8520, 8531, 8547, 8561, 
8576, 8590, 8612, 8852, 8862, 8881, 8912, 8939, 9231, 9249, 9280, 
9304, 9337, 9468, 9511, 9623, 9652, 9679, 9981, 9995, 10028, 
10071, 10371, 10374, 10434, 10484, 10520, 10554, 10721, 10736, 
10764, 10794, 10904, 10926, 11020, 11026, 11068, 11086, 11136, 
11288, 11298, 11369, 11388, 11442, 11453, 11498, 11811, 11859, 
12175, 12218, 12597, 12600), class = "Date"), class = "zoo")

   They appear to have seasonal variation and a trend. When I try to decompose
them using stl() I get an error about missing values:

s95so4.stl <- stl(s95so4.z)
Error in na.fail.default(as.ts(x)) : missing values in object

   The s.window option might be applicable, but it seems to me that
specifying 'periodic' for an irregular time series is inappropriate (in any
case, it still produces the same error message), and I don't know what would
be an appropriate span (in lags) for the loess window.

   I would like to learn how to decompose such irregular (zoo) time series
into seasonal variation, trend, and residual errors so I can apply
regressions (using lm()) to pairs that ought to be related.

   Would StructTS() be the appropriate function for these data?

Rich




More information about the R-help mailing list