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
Help with 'spectrum'
5 messages · rkevinburton at charter.net, Brian Ripley, PIKAL Petr +2 more
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 period).
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 periodicity yet).
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. Kevin
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
2 days later
Hi r-help-bounces at r-project.org napsal dne 09.09.2008 18:44:34:
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)?
Well, although I am not an expert in this matter I try to explain my humble understanding of spectrum results. sss<-spectrum(sunspots) sss$freq[which.max(sss$spec)] [1] 0.09166667 1/sss$freq[which.max(sss$spec)] [1] 10.90909 you can see that maximum of spec value is for this time series at freq 0.09 and 1/0.09 is almost eleven. Knowing that sunspots have periodicity 11 years I assume that for each series I can get an information about its periodicity by 1/freq. E.g. if your series is days 1/freq means period in days. Regards Petr
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.
1/(x-axis value) = frequency in time (the x-axis is in cycles per time) 2008/9/12 Petr PIKAL <petr.pikal at precheza.cz>:
Hi r-help-bounces at r-project.org napsal dne 09.09.2008 18:44:34:
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)?
Well, although I am not an expert in this matter I try to explain my humble understanding of spectrum results. sss<-spectrum(sunspots) sss$freq[which.max(sss$spec)] [1] 0.09166667 1/sss$freq[which.max(sss$spec)] [1] 10.90909 you can see that maximum of spec value is for this time series at freq 0.09 and 1/0.09 is almost eleven. Knowing that sunspots have periodicity 11 years I assume that for each series I can get an information about its periodicity by 1/freq. E.g. if your series is days 1/freq means period in days. Regards Petr
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. ______________________________________________ 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.
Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
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.