time series in R

Martyn Plummer plummer@iarc.fr
Tue, 20 Jul 1999 15:38:34 +0200 (CEST)


On 20-Jul-99 Prof Brian Ripley wrote:
> 
>> I also suggested an "na.omit" method for time series - which would be
>> used by many of the time series functions. Martin has made na.omit()
>> and na.fail() generic so this is possible now.
> 
> Good. What do you want na.omit.ts to do? 

It would either
1) remove missing values only from the beginning or end of a time
   series, or
2) return the longest contiguous subseries with no missing values,
   e.g. presidents[32:110], or the first such subseries if there
   were multiple matches.
A lot of S-plus time series functions use option 1). Option 2) seems
more useful to me. There is no "na.omit.ts" in Splus 3.3 but  it
seems like a good way to implement this functionality.

>> I updated acf() in bats_0.1-3.tar.gz (now on CRAN) to use FFT instead,
>> after seeing its rather embarrassing performance.
> 
> I have that. However, I am having a number of problems with it,
> for example that pacf does not work, and acf does not work correctly
> for multiple series.
> 
>> library(bats)
>> data(presidents)
>> acf(presidents, type="partial")
> Error: Object "xb" not found
> 
> OK, fix that:
>> acf(presidents, type="partial")
> Error: NA/NaN/Inf in foreign function call (arg 1)
> 
> [The NA handling needs to be sorted out.]

See above.

> A little later:
> 
>             var0 <- diag(acf[1, , ], nrow = nser)
> 
> is wrong: it gives a matrix and multivariate acfs fail. I used

This works for me!

> 
>             var0 <- if(nser > 1) diag(acf[1, , ]) else acf[1,1,1]
> 
> I think I will special-case the univariate code here.
> 
> 
>> > spectrum, spec.pgram from bats  (after looking at tseries hard)
>> 
>> Adrian's spectrum() function allows a wider range of kernel smoothers
>> and it would be nice to keep this.  Since spectrum() is just a wrapper
>> function anyway, it should be possible to do this, while keeping the
>> S-PLUS compatible interface.
> 
> Yes, I intend to look at that. For now, though, your code is not
> giving the same results as S-PLUS, and I need to fix up at least the
> confidence interval calculations.  (I think I know exactly how it
> is done in S-PLUS: it uses Bloomfield's code.)  

The main reason my confidence intervals are different is that I don't
have the correct expression for the degrees of freedom in the presence
of tapering (or padding, but that is trivial). Apart from that,
I deliberately chose different limits because I allow the user to
specify the coverage of the confidence interval in plot.spec, and if
one is allowed to do that, one needs to make sure that the confidence
interval contains the estimate, which would not always be the case with
the Splus behaviour.

> I believe that padding
> needs to be optional.

There seems to be two sorts of padding going on in Splus. One under
the control of the user, via the "pad" argument and the other
which is automatic, to aid the Fast Fourier Transform. I have
tried to reproduce this, but can't exactly match the Splus behaviour.

Martyn
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._