Title: | Simulation and Spectral Estimation of Locally Stationary Wavelet Packet Processes |
---|---|
Description: | Library of functions for the statistical analysis and simulation of Locally Stationary Wavelet Packet (LSWP) processes. The methods implemented by this library are described in Cardinali and Nason (2017) <doi:10.1111/jtsa.12230>. |
Authors: | Alessandro Cardinali [aut, cre], Guy Nason [aut] |
Maintainer: | Alessandro Cardinali <[email protected]> |
License: | GPL-3 |
Version: | 0.1.0 |
Built: | 2024-11-20 06:32:58 UTC |
Source: | CRAN |
autoconv
computes the linear convolution of a numeric vector with itself.
It is based on the fft
function and is twicked to achieve maximum performance.
autoconv(x)
autoconv(x)
x |
a real or complex vector |
The speed of calculation for the linear convolution depends upon the number of factors in the number representing the vector length. This implementation maximizes calculation speed for vectors of dyadic length, or lengths with a single factor.
The linear auto convolution of a given vector with itself, which is equivalent with its inner product.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
v <- rnorm(n = 64) vv <- autoconv(x = v)
v <- rnorm(n = 64) vv <- autoconv(x = v)
best.basis
returns a selection of packets from a dyadic tree where the selection is made by minimizing the cost functionals associated with each packet.
best.basis(wpc)
best.basis(wpc)
wpc |
this is a list containing the cost functionals associated with each packet. Each element in the list corresponds to a level of the dyadic tree. |
The function implements best basis selection from an arbitrary tree. Typically this tree is produced by other functions in this package and this function is also used to produce a selected basis. Since best basis methods are of general interest this function has been exported for possible other uses.
A matrix of two columns where each row refers to a different selected packet. The first index refers to the tree level, the second index refers to the packet within that level.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
costs <- vector(mode = 'list', length = 4) for(i in 1:4) costs[[i]] <- rnorm(2^i)^2 best.basis(wpc = costs)
costs <- vector(mode = 'list', length = 4) for(i in 1:4) costs[[i]] <- rnorm(2^i)^2 best.basis(wpc = costs)
get.flat.basis
returns the full set of packet indices relative to a basis
for a single scale from the wavelet packet table.
get.flat.basis(scale)
get.flat.basis(scale)
scale |
The scale for which the indices of wavelet packet basis are returned. Typically this is a positive integer. |
This function is used internally by other routines but it might be useful when
the wavelet packet spectral estimation over a fixed scale is of interest. The function returns
an object of class lswpbb
, whose structure is the same to the object produced by best.basis
.
A matrix of two columns where each row refers to a different selected packet.
The first index is the argument scale
, the second index refers to the packet within this level.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
get.flat.basis(scale = 4)
get.flat.basis(scale = 4)
get.wavelet.basis
returns the full set of packet indices relative to a wavelet basis
selected from the wavelet packet table.
get.wavelet.basis(scale)
get.wavelet.basis(scale)
scale |
The maximum scale for which the indices of the wavelet basis are returned. Tipically this is a positive integer. |
This function is used internally by other routines but it might be useful when
the 'classical' wavelet spectral estimation is of interest. The function returns
an object of class LSWPbasis
, whose structure is the same to the object produced by
best.basis
.
A matrix of two columns where each row refers to a different selected packet. The first index refers to each given scale, the second index refers to the packet within this level.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
get.wavelet.basis(scale = 4)
get.wavelet.basis(scale = 4)
LSWPbasis
returns a matrix containing the wavelet packet basis indices.
LSWPbasis(x, wavelet, lev.max, smooth, spa, penalty = 0.976)
LSWPbasis(x, wavelet, lev.max, smooth, spa, penalty = 0.976)
x |
a (locally stationary) time series of dyadic length. |
wavelet |
the wavelet used to estimate the wavelet packet spectra. |
lev.max |
the maximum scale for which the basis is fitted. |
smooth |
should the penasised least squares cost functionals be smoothed? Default value is |
spa |
parameter for the local polynomial smothing implemented through |
penalty |
implemets increasing penalty for increasing scales. |
This function fits a wavelet packet basis to data using a penalised least square method.
This function implements a data-driven basis selection of locally stationary time series.
The wavelet argument is specified as in other functions of this package.
Therefore, the current implementation allows for three discrete wavelets: Haar ("haar"
),
Daubechies Extremal Phase linear filters of length 4 ("d4"
) and Least Asymmetric linear filters of length 8 ("la8"
).
Smoothing is controlled through the argument spa.
A matrix of dimensions |b| x 2, where |b| is the number of packets in the basis. The first column contains the scale indices of each packet in the basis, the second column contains the packet index within each scale.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
wpb <- LSWPbasis(x = sp500, wavelet = 'la8', lev.max = 4, smooth = TRUE, spa = 0.35)
wpb <- LSWPbasis(x = sp500, wavelet = 'la8', lev.max = 4, smooth = TRUE, spa = 0.35)
Library of functions for the statistical analysis and simulation of LSWP processes.
Alessandro Cardinali [email protected]
LSWPsim
returns simulated time series from a specified LSWP specification.
LSWPsim(bb, spec, lev, wavelet, N)
LSWPsim(bb, spec, lev, wavelet, N)
bb |
a wavelet packet basis for the simulated process. |
spec |
a (locally stationary) spectra corresponding to the wavelet packet basis. |
lev |
the maximum level of the basis that is considered for simulation. Usually this is set as the maximum level in |
wavelet |
the Daubechies wavelet used to build wavelet packets to simulate the process. See also Details. |
N |
the number of realizations to be simulated. |
This function produces one or multiple realizations of an LSWP process that is specified in terms of a wavelet packet basis and its corresponding spectra.
The function simulates realizations accordingly to the specified arguments.
The wavelet argument is specified as in other functions of this package.
Therefore, the current implementation allows for three discrete wavelets: Haar ("haar"
),
Daubechies Extremal Phase linear filters of length 4 ("d4"
) and Least Asymmetric linear filters of length 8 ("la8"
).
If N = 1
the function returns a vector containing the simulated time series.
If N > 1
the function returns a matrix with N
columns each containing a different
simulated series.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
LSWPspec
, best.basis
, get.flat.basis
, get.wavelet.basis
.
wwb <- get.flat.basis(scale = 4) wwp <- matrix(2^{-(1:4)}, nrow = 4, ncol = 512, byrow = FALSE) xt <- LSWPsim(bb = wwb, spec = wwp, lev = 4, wavelet = 'la8', N = 10)
wwb <- get.flat.basis(scale = 4) wwp <- matrix(2^{-(1:4)}, nrow = 4, ncol = 512, byrow = FALSE) xt <- LSWPsim(bb = wwb, spec = wwp, lev = 4, wavelet = 'la8', N = 10)
LSWPspec
returns the spectral estimate of a locally stationary time series
characterized by a wavelet packet basis.
LSWPspec(x, lev, bb, wavelet, smooth, spa, correct = TRUE, AA = NULL)
LSWPspec(x, lev, bb, wavelet, smooth, spa, correct = TRUE, AA = NULL)
x |
a real valued numeric vector containing a time series of dyadic length. |
lev |
the maximum level for which the spectra should be estimated. |
bb |
a wavelet packet basis for which the spectra is estimated. |
wavelet |
wavelet used to estimate the wavelet packet spectra. Possible values are |
smooth |
logical. If |
spa |
window length for spectral smoothing. Increasing values increase the smoothing. |
correct |
logical. Should the returned spectral estimate be unbiased? Default is |
AA |
this argument is for internal use only and should be left alone. See also Details. |
The current implementation allow the use of these three well known Daubechies discrete wavelets for spectral estimation. Default choice is the
"la8"
wavelet which has decent control over frequency leakage characterizing compactly supported filters. In this initial implementation
smoothing is provided by local polynomials through the lowess
function and the smoothing parameter spa
is passed to lowess
.
Future package versions will allow for different smoothing methods. The argument AA
is tipically used by other functions to provide the
inner product matrix when running simulations. For a direct usage on a single time series the matrix is calculated internally usig the default settings.
A matrix containing the time-frequency spectral estimate where each column corresponds to a different time point and ech row corresponds to a different packet from the given basis.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
get.wavelet.basis
, LSWPsim
, best.basis
.
wb <- get.wavelet.basis(4) wpp <- LSWPspec(x = sp500, lev = 4, bb = wb, wavelet = 'la8', smooth = TRUE, spa = 0.35)
wb <- get.wavelet.basis(4) wpp <- LSWPspec(x = sp500, lev = 4, bb = wb, wavelet = 'la8', smooth = TRUE, spa = 0.35)
marg.spec
returns the time-average spectra of LSWP processes for each packet.
marg.spec(bas, spec, plot = TRUE)
marg.spec(bas, spec, plot = TRUE)
bas |
is a (|b| x 2) matrix containing indices of a wavelet packet basis, where |b| is the number of packets in the basis. |
spec |
is a (|b| x T) matrix containing, in each row, the values of the time-varying spectra for each packet. |
plot |
should a plot of the marginal spectra vs frequency intervals be returned? |
This function computes the frequency intervals corresponding to each packet, along with the (time) average spectra for each packet.
This function is used to compute, and eventually plot, the time averaged spectra (or spectral estimate) vs packet frequencies. The arguments bas and spec shuld be provided as matrices.
A (|b| x 2) matrix. In the first column the lower frequency relative to each packet is displayed. The second column contains the (time) average spectra.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
wwb <- get.wavelet.basis(scale = 4) wwp <- matrix(2^{-(1:4)}, nrow = 4, ncol = 512, byrow = FALSE) msp <- marg.spec(bas = wwb, spec = wwp, plot = TRUE)
wwb <- get.wavelet.basis(scale = 4) wwp <- matrix(2^{-(1:4)}, nrow = 4, ncol = 512, byrow = FALSE) msp <- marg.spec(bas = wwb, spec = wwp, plot = TRUE)
plot.LSWPspec
returns the plot for objects of class "LSWPspec"
, typically (but not exclusively) a wavelet packet spectral estimate.
## S3 method for class 'LSWPspec' plot(x, y, ...)
## S3 method for class 'LSWPspec' plot(x, y, ...)
x |
an object of class lswpspec. |
y |
not used, is set to |
... |
not currently used. |
This function implements the plot
method for objects of class "LSWPspec"
. It is mainly used to plot spectral estimates returned by LSWPspec
.
The label of the vertical axis uses the wavelet packet basis index notation p = 1,2,...,|b|
, where |b| is the number of packets in a wavelet
packet basis as defined in Cardinali and Nason (2017). The label of the horizontal axis is the time index.
A plot of the time-varying spectral estimates.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
wb <- get.wavelet.basis(4) wpp <- LSWPspec(x = sp500, lev = 4, bb = wb, wavelet = 'la8', smooth = TRUE, spa = 0.35) plot(wpp)
wb <- get.wavelet.basis(4) wpp <- LSWPspec(x = sp500, lev = 4, bb = wb, wavelet = 'la8', smooth = TRUE, spa = 0.35) plot(wpp)
Log-returns from daily quotes of the Standard & Poors 500 Index.
sp500
sp500
A vector containing 1024 daily log-returns.
The data cover the period April 1996 - December 1999.
summary.LSWPbasis
returns a table containing the wavelet packet basis and its wavelet packet bases index notation.
## S3 method for class 'LSWPbasis' summary(object, ...)
## S3 method for class 'LSWPbasis' summary(object, ...)
object |
an object of class |
... |
not currently used. |
This function is used to print a wavelet packet basis with the wavelet packet basis index notation p = 1,2,...,|b|
,
where |b| is the number of packets in a wavelet packet basis as defined in Cardinali and Nason (2017). The doublets "j_p, i_p"
refer,
to the scale and packet index within each scale, respectively.
Print an object of class LSWPbasis
with LSWP basis notation.
Alessandro Cardinali
A. Cardinali and G.P. Nason (2017). Locally Stationary Wavelet Packet Processes: Basis Selection and Model Fitting. Journal of Time Series Analysis, 38:2, 151-174.
wpb <- LSWPbasis(x = sp500, wavelet = 'la8', lev.max = 4, smooth = TRUE, spa = 0.35) summary(wpb)
wpb <- LSWPbasis(x = sp500, wavelet = 'la8', lev.max = 4, smooth = TRUE, spa = 0.35) summary(wpb)