[R] R question about spectrum metric

Niels Waller niels.waller at vanderbilt.edu
Sun Jul 18 01:03:53 CEST 2004


 
Dear R community,

I would like to conduct a simulation study that involves the 
generation and recovery of times series spectra.  Spectrum analysis 
is a new area for me so I am very much in the crawling stage at this point.

I am having difficulty understanding the output of the spec.pgram (or
spectrum) 
function. Specifically, I do not understand the metric of the results.  In
my 
simulation the recovered coefficients correlate  .99 with the generating 
coefficients, so everything appears in order -- accept for my 
confusion regarding the metric of the recovered coefficients.

I have written a function (makeWave) to generate the series. I then call
this
function with the required arguments. Next I analyze the resulting series
with 
spec.pgram and compare the results with the generating coefficients 
(at the appropriate frequencies).  In a small simulation study the
generating 
and recovered coefficients correlated .99 -- however the metric of the two 
sets of coefficients differ by several orders of magnitude.

I would be very happy to send the actual code of this simulation 
(less than 2 pages of code) to anyone who could help me understand how 
to scale my recovered coefficients to the metric of the generating
parameters. 
Specifically, I am looking for a general solution to the scaling problem (if
one exists).

Thank you in advance for any and all help.

Niels Waller
Vanderbilt University
R 1.9.1
Windows XP

##------------------------------------------------------------------##
##FUNCTION:   makeWave
##Purpose:    to generate periodic time series (no white noise)
##Arguments
## c0        :: coefficient for frequency 0
## c.n       :: vector of (complex) coefficients for frequencies 1...+n
## cminus.n  :: vector of (complex) coefficients for frequencies 1...-n
## N         :: number of time points in generated wave
## f         :: fundamental frequency of wave


makeWave<-function(c0, c.n, cminus.n, N, f){
k<-1:N  #k = time point
x<-rep(0,N)
w <- 2*pi*f
   for(t.i in 1:N){   ## over time t.i
      x[t.i] <- c0 
      temp<-0 
          for(j in 1:length(c.n)){   ## over frequency j
          temp<-temp +  c.n[j] * exp(1i*w*j*t.i) + 
                        cminus.n[j] * exp(1i*w*j*t.i) 
          }   
    x[t.i]<-x[t.i]+temp   
   }
 x  ##  composite wave
}




More information about the R-help mailing list