[R] spectrum
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Jan 22 19:20:24 CET 2004
On Thu, 22 Jan 2004, Andreas Pauling wrote:
> I have two questions about estimating the spectral power of a
> time series:
>
> 1) I came across a funny thing with the following code:
>
> data(co2)
> par(mfrow=c(2,1))
> co2.sp1<-spectrum(co2,detrend=T,demean=T,span=3)
> co2.sp2<-spectrum(co2[1:468],detrend=T,demean=T,span=3)
>
> The first plot displays the frequencies ranging from 0 to 6
> whearas the second plot displays the same curve but with
> frequencies between 0 and .5 although it is based on the same
> data (length(co2)=468). Why does the selection (co2[1:468])
> determine the vector of frequencies and plot it obviously
> incorrectly?
It is correct! co2[1:468] is not a time series: you should be using
window() to subset time series. So you supplied a vector which does not
have a frequency (or a start or an end) and default values are used.
Did you consider actually looking at co2[1:468]?
> Generally, is it possible to choose the vector of frequencies at
> which the spectral density is estimated and plotted?
Wait a minute: spectrum() does not estimate a spectral density but calls
helper functions to do so. Please consult their help pages. The answer
is a qualified `yes'.
> 2) How can the significance of the peaks be tested?
Not an R question, and not well enough defined for a short answer. See
any good book on time series.
--
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