On Wed, 2 Nov 2011, Pierre Chausse wrote:
I have a suggestion for kernapply for ts objects. When we choose the
option circular=F, the returned series don't have the correct dates. The
That's a matter of opinion. A kernel is applied in the same way as an
MA filter, to historical data.
removed dates are all at the beginning instead of half at the beginning
and half at the end. It is particularly useful when we need to smooth
the series (or remove a trend using a filter) before estimating a model
(like in macroeconomics) or simply to plot the original series with the
smoothed one. Of course, there is always the option of doing it by hand
of the use circular=T and trim the series but I thought it would be
nicer that way.
Here is my suggestion (maybe not the nicest way to do it but it works)
kernapply.ts <- function (x, k, circular = FALSE, ...)
{
if (!is.matrix(x))
{
y <- kernapply.vector(as.vector(x), k, circular=circular)
ts (y, end=end(x), frequency=frequency(x))
}
else
y <- apply(x, MARGIN=2L, FUN=kernapply, k, circular=circular)
if(circular)
ts (y, end=end(x), frequency=frequency(x))
else
{
y <- as.ts(y)
t1 <- tsp(x)[1]+(length(k[[1]])-1)/tsp(x)[3]
t2 <- tsp(x)[2]-(length(k[[1]])-1)/tsp(x)[3]
tsp(y) <- c(t1,t2,tsp(x)[3])
return(y)
}
}
--
*Pierre Chauss?*
Assistant Professor
Department of Economics
University of Waterloo
[[alternative HTML version deleted]]
--
Brian D. Ripley, [email protected]
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
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel