Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

In Statistica one can do a "two series"/bivariate/cross spectrum Fourier analysis to examine the coherency, gain, and phase spectrum across a pair of signals. It is probably a failing on my part, but my attempts to use those search terms to come up with similar values from R have come up blank. What functions/packages should I review in more detail? Can you provide some simple examples?

share|improve this question
1  
I've used various EEG analysis packages to accomplish the same thing, but never in R -- see if the "bivariate" snippet here is what you are looking for stat.ethz.ch/R-manual/R-patched/library/stats/html/… – jonsca Apr 3 '12 at 5:36
Close, but it doesn't seem like it calculates gain. – Russell S. Pierce Apr 3 '12 at 22:11
I'm not sure how to do that using R. – jonsca Apr 3 '12 at 22:20

1 Answer

up vote 2 down vote accepted

The same familiar spectrum instruction yields cross-spectra. coherency and phase when used on a bivariate time series. Look at this sample code. dIPC and Crudo are respectively (differenced) consumer price index and oil price. We first build a bivariate time series (out of ordinary ts time series) with ts.union, then invoke spectrum.

datos <- ts.union(dIPC,
           Crudo)
datos <- window(datos,
           start=c(1979,1),
           end=c(2002,1))
sp <- spectrum(datos,
           main="PetrĂ³leo e IPC",
           spans=rep(3,5))

We only need now to plot coherency and phase. I find it useful to align them one below the other with

par(mfrow=c(2,1))

and then do the plots:

plot(sp,plot.type="coh")
plot(sp,plot.type="phase")
share|improve this answer
What does (differenced) mean in this context? Is it just a characteristic of your data, or does it represent something I must do to my data before analysis? – Russell S. Pierce Apr 3 '12 at 14:49
You difference series x(t) by replacing it with dx(t) = x(t) - x(t-1). Since spectral analysis is intended for stationary random processes, this is a way of bringing non stationary data to near stationarity. Only needed if strong trends are apparent. – F. Tusell Apr 3 '12 at 16:16
How is gain calculated from this output? – Russell S. Pierce Apr 3 '12 at 17:30
Per Statistica's website: "The gain value is computed by dividing the cross-amplitude value by the spectrum density estimates for one of the two series in the analysis. Consequently, two gain values are computed, which can be interpreted as the standard least squares regression coefficients for the respective frequencies." But I'm unclear on how to find the cross-amplitude value. – Russell S. Pierce Apr 3 '12 at 21:36
1  
You can dig the source of spectrum, and you will find that cross-spectra are computed in an object of name pgram. Or, since the coherency is defined as the cross-spectrum divided by the square root of the product of univariate spectra (i.e. f12 / sqrt(f11*f22) ), you can find what you want the two gains as tou define them by multiplying the squared coherency by either univariate spectra. – F. Tusell Apr 4 '12 at 5:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.