[R] first derivative of a time series
Spencer Graves
spencer.graves at pdf.com
Tue Jan 17 04:57:18 CET 2006
First, I have to say that R is great. I'd never heard of "cyclone"
before I read your post, but in only a couple of minutes, I was able to
install it, try it out, and form a (perhaps erroneous) opinion thereof.
The function "coefFit" fits a polynomial of degree N-1 to a
timeseries of degree N-1. For most applications, this is a bad idea,
because the higher order coefficents are largely noise -- and the
greater the noise, the fewer sensible coefficients one can get. In
other words, the more noise, the more nonsense on will likely get from
such a procedure. As evidence, I present the following:
set.seed(1)
ts.values <- rnorm(11)
## first calculate coefficients to pass to coefDeriv
(ts.coef <- coefFit(ts.values))
> (ts.coef <- coefFit(ts.values))
$coefs
[1] -0.8204684 2.1309962 39.9775982 -53.9342218 -254.8143434
[6] 281.8953570 611.4776909 -476.4068559 -634.0601417 247.3838420
[11] 238.6823281 NA
<snip>
The absolute values of ts.coef$coefs increase monotonically up to the
7th coefficient, beyond which the smallest coefficient in absolute value
is over 200 -- estimated from 11 pseudo-random numbers drawn per N(0,1).
I think it is conservative to describe this as merely silly.
From what I know, "the first derivative of an original time series"
is not anything that has a standard definition. If you would like more
help from this listserve, please tell us a bit more about the problem
you are trying to solve, for which you think "the first derivative of an
original time series" might be useful.
spencer graves
p.s. The fact that you included an almost reprodicible example was
critical in permitting me to reply. Without that, the most constructive
comment I might have been able to make might have been, "PLEASE do read
the posting guide! 'www.R-project.org/posting-guide.html'." With your
future posts, it might help increase the utility and frequency of
replies if you include a self-contained snippet of R code. I almost
gave up on my attempt to reply to your question, because I when I tried,
'read.table("timeseries.1d")', I got, 'Error in file(file, "r") : unable
to open connection'. You might get better help if you make it easier
for people to help you.
gj wrote:
> Hi,
>
> I need to derive a time series that represents the first derivative of an
> original time series. The function coefDeriv in the cyclones package seemed to
> be the ticket, but I'm not sure if I am interpreting the output of the function
> correctly...or even using the function correctly.
>
> This is a snipbit of what I've been trying:
> --------
> library(cyclones)
>
> ## read in my 1-column of values, each line is a different time step
> ts.table <- read.table("timeseries.1d")
> ts.values <- ts.table[,1]
>
> ## first calculate coefficients to pass to coefDeriv
> ts.coef <- coefFit(ts.values)
>
> d.ts <- coefDeriv(ts.coef)
> -------
>
> However, when I try to look at d.ts$y.deriv, assumning that this will plot the
> derivative I want, all the numbers are huge (on the order of e+02 to e+08) when
> my original time series ranged from 0 to 970. Am I going about this the wrong
> way? Or are there other tools that would lead me to estimating the derivative
> of a time series?
>
> Thanks in advance for any help!
> g
>
> ______________________________________________
> 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
More information about the R-help
mailing list