[R] Help with 'spectrum'
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Sep 9 23:14:47 CEST 2008
This is why some help pages have references: please use them (Venables &
Ripley explain the exact formulae used in R).
On Tue, 9 Sep 2008, rkevinburton at charter.net wrote:
> For the command 'spectrum' I read:
> The spectrum here is defined with scaling 1/frequency(x), following
> S-PLUS. This makes the spectral density a density over the range
> (-frequency(x)/2, +frequency(x)/2], whereas a more common scaling is 2π
> and range (-0.5, 0.5] (e.g., Bloomfield) or 1 and range (-π, π].
> Forgive my ignorance but I am having a hard time interpreting this. Does
> this mean that in the spectrum output every element of the $spec array
> is scaled by 1/frequency(x)? I am having a hard time determing what is
> meant by 'frequency'.
So please do look up the help for frequency().
> Say I define a time series for a year with samples
> for every day. I input a 'frequency' of 365 (which in my mind is the
The point is that your time unit is 1 year, and your measurements are
every 1/365 year. That is unrelated to the 'period' (no one mentioned
> On the output of 'spectrum' would this mean that every element
> of the $spec array is scaled by 1/365? There is a corresponding
> frequency array on the output from 'spectrum'. If the frequency is 365
> and an element in the frequency array output from 'spectrum' is .1 am I
> to assume that the period is 36.5 and a corresponding sin wave would be
> sin(2 * pi * 36.5/365)?
Hmm, you need a 't' in there (and a phase). The issue is the units for t.
A frequency in the 'freq' element of the output of 0.1 corresponds to 10
cycles per unit of time, and in your example the unit of time is 365
observations. So the sine (sic) wave is sin(2*pi*0.1*t + phi), where the
increments in 't' are 1/365: that gives 10 complete cycles in observations
at, say, c(1990, 1) ... c(1990, 365), the days of 1990 (not a leap year).
> Thank you in advance for helping me clear up some confusion.
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