[R-SIG-Finance] timeseries - xst vs. dataframe?

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Thu Feb 14 13:03:40 CET 2008


Just a few comments in addition to Gabor's:

> > It looks like help('$') and help('is.atomic') raise some interesting
> > ts and zoo implementation questions. I understand that zoo is modeled
> > on ts; I didn't really appreciate until now that ts was atomic. Is an
> > atomic ts and zoo "correct"? Would a recursive zoo break things? Items
> > of note:
> >
> > * Is zoo conceptually atomic if it contains a non-integer index vector
> > and an integer data vector?
>
> zoo does not know what the mode or class of its index vector is.  It only deals
> with the index vector through the methods of index vector's class that
> are required to be there as defined in ?zoo .   The only exceptions
> are a few routines which deal with outside world:

Just to clarify: zoo is the core data plus an index attribute. zoo does
not know anything about the index. But the core data is always atomic
(vector or matrix -- and very limited support for factor).

> > *zoo and ts behave more recursively than atomically under certain conditions:
> > One example is dynlm.

Because it explicitely adds some glue to deal with these situation
(leveraging the tools from "zoo"). It is necessary to write something like
"dynlm" or "dyn" because otherwise the data handling wouldn't work
(sufficiently well) in lm() (and friends).

> > It accepts a number of recursive objects for
> > "data=", including environments and dataframes. Here zoo and ts as
> > atomic seem to be temporarily granted recursive, environment-like
> > status so that the model can be specified using the traditional
> > environment-element syntax:
> >
> > # one of these is not like the others
> > test.matrix = cbind(a=1:5, b=2*1:5)
> > test.ts = ts(cbind(a=1:5, b=2*1:5))
> > test.zoo = zoo(data.frame(a=1:5, b=2*1:5), order.by=letters[1:5])
> > test.df = data.frame(a=1:5, b=2*1:5, group=c('A', 'A', 'A', 'B', 'B'),
> >  order.by=letters[1:5])
> >
> > dynlm(a ~ b, data=test.matrix)
> > dynlm(a ~ b, data=test.ts)
> > dynlm(a ~ b, data=test.zoo)
> > dynlm(a ~ b, data=test.df)
> > # the first one doesn't work, but all the others are identical. same for lm()

Note that the documentation wants you to specify "data" as a
ts or zoo or data.frame (not a matrix).

Best,
Z



More information about the R-SIG-Finance mailing list