[R] Time Series information in formulae
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Apr 12 09:25:02 CEST 2006
The problem here is that you called model.frame() with (I presume, the
'factory-fresh' default) na.action=na.omit, and model.frame is documented
to remove tsp attributes in that case.
Use model.frame(..., na.action = NULL), e.g.
model.frame(~UKgas, na.action=NULL)[[1]]
is a time series but
model.frame(~UKgas, na.action=na.omit)[[1]]
is not. See ?model.frame.
On Tue, 11 Apr 2006, Claus Dethlefsen wrote:
> Dear List
>
> The UKgas data is stored as an object of class 'ts'. I am trying to use "UKgas"
> in a formula as argument to a function. However, I do not know how to access
> the 'time series' information in the response (such as start() end() etc.).
>
> Here is a boiled down example.
>
> ssm <- function(formula, data = list(),subset=NULL) {
> cl <- match.call()
> if (missing(data))
> data <- environment(formula)
> mf <- match.call(expand.dots = FALSE)
> mf$drop.unused.levels <- TRUE
> mf[[1]] <- as.name("model.frame")
> mf <- eval(mf, .GlobalEnv)
> mt <- attr(mf, "terms")
> y <- model.response(mf, "numeric")
> print(class(y))
> }
>
> R> class(UKgas)
> [1] "ts"
> R> ssm(UKgas~1)
> [1] "numeric"
> R> ssm(log10(UKgas)~1)
> [1] "numeric"
>
> I want the latter two to be "ts". I have tried putting "any" in place
> of "numeric" in the call to model.response, but it does not change anything for
> me.
>
> How do I retrieve the response from a formula without loosing its "ts" status?
>
> Best,
> Claus
> ----------------------------------------------------
> Claus Dethlefsen, MSc, PhD
> Biostatistician at Center for Cardiovascular Research
> Aalborg Hospital, Aarhus University Hospital, Denmark
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list