Description Usage Arguments Value Author(s) References See Also Examples
View source: R/analyze.coherency.R
The two time series are selected from an input data frame by specifying either their names
or their column numbers. Optionally, the time series are detrended, using loess
with parameter
loess.span
. Internally, the series will be standardized before they undergo wavelet transformation.
The cross-wavelet power spectrum is computed applying the Morlet wavelet.
P-values to test the null hypothesis that a period (within lowerPeriod
and upperPeriod
)
is irrelevant at a certain time are calculated if desired; this is accomplished with the help of a
simulation algorithm. There is a selection of models from which to choose the alternative hypothesis.
The selected model will be fitted to the data and simulated according to estimated parameters
in order to provide surrogate time series.
For the computation of wavelet coherence, a variety of filtering methods is provided, with flexible window parameters.
Wavelet transformation, as well as p-value computations, are carried out by calling subroutine wc
.
The name and parts of the layout of subroutine wc
were inspired by a similar function
developed by Huidong Tian and Bernard Cazelles (archived R package WaveletCo
).
The basic concept of the simulation algorithm and of ridge determination build on ideas
developed by these authors. The major part of the code for the computation of the cone of influence
and the code for Fourier-randomized surrogate time series has been adopted from Huidong Tian.
The implementation of a choice of filtering windows for the computation of the wavelet coherence
was inspired by Luis Aguiar-Conraria and Maria Joana Soares (GWPackage
).
Cross-wavelet and coherence computation, the simulation algorithm and ridge determination build heavily on the use of matrices in order to minimize computation time in R.
This function provides a broad variety of final as well as intermediate results which can be further analyzed in detail.
1 2 3 4 5 6 7 8 9 10 | analyze.coherency(my.data, my.pair = c(1, 2), loess.span = 0.75,
dt = 1, dj = 1/20,
lowerPeriod = 2*dt,
upperPeriod = floor(nrow(my.data)/3)*dt,
window.type.t = 1, window.type.s = 1,
window.size.t = 5, window.size.s = 1/4,
make.pval = TRUE, method = "white.noise", params = NULL,
n.sim = 100,
date.format = NULL, date.tz = NULL,
verbose = TRUE)
|
my.data |
data frame of time series (including header, and dates as row names or as separate column
named |
my.pair |
pair of names or column indices indicating the series to be analyzed,
e.g. Default: |
loess.span |
parameter Default: |
dt |
time resolution, i.e. sampling resolution in the time domain, Default: |
dj |
frequency resolution, i.e. sampling resolution in the frequency domain, Default: |
lowerPeriod |
lower Fourier period (measured in time units determined by Default: |
upperPeriod |
upper Fourier period (measured in time units determined by Default: |
window.type.t |
type of window for smoothing in time direction; select from:
Default: | ||||||||||||||||||||||||||||||||||||||||
window.type.s |
type of window for smoothing in scale (period) direction; select from:
Default: | ||||||||||||||||||||||||||||||||||||||||
window.size.t |
size of the window used for smoothing in time direction, measured in time units
determined by Default: | ||||||||||||||||||||||||||||||||||||||||
window.size.s |
size of the window used for smoothing in scale (period) direction in units of Default: |
make.pval |
Compute p-values? Logical. Default: |
method |
the method of generating surrogate time series; select from:
Default: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
params |
a list of assignments between methods (AR, and ARIMA) and lists of parameter values
applying to surrogates. Default: Default includes two lists named
|
n.sim |
number of simulations. Default: |
date.format |
optional, and for later reference: the format of calendar date
(if available in the input data frame) given as a character string, e.g. Default: |
date.tz |
optional, and for later reference: a character string specifying the time zone of calendar date
(if available in the input data frame); see Default: |
verbose |
Print verbose output on the screen? Logical. Default: |
A list of class "analyze.coherency"
with elements of different dimensions.
The elements of matrix type, namely:
Wave.xy
, Angle
, sWave.xy
, sAngle
,
Power.xy
, Power.xy.pval
,
Coherency
, Coherence
, Coherence.pval
,
Wave.x
, Wave.y
, Phase.x
, Phase.y
, Ampl.x
, Ampl.y
,
Power.x
, Power.y
, Power.x.pval
, Power.y.pval
, sPower.x
, sPower.y
,
Ridge.xy
, Ridge.co
, Ridge.x
, Ridge.y
,
have the following structure:
columns correspond to observations (observation epochs; "epoch" meaning point in time),
rows correspond to scales (Fourier periods) whose values are given in Scale
(Period
).
Here is a detailed list of all elements:
series |
a data frame with the following columns:
Row names are taken over from | ||||||||||||||||||||||||||||
loess.span |
parameter |
dt |
time resolution, i.e. sampling resolution in the time domain, |
dj |
frequency resolution, i.e. sampling resolution in the frequency domain, |
Wave.xy |
(complex-valued) cross-wavelet transform (analogous to Fourier cross-frequency spectrum, and to the covariance in statistics) |
Angle |
phase difference, i.e. phase lead of <x> over <y> (= |
sWave.xy |
smoothed (complex-valued) cross-wavelet transform |
sAngle |
phase difference, i.e. phase lead of <x> over <y>, affected by smoothing |
Power.xy |
cross-wavelet power (analogous to Fourier cross-frequency power spectrum) |
Power.xy.avg |
average cross-wavelet power in the frequency domain (averages over time) |
Power.xy.pval |
p-values of cross-wavelet power |
Power.xy.avg.pval |
p-values of average cross-wavelet power |
Coherency |
the (complex-valued) wavelet coherency of series <x> over series <y> in the time/frequency domain, affected by smoothing (analogous to Fourier coherency, and to the coefficient of correlation in statistics) |
Coherence |
wavelet coherence (analogous to Fourier coherence, and to the coefficient of determination in statistics (affected by smoothing) |
Coherence.avg |
average wavelet coherence in the frequency domain (averages across time) |
Coherence.pval |
p-values of wavelet coherence |
Coherence.avg.pval |
p-values of average wavelet coherence |
Wave.x, Wave.y |
(complex-valued) wavelet transforms of series <x> and <y> |
Phase.x, Phase.y |
phases of series <x> and <y> |
Ampl.x, Ampl.y |
amplitudes of series <x> and <y> |
Power.x, Power.y |
wavelet power of series <x> and <y> |
Power.x.avg, Power.y.avg |
average wavelet power of series <x> and <y>, averages across time |
Power.x.pval, Power.y.pval |
p-values of wavelet power of series <x> and <y> |
Power.x.avg.pval, Power.y.avg.pval |
p-values of average wavelet power of series <x> and <y> |
sPower.x, sPower.y |
smoothed wavelet power of series <x> and <y> |
Ridge.xy |
ridge of cross-wavelet power, in the form of a matrix of |
Ridge.co |
ridge of wavelet coherence |
Ridge.x, Ridge.y |
power ridges of series <x> and <y> |
Period |
the Fourier periods
(measured in time units determined by |
Scale |
the scales (the Fourier periods divided by the Fourier factor) |
nc |
number of columns = number of observations = number of observation epochs; "epoch" meaning point in time |
nr |
number of rows = number of scales (Fourier periods) |
coi.1, coi.2 |
borders of the region where the wavelet transforms are not influenced by edge effects (cone of influence).
The coordinates of the borders are expressed in terms of internal axes |
axis.1 |
tick levels corresponding to the time steps used for (cross-)wavelet transformation: |
axis.2 |
tick levels corresponding to the log of Fourier periods: |
date.format |
the format of calendar date (if available) |
date.tz |
the time zone of calendar date (if available) |
Angi Roesch and Harald Schmidbauer; credits are also due to Huidong Tian, Bernard Cazelles, Luis Aguiar-Conraria, and Maria Joana Soares.
Aguiar-Conraria L., and Soares M.J., 2011. Business cycle synchronization and the Euro: A wavelet analysis. Journal of Macroeconomics 33 (3), 477–489.
Aguiar-Conraria L., and Soares M.J., 2011. The Continuous Wavelet Transform: A Primer. NIPE Working Paper Series 16/2011.
Aguiar-Conraria L., and Soares M.J., 2012. GWPackage
.
Available at https://sites.google.com/site/aguiarconraria/joanasoares-wavelets; accessed September 4, 2013.
Cazelles B., Chavez M., Berteaux, D., Menard F., Vik J.O., Jenouvrier S., and Stenseth N.C., 2008. Wavelet analysis of ecological time series. Oecologia 156, 287–304.
Liu P.C., 1994. Wavelet spectrum analysis and ocean wind waves. In: Foufoula-Georgiou E., and Kumar P., (eds.), Wavelets in Geophysics, Academic Press, San Diego, 151–166.
Tian, H., and Cazelles, B., 2012. WaveletCo
.
Available at https://cran.r-project.org/src/contrib/Archive/WaveletCo/, archived April 2013; accessed July 26, 2013.
Torrence C., and Compo G.P., 1998. A practical guide to wavelet analysis. Bulletin of the American Meteorological Society 79 (1), 61–78.
Veleda D., Montagne R., and Araujo M., 2012. Cross-Wavelet Bias Corrected by Normalizing Scales. Journal of Atmospheric and Oceanic Technology 29, 1401–1408.
wc.image
, wc.avg
, wc.sel.phases
, wc.phasediff.image
,
wt.image
, wt.avg
, wt.sel.phases
, wt.phase.image
, reconstruct
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | ## Not run:
## The following example is modified from Veleda et al, 2012:
series.length <- 3*128*24
x1 <- periodic.series(start.period = 1*24, length = series.length)
x2 <- periodic.series(start.period = 2*24, length = series.length)
x3 <- periodic.series(start.period = 4*24, length = series.length)
x4 <- periodic.series(start.period = 8*24, length = series.length)
x5 <- periodic.series(start.period = 16*24, length = series.length)
x6 <- periodic.series(start.period = 32*24, length = series.length)
x7 <- periodic.series(start.period = 64*24, length = series.length)
x8 <- periodic.series(start.period = 128*24, length = series.length)
x <- x1 + x2 + x3 + x4 + 3*x5 + x6 + x7 + x8 + rnorm(series.length)
y <- x1 + x2 + x3 + x4 - 3*x5 + x6 + 3*x7 + x8 + rnorm(series.length)
matplot(data.frame(x, y), type = "l", lty = 1, xaxs = "i", col = 1:2,
xlab = "index", ylab = "",
main = "hourly series with periods of 1, 2, 4, 8, 16, 32, 64, 128 days",
sub = "(out of phase at period 16, different amplitudes at period 64)")
legend("topright", legend = c("x","y"), col = 1:2, lty = 1)
## The following dates refer to the local time zone
## (possibly allowing for daylight saving time):
my.date <- seq(as.POSIXct("2014-10-14 00:00:00", format = "%F %T"),
by = "hour",
length.out = series.length)
my.data <- data.frame(date = my.date, x = x, y = y)
## Computation of cross-wavelet power and wavelet coherence, x over y:
## a natural choice of 'dt' in the case of hourly data is 'dt = 1/24',
## resulting in one time unit equaling one day.
## This is also the time unit in which periods are measured.
## There is an option to store the date format and time zone as additional
## parameters within object 'my.wc' for later reference.
my.wc <- analyze.coherency(my.data, c("x","y"),
loess.span = 0,
dt = 1/24, dj = 1/20,
window.size.t = 1, window.size.s = 1/2,
lowerPeriod = 1/4,
make.pval = TRUE, n.sim = 10,
date.format = "%F %T", date.tz = "")
## Note:
## By default, Bartlett windows are used for smoothing in order to obtain
## the wavelet coherence spectrum; window lengths in this example:
## 1*24 + 1 = 25 observations in time direction,
## (1/2)*20 + 1 = 11 units in scale (period) direction.
## Plot of cross-wavelet power
## (with color breakpoints according to quantiles):
wc.image(my.wc, main = "cross-wavelet power spectrum, x over y",
legend.params = list(lab = "cross-wavelet power levels"),
periodlab = "period (days)")
## The same plot, now with calendar axis
## (according to date format stored in 'my.wc'):
wc.image(my.wc, main = "cross-wavelet power spectrum, x over y",
legend.params = list(lab = "cross-wavelet power levels"),
periodlab = "period (days)", show.date = TRUE)
## Plot of average cross-wavelet power:
wc.avg(my.wc, siglvl = 0.05, sigcol = 'red',
periodlab = "period (days)")
## Plot of wavelet coherence
## (with color breakpoints according to quantiles):
wc.image(my.wc, which.image = "wc", main = "wavelet coherence, x over y",
legend.params = list(lab = "wavelet coherence levels",
lab.line = 3.5, label.digits = 3),
periodlab = "period (days)")
## plot of average coherence:
wc.avg(my.wc, which.avg = "wc",
siglvl = 0.05, sigcol = 'red',
legend.coords = "topleft",
periodlab = "period (days)")
## Please see our guide booklet for further examples:
## URL http://www.hs-stat.com/projects/WaveletComp/WaveletComp_guided_tour.pdf.
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.