[R] discrepancy between periodogram implementations ? per and spec.pgram

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Dec 12 16:44:33 CET 2007


There are several definitions of a periodgram.  Note that

> log(2*pi)
[1] 1.837877

See the comments in ?spectrum about scalings.

I think the comments in ?per incorrectly ignore the scaling issues: per() 
does not take the base frequency into account and has an extra divisor of 
2*pi.  E.g.

> x <- rnorm(64)
> spec.pgram(x, taper=0, detrend=F)$spec/per(x)[-1]
  [1] 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185
  [9] 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185
[17] 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185
[25] 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185 6.283185


On Wed, 12 Dec 2007, Lieven Desmet wrote:

> hello,
>
> I have been using the per function in package longmemo to obtain a
> simple raw periodogram.
> I am considering to switch to the function spec.pgram since I want to be
> able to do tapering.
> To compare both I used spec.pgram with the options as suggested in the
> documentation of per {longmemo} to make them correspond.
>
> Now I have found on a variety of examples that there is a shift between
> the log of the periodogram with per and that with spec.pgram. This
> vertical shift amounts to  approx. 1.8  on the log scale  (the graph of
> spec.pgram being above the one from per).
>
> Is there some explanation for this ? Is the one from spec.pgram the
> better one as suggested in the documentation of per {longmemo}? Finally
> how are these related to an estimate of the spectral density obtained
> from spec.arima ?

What is spec.arima?  If you meant spec.ar, that is on the same scale as 
spec.pgram for series with base frequency 1 (and for all series for R >= 
2.7.0).


> Many thanks for help and clarification.
>
> Lieven Desmet

-- 
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