analyze.coherency: Computation of the cross-wavelet power and wavelet coherence...

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/analyze.coherency.R

Description

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.

Usage

 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)

Arguments

my.data

data frame of time series (including header, and dates as row names or as separate column named "date" if available)

my.pair

pair of names or column indices indicating the series to be analyzed, e.g. c(1,2), c(2,1), c("dji","ftse").

Default: c(1,2).

loess.span

parameter alpha in loess controlling the degree of time series smoothing, if the time series are to be detrended; no detrending if loess.span = 0.

Default: 0.75.

dt

time resolution, i.e. sampling resolution in the time domain, 1/dt = number of observations per time unit. For example: a natural choice of dt in 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. If dt = 1, the time interval between two consecutive observations will equal one time unit.

Default: 1.

dj

frequency resolution, i.e. sampling resolution in the frequency domain, 1/dj = number of suboctaves (voices per octave).

Default: 1/20.

lowerPeriod

lower Fourier period (measured in time units determined by dt, see the explanations concerning dt) for wavelet decomposition.
If dt = 1, the minimum admissible value is 2.

Default: 2*dt.

upperPeriod

upper Fourier period (measured in time units determined by dt, see the explanations concerning dt) for wavelet decomposition.

Default: (floor of one third of time series length)*dt.

window.type.t

type of window for smoothing in time direction; select from:

0 ("none") : no smoothing in time direction
1 ("bar") : Bartlett
2 ("tri") : Triangular (Non-Bartlett)
3 ("box") : Boxcar (Rectangular, Dirichlet)
4 ("han") : Hanning
5 ("ham") : Hamming
6 ("bla") : Blackman

Default: 1 = "bar".

window.type.s

type of window for smoothing in scale (period) direction; select from:

0 ("none") : no smoothing in scale (period)
direction
1 ("bar") : Bartlett
2 ("tri") : Triangular (Non-Bartlett)
3 ("box") : Boxcar (Rectangular, Dirichlet)
4 ("han") : Hanning
5 ("ham") : Hamming
6 ("bla") : Blackman

Default: 1 = "bar".

window.size.t

size of the window used for smoothing in time direction, measured in time units determined by dt, see the explanations concerning dt.

Default: 5, which together with dt = 1 defines a window of length 5*(1/dt) = 5, equaling 5 observations (observation epochs). Windows of even-numbered sizes are extended by 1.

window.size.s

size of the window used for smoothing in scale (period) direction in units of 1/dj.

Default: 1/4, which together with dj = 1/20 defines a window of length (1/4)*(1/dj) = 5. Windows of even-numbered sizes are extended by 1.

make.pval

Compute p-values? Logical.

Default: TRUE.

method

the method of generating surrogate time series; select from:

"white.noise" : white noise
"shuffle" : shuffling the given time series
"Fourier.rand" : time series with a similar spectrum
"AR" : AR(p)
"ARIMA" : ARIMA(p,0,q)

Default: "white.noise".

params

a list of assignments between methods (AR, and ARIMA) and lists of parameter values applying to surrogates. Default: NULL.

Default includes two lists named AR and ARIMA:

  • AR = list(...), a list containing one single element:

    p : AR order.
    Default: 1.
  • ARIMA = list(...), a list of six elements:

    p : AR order.
    Default: 1.
    q : MA order.
    Default: 1.
    include.mean : Include a mean/intercept term?
    Default: TRUE.
    sd.fac : magnification factor to boost the
    residual standard deviation.
    Default: 1.
    trim : Simulate trimmed data?
    Default: FALSE.
    trim.prop : high/low trimming proportion.
    Default: 0.01.
n.sim

number of simulations.

Default: 100.

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. "%Y-%m-%d", or equivalently "%F"; see strptime for a list of implemented date conversion specifications. Explicit information given here will be overwritten by any later specification given in e.g. wc.image. If unspecified, date formatting will be attempted according to as.Date.

Default: NULL.

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 strptime. Explicit information given here will be overwritten by any specification given in e.g. wc.image. If unspecified, "" (the local time zone) will be used.

Default: NULL.

verbose

Print verbose output on the screen? Logical.

Default: TRUE.

Value

A list of class "analyze.coherency" with elements of different dimensions. The elements of matrix type, namely:

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:

date : the calendar date
(if available as column in my.data)
<x>, <y> : the two series which have been analyzed
(detrended, if loess.span != 0;
original names retained)
<x>.trend, <y>.trend : the two trend series
(included if loess.span != 0)

Row names are taken over from my.data, and so are dates if given as row names.

loess.span

parameter alpha in loess controlling the degree of time series smoothing if the time series were detrended; no detrending if loess.span = 0

dt

time resolution, i.e. sampling resolution in the time domain, 1/dt = number of observations per time unit

dj

frequency resolution, i.e. sampling resolution in the frequency domain, 1/dj = number of suboctaves (voices per octave)

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> (= phase.x minus phase.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 0s and 1s

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 dt, see the explanations concerning dt)

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 and axis.2.

axis.1

tick levels corresponding to the time steps used for (cross-)wavelet transformation: 1, 1+dt, 1+2dt, .... The default time axis in plot functions provided by WaveletComp is determined by observation epochs, however; "epoch" meaning point in time.

axis.2

tick levels corresponding to the log of Fourier periods: log2(Period). This determines the period axis in plot functions provided by WaveletComp.

date.format

the format of calendar date (if available)

date.tz

the time zone of calendar date (if available)

Author(s)

Angi Roesch and Harald Schmidbauer; credits are also due to Huidong Tian, Bernard Cazelles, Luis Aguiar-Conraria, and Maria Joana Soares.

References

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.

See Also

wc.image, wc.avg, wc.sel.phases, wc.phasediff.image, wt.image, wt.avg, wt.sel.phases, wt.phase.image, reconstruct

Examples

 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)

WaveletComp documentation built on May 2, 2019, 6:33 a.m.