[R] Help with 'spectrum'

David Stoffer dsstoffer at gmail.com
Sat Sep 13 04:27:00 CEST 2008


Kevin- this is a simple rescaling of the axes so that the "area under the
curve" remains constant (and is half of the variance since you only look at
the positive frequencies).   In this case, freq(x) = 1/dx, where dx is the
time between points.   It is basically a graphic device so that you get
pretty graphics and it's akin to drawing probability histograms so that area
corresponds to probability.  I think you'd get a good idea of what is going
on by doing this:

x <- ts(cos(2*pi*1:60*1/12))    # think of monthly high temps
y <- ts(x, freq=12)
par(mfrow=c(2,1))
plot(x)
plot(y)
# see the difference?  ... which do you prefer? now do this:

par(mfrow=c(2,1))
spec.pgram(x, taper=0, log="no")    # freq axis is 0 to .5 cycles per unit
time (which is 1)
spec.pgram(y, taper=0, log="no")    # freq axis is 0 to 6 cycles per unit
time (which is 12)
#   ... which do you prefer?

and you'll see by stretching the frequency axis you have to adjust the
spectrum axis accordingly so that you maintain "variance under the curve".





rkevinburton 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'.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 period).
> 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)?
> 
> Thank you in advance for helping me clear up some confusion.
> 
> Kevin
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 


-----
The power of accurate observation is commonly called cynicism 
by those who have not got it.  George Bernard Shaw
-- 
View this message in context: http://www.nabble.com/Help-with-%27spectrum%27-tp19396471p19466898.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list