Skip to content

Semi-Regular Time Series with Missing Values

14 messages · Adam Oliner, Gabor Grothendieck

#
On Tue, Jan 18, 2011 at 6:33 PM, Adam Oliner <oliner at gmail.com> wrote:
Note that there is an as.ts.zoo method.
#
On Wed, Jan 19, 2011 at 1:10 PM, Adam Oliner <oliner at gmail.com> wrote:
Normally S3 methods such as as.ts.zoo are not exported unless there is
particular reason to access them directly.  Rather one accesses them
via their generic which dispatches the appropriate method based on the
class of its first argument.

That is if z is a zoo object then as.ts(z) dispatches as.ts.zoo.

If you really want to see it you can do this zoo:::as.ts.zoo
#
On Wed, Jan 19, 2011 at 3:07 PM, Adam Oliner <oliner at gmail.com> wrote:
Its not clear what you are expecting but here is an example:
1(1) 1(2) 1(3) 1(4) 2(1) 2(2) 2(3) 2(4) 3(1) 3(2) 3(3) 3(4)
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
[1] 4
Qtr1 Qtr2 Qtr3 Qtr4
1 1001 1002 1003 1004
2 1005 1006 1007 1008
3 1009 1010 1011 1012
[1] 4
#
On Wed, Jan 19, 2011 at 4:17 PM, Adam Oliner <oliner at gmail.com> wrote:
zoo and zooreg classes handle series which may not be regularly spaced
whereas ts only handles regularly spaced series so the series
necessarily must be filled with NAs if you convert it from an
irregularly spaced one to a regularly spaced one.
#
On Wed, Jan 19, 2011 at 4:27 PM, Adam Oliner <oliner at gmail.com> wrote:
Please provide a minimal self-contained reproducible example (as per
last line on every r-help message) and explain what you were expecting
that is different than what you got and we may be able to say more.
#
On Wed, Jan 19, 2011 at 5:21 PM, Adam Oliner <oliner at gmail.com> wrote:
I think what you want is:

library(zoo)

library(zoo)
data <- c(50, 32, 22, 13, 14, 6, 12, 3, 6, 21, NA, NA, 15, 13, 17, 9,
11, 34, 63)
z <- zooreg(data, frequency = 2)
stl(z)

or equivalently

tt <- ts(data, frequency = 2)
stl(tt)

however stl does not support series with NAs so that can't work with
your data and specifying na.action won't help since that is equivalent
to stl(na.action(as.ts(z))).  Also note that na.action's value is a
function and na.action = F is illegal unless you have a function
called F in your workspace.

These work in so far as they give an answer but whether they are
acceptable is up to you:

stl(z[1:01], "per")
stl(z[13:19], "per")
stl(na.approx(z), "per")