Title: | Test of Stationarity and Localized Autocovariance |
---|---|
Description: | Provides test of second-order stationarity for time series (for dyadic and arbitrary-n length data). Provides localized autocovariance, with confidence intervals, for locally stationary (nonstationary) time series. See Nason, G P (2013) "A test for second-order stationarity and approximate confidence intervals for localized autocovariance for locally stationary time series." Journal of the Royal Statistical Society, Series B, 75, 879-904. <doi:10.1111/rssb.12015>. |
Authors: | Guy Nason [aut, cre] |
Maintainer: | Guy Nason <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.7.7 |
Built: | 2024-11-06 06:23:31 UTC |
Source: | CRAN |
Provides functionality to perform a new test of second-order stationarity for time series. The method works by computing a wavelet periodogram and then examining its Haar wavelet coefficients for significant ones. The other main feature of the software is to compute the localized autocovariance and pointwise confidence intervals.
For the test of stationarity there are two main functions.
The original is
the hwtos2
function and this returns a
tos
object. The hwtos2
function
works on data sets whose length is a power of two. Version 1.5
introduced a new function, hwtos
which carries out the
test on arbitrary length data.
The summary.tos
function
performs a Bonferroni and FDR statistical analysis to detect
which Haar wavelet coefficients are significant. The
function plot.tos
provides a plot of the
original time series with any non-stationarities clearly indicated
on the plot (actually locations and scales of the Haar wavelet coefficients).
For the localized autocovariance the main function is
Rvarlacf
. This computes the localized autocovariance
values and approximate pointwise condifence intervals. The function
plot.lacfCI
can then plot the localized autocovariance
and its confidence intervals in a number of forms.
Guy Nason
Maintainer: Guy Nason
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Here's a simple simulated example. # # A series which is a concatenation of two iid Gaussian series with # different variances. # x <- c(rnorm(256, sd=1), rnorm(256, sd=2)) # # Let's do a test of stationarity # st.test <- hwtos2(x) #8 7 6 5 4 3 # # Ok, that's the computation gone, let's look at the results. # st.test #Class 'tos' : Stationarity Object : #~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 186 hypothesis tests altogether #There were 4 FDR rejects #The rejection p-value was 0.0001376564 #Using Bonferroni rejection p-value is 0.0002688172 #And there would be 4 rejections. #Listing FDR rejects... (thanks Y&Y!) #P: 5 HWTlev: 0 indices on next line...[1] 1 #P: 6 HWTlev: 0 indices on next line...[1] 1 #P: 7 HWTlev: 0 indices on next line...[1] 1 #P: 8 HWTlev: 0 indices on next line...[1] 1 # # In the lines above if there are any rejects then the series is # deemed to be nonstationary, and note that there were 4 in both # the lines above (sometimes FDR rejects a few more). # # You can also plot the object and it shows you where it thinks the # nonstationarities are # ## Not run: plot(st.test) # # See the help page for the hwtos2 function, where there is an example # with a stationary series. # # For the localized autocovariance... # # Let's use the function tvar1sim which generates a time-varying AR model # with AR(1) paramter varying over the extent of the series from 0.9 # to -0.9 (that is, near the start of the series it behaves like an # AR(1) with parameter 0.9, and near the end like an AR(1) with parameter # -0.9, and in between the parameter is somewhere between 0.9 and -0.9 # figured linearly between the two. # x <- tvar1sim() # # Plot it, so you know what the series looks like, should always do this. # ## Not run: ts.plot(x) # # Now, let's compute the localized autocovariance and also confidence intervals # For the variance, let's look at the first 20 lags # # Do it at t=50 and t=450, ie what is the localized autocovariance at these # two times. # x.lacf.50 <- Rvarlacf(x=x, nz=50, var.lag.max=20) x.lacf.450 <- Rvarlacf(x=x, nz=450, var.lag.max=20) # # Now plot the answers, you may want to do this on two different plots # so that you can compare the answers # # ## Not run: plot(x.lacf.50, plotcor=FALSE, type="acf") ## Not run: plot(x.lacf.450, plotcor=FALSE, type="acf") # # Note that the plotcor argument is set so covariances and not correlations # are plotted. Also, the type is set to "acf" to make the plot *look* like # the regular acf plot. But DON'T be fooled, it is not the regular acf # that is plotted, but a time localized plot. The two plots should look # very different, both like AR(1) but with different parameters (from the # same time series). # # You could also plot the regular acf and see how it gets it wrong! #
# # Here's a simple simulated example. # # A series which is a concatenation of two iid Gaussian series with # different variances. # x <- c(rnorm(256, sd=1), rnorm(256, sd=2)) # # Let's do a test of stationarity # st.test <- hwtos2(x) #8 7 6 5 4 3 # # Ok, that's the computation gone, let's look at the results. # st.test #Class 'tos' : Stationarity Object : #~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 186 hypothesis tests altogether #There were 4 FDR rejects #The rejection p-value was 0.0001376564 #Using Bonferroni rejection p-value is 0.0002688172 #And there would be 4 rejections. #Listing FDR rejects... (thanks Y&Y!) #P: 5 HWTlev: 0 indices on next line...[1] 1 #P: 6 HWTlev: 0 indices on next line...[1] 1 #P: 7 HWTlev: 0 indices on next line...[1] 1 #P: 8 HWTlev: 0 indices on next line...[1] 1 # # In the lines above if there are any rejects then the series is # deemed to be nonstationary, and note that there were 4 in both # the lines above (sometimes FDR rejects a few more). # # You can also plot the object and it shows you where it thinks the # nonstationarities are # ## Not run: plot(st.test) # # See the help page for the hwtos2 function, where there is an example # with a stationary series. # # For the localized autocovariance... # # Let's use the function tvar1sim which generates a time-varying AR model # with AR(1) paramter varying over the extent of the series from 0.9 # to -0.9 (that is, near the start of the series it behaves like an # AR(1) with parameter 0.9, and near the end like an AR(1) with parameter # -0.9, and in between the parameter is somewhere between 0.9 and -0.9 # figured linearly between the two. # x <- tvar1sim() # # Plot it, so you know what the series looks like, should always do this. # ## Not run: ts.plot(x) # # Now, let's compute the localized autocovariance and also confidence intervals # For the variance, let's look at the first 20 lags # # Do it at t=50 and t=450, ie what is the localized autocovariance at these # two times. # x.lacf.50 <- Rvarlacf(x=x, nz=50, var.lag.max=20) x.lacf.450 <- Rvarlacf(x=x, nz=450, var.lag.max=20) # # Now plot the answers, you may want to do this on two different plots # so that you can compare the answers # # ## Not run: plot(x.lacf.50, plotcor=FALSE, type="acf") ## Not run: plot(x.lacf.450, plotcor=FALSE, type="acf") # # Note that the plotcor argument is set so covariances and not correlations # are plotted. Also, the type is set to "acf" to make the plot *look* like # the regular acf plot. But DON'T be fooled, it is not the regular acf # that is plotted, but a time localized plot. The two plots should look # very different, both like AR(1) but with different parameters (from the # same time series). # # You could also plot the regular acf and see how it gets it wrong! #
Computes running mean estimator closest to wavelet estimator of evolutionary wavelet spectrum. The idea is to obtain a good linear bandwidth.
AutoBestBW(x, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, tol = 0.01, maxits = 200, plot.it = FALSE, verbose = 0, ReturnAll = FALSE)
AutoBestBW(x, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, tol = 0.01, maxits = 200, plot.it = FALSE, verbose = 0, ReturnAll = FALSE)
x |
Time series you want to analyze. |
filter.number |
The wavelet filter used to carry out smoothing operations. |
family |
The wavelet family used to carry out smoothing operations. |
smooth.dev |
The deviance estimate used for the smoothing (see ewspec help) |
AutoReflect |
Mitigate periodic boundary conditions of wavelet transforms by reflecting time series about RHS end before taking transforms (and is undone before returning the answer). |
tol |
Tolerance for golden section search for the best bandwidth |
maxits |
Maximum number of iterations for the golden section search |
plot.it |
Plot the values of the bandwidth and its closeness of the linear smooth to the wavelet smooth, if TRUE. |
verbose |
If nonzero prints out informative messages about the progress of the golden section search. Higher integers produce more messages. |
ReturnAll |
If TRUE then return the best bandwidth (in the ans component), the wavelet smooth (in EWS.wavelet) and the closest linear smooth (EWS.linear). If FALSE then just the bandwidth is returned. |
Tries to find the best running mean fit to an estimated spectrum obtained via wavelet shrinkage. The goal is to try and find a reasonable linear bandwidth.
If ReturnAll argument is FALSE then the best bandwidth is returned.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Generate synthetic data # x <- rnorm(256) # # Compute best linear bandwidth # tmp <- AutoBestBW(x=x) # # Printing it out in my example gives: # tmp # [1] 168
# # Generate synthetic data # x <- rnorm(256) # # Compute best linear bandwidth # tmp <- AutoBestBW(x=x) # # Printing it out in my example gives: # tmp # [1] 168
Computes using the formula
given in Nason (2012) in Theorem 1. Note: one usually should
use the
covIwrap
function for efficiency.
covI(II, m, n, ll, ThePsiJ)
covI(II, m, n, ll, ThePsiJ)
II |
Actually the *spectral* estimate S, not the periodogram values. This is for an assumed stationary series, so this is just a vector of length J, one for each scale of S. |
m |
Time location m |
n |
Time location n |
ll |
Scale of the raw wavelet periodogram |
ThePsiJ |
Autocorrelation wavelet corresponding to the wavelet that computed the raw peridogram (also assumed to underlie the time series |
The covariance is returned.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # Compute the covariance # covI(II=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, ThePsiJ=P1) # # [1] 0.8430809
P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # Compute the covariance # covI(II=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, ThePsiJ=P1) # # [1] 0.8430809
Computation of the covI
function is
intensive. This function permits values of covI
to be stored in an object, and then if these values are
requested again the values can be obtained from a store
rather than being computed from scratch.
covIwrap(S, m, n, ll, storewrap, P)
covIwrap(S, m, n, ll, storewrap, P)
S |
Same argument as for |
m |
The same argument as in |
n |
The same argument as in |
ll |
The same argument as in |
storewrap |
A list. On first call to this function the user should
supply |
P |
Same argument as in |
Note: covIwrap
could be removed from the function tree
altogether. I.e. varip2
could call
covI
directly. However,
covIwrap
considerably improves the efficiency of the algorithm
as it stores intermediate calculations that can be reused rather
than being computed repeatedly.
A list containing the following components:
ans |
The appropriate covariance |
storewrap |
A list containing information about all previously
computed covariances. This list should be supplied as the
|
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # First call to covIwrap # ans <- covIwrap(S=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, storewrap=NULL, P=P1) # # Make sure you keep the storewrap component. # my.storewrap <- ans$storewrap # # What is the answer? # ans$ans #[1] 0.8430809 # # Issue next call to covIwrap: but storewrap argument is now the one we stored. # ans <- covIwrap(S=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, storewrap=my.storewrap, P=P1) # # This call will reuse the stored value. However, if you change any of the # arguments then the store won't be used.
P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # First call to covIwrap # ans <- covIwrap(S=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, storewrap=NULL, P=P1) # # Make sure you keep the storewrap component. # my.storewrap <- ans$storewrap # # What is the answer? # ans$ans #[1] 0.8430809 # # Issue next call to covIwrap: but storewrap argument is now the one we stored. # ans <- covIwrap(S=c(1/2, 1/4, 1/8, 1/16, 1/32), m=1, n=3, ll=5, storewrap=my.storewrap, P=P1) # # This call will reuse the stored value. However, if you change any of the # arguments then the store won't be used.
Performs precisely the same role as varip2
except it is implemented internally using C code and hence
is much faster.
Cvarip2(i, p, ll, S, Pmat, PsiJL)
Cvarip2(i, p, ll, S, Pmat, PsiJL)
i |
Scale parameter of Haar wavelet analyzing periodogram. Scale 1 is the finest scale. |
p |
Location parameter of Haar wavelet analyzing periodogram |
ll |
Scale of the raw wavelet periodogram being analyzed. |
S |
Estimate of the spectrum, under the assumption of stationarity.
So, this is just a vector of (possibly) J scales (which is often
the usual spectral estimate averaged over time). Note: that the
main calling function, |
Pmat |
Matrix version of autocorrelation wavelet computed
using the |
PsiJL |
True length of the autocorrelation wavelets
in the |
The list returned from the .C
calling function.
The only object of real interest is the ans
component
which contains the variance.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example from varip2 # # my.Pmat <- PsiJmat(-5, filter.number=1, family="DaubExPhase") my.PsiJ <- PsiJ(-5, filter.number=1, family="DaubExPhase") my.PsiJL <- sapply(my.PsiJ, "length") Cvarip2(i=1, p=10, ll=2, S=c(1/2,1/4,1/8,1/16,1/32), Pmat=my.Pmat, PsiJL=my.PsiJL) # # Gives answer 1.865244, which is the same as given in the example for varip2
# # See example from varip2 # # my.Pmat <- PsiJmat(-5, filter.number=1, family="DaubExPhase") my.PsiJ <- PsiJ(-5, filter.number=1, family="DaubExPhase") my.PsiJL <- sapply(my.PsiJ, "length") Cvarip2(i=1, p=10, ll=2, S=c(1/2,1/4,1/8,1/16,1/32), Pmat=my.Pmat, PsiJL=my.PsiJL) # # Gives answer 1.865244, which is the same as given in the example for varip2
An estimate of the wavelet periodogram at a location
nz
is generated. This is obtained by first computing the
empirical raw wavelet periodogram by squaring the results of
the nondecimated wavelet transform of the time series. Then
a running mean smooth is applied.
EstBetaCov(x, nz, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, WPsmooth.type = "RM", binwidth = 0, mkcoefOBJ, ThePsiJ, Cverbose = 0, verbose = 0, OPLENGTH = 10^5, ABB.tol = 0.1, ABB.plot.it = FALSE, ABB.verbose = 0, ABB.maxits = 10, do.init = TRUE, truedenom=FALSE, ...)
EstBetaCov(x, nz, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, WPsmooth.type = "RM", binwidth = 0, mkcoefOBJ, ThePsiJ, Cverbose = 0, verbose = 0, OPLENGTH = 10^5, ABB.tol = 0.1, ABB.plot.it = FALSE, ABB.verbose = 0, ABB.maxits = 10, do.init = TRUE, truedenom=FALSE, ...)
x |
The time series for which you wish to have the estimate for. |
nz |
The time point at which you want the estimate computed at. This is an integer ranging from one up to the length of the time series. |
filter.number |
The analysis wavelet (the wavelet periodogram is computed using this to form the nondecimated wavelet coefficients) |
family |
The family of the analysis wavelet. |
smooth.dev |
The deviance function used in smoothing via the
internal call to the |
AutoReflect |
Whether better smoothing is to be obtained by
AutoReflection to mitigate the effects of using periodic
transforms on non-periodic data. See |
WPsmooth.type |
The type of wavelet periodogram smoothing. For here
leave the option at |
binwidth |
The running mean length. If zero then a good bandwidth
will be chosen using the |
mkcoefOBJ |
If this argument is missing then it is computed internally
using the |
ThePsiJ |
As for |
Cverbose |
This function called the C routine |
verbose |
If TRUE then debugging messages from the R code are produced. |
OPLENGTH |
Subsidiary parameters for potential call to
|
ABB.tol |
Tolerance to be passed to |
ABB.plot.it |
Argument to be passed to |
ABB.verbose |
Argument to be passed to |
ABB.maxits |
Argument to be passed to |
do.init |
Initialize stored statistics, for cache hit rate info. |
truedenom |
If TRUE use the actual number of terms in the sum as the denominator in the formula for the calculation of the covariance of the smoothed periodogram. If FALSE use the (2s+1) |
... |
Other arguments that are passed to the
|
First optionally computes a good bandwidth using the
AutoBestBW
function. Then
computes raw wavelet periodogram using ewspec3
using running mean smoothing with the binwidth
bandwith
(which might be automatically chosen). This computes the estimate
of the wavelet periodogram at time nz
. The covariance matrix
of this estimate is then computed in C using the
CstarIcov
function and this is returned.
A list with two components:
betahat |
A vector of length |
Sigma |
A matrix of dimensions |
Guy Nason
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Small example, not too computationally demanding on white noise # myb <- EstBetaCov(rnorm(64), nz=32) # # Let's see the results (of my run) # ## Not run: myb$betahat #[1] 0.8323344 0.7926963 0.7272328 1.3459313 2.1873395 0.8364632 # # For white noise, these values should be 1 (they're estimates) ## Not run: myb$Sigma # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 0.039355673 0.022886994 0.008980497 0.01146325 0.003211176 0.001064377 #[2,] 0.022886994 0.054363333 0.035228164 0.06519112 0.017146883 0.006079162 #[3,] 0.008980497 0.035228164 0.161340373 0.38326812 0.111068916 0.040068318 #[4,] 0.011463247 0.065191118 0.383268115 1.31229598 0.632725858 0.228574601 #[5,] 0.003211176 0.017146883 0.111068916 0.63272586 1.587765187 0.919247252 #[6,] 0.001064377 0.006079162 0.040068318 0.22857460 0.919247252 2.767615374 # # Here's an example for T (length of series) bigger, T=1024 # ## Not run: myb <- EstBetaCov(rnorm(1024), nz=512) # # Let's look at results # ## Not run: myb$betahat # [1] 1.0276157 1.0626069 0.9138419 1.1275545 1.4161028 0.9147333 1.1935089 # [8] 0.6598547 1.1355896 2.3374615 # # These values (especially for finer scales) are closer to 1 #
# # Small example, not too computationally demanding on white noise # myb <- EstBetaCov(rnorm(64), nz=32) # # Let's see the results (of my run) # ## Not run: myb$betahat #[1] 0.8323344 0.7926963 0.7272328 1.3459313 2.1873395 0.8364632 # # For white noise, these values should be 1 (they're estimates) ## Not run: myb$Sigma # [,1] [,2] [,3] [,4] [,5] [,6] #[1,] 0.039355673 0.022886994 0.008980497 0.01146325 0.003211176 0.001064377 #[2,] 0.022886994 0.054363333 0.035228164 0.06519112 0.017146883 0.006079162 #[3,] 0.008980497 0.035228164 0.161340373 0.38326812 0.111068916 0.040068318 #[4,] 0.011463247 0.065191118 0.383268115 1.31229598 0.632725858 0.228574601 #[5,] 0.003211176 0.017146883 0.111068916 0.63272586 1.587765187 0.919247252 #[6,] 0.001064377 0.006079162 0.040068318 0.22857460 0.919247252 2.767615374 # # Here's an example for T (length of series) bigger, T=1024 # ## Not run: myb <- EstBetaCov(rnorm(1024), nz=512) # # Let's look at results # ## Not run: myb$betahat # [1] 1.0276157 1.0626069 0.9138419 1.1275545 1.4161028 0.9147333 1.1935089 # [8] 0.6598547 1.1355896 2.3374615 # # These values (especially for finer scales) are closer to 1 #
This function is a development of the ewspec
function from wavethresh
but with more features.
The two new features are: the addition of running mean smoothing
and autoreflection which mitigates the problems caused in
ewspec
which performed periodic transforms on
data (time series) which were generally not periodic.
ewspec3(x, filter.number = 10, family = "DaubLeAsymm", UseLocalSpec = TRUE, DoSWT = TRUE, WPsmooth = TRUE, WPsmooth.type = "RM", binwidth = 5, verbose = FALSE, smooth.filter.number = 10, smooth.family = "DaubLeAsymm", smooth.levels = 3:WPwst$nlevels - 1, smooth.dev = madmad, smooth.policy = "LSuniversal", smooth.value = 0, smooth.by.level = FALSE, smooth.type = "soft", smooth.verbose = FALSE, smooth.cvtol = 0.01, smooth.cvnorm = l2norm, smooth.transform = I, smooth.inverse = I, AutoReflect = TRUE)
ewspec3(x, filter.number = 10, family = "DaubLeAsymm", UseLocalSpec = TRUE, DoSWT = TRUE, WPsmooth = TRUE, WPsmooth.type = "RM", binwidth = 5, verbose = FALSE, smooth.filter.number = 10, smooth.family = "DaubLeAsymm", smooth.levels = 3:WPwst$nlevels - 1, smooth.dev = madmad, smooth.policy = "LSuniversal", smooth.value = 0, smooth.by.level = FALSE, smooth.type = "soft", smooth.verbose = FALSE, smooth.cvtol = 0.01, smooth.cvnorm = l2norm, smooth.transform = I, smooth.inverse = I, AutoReflect = TRUE)
x |
The time series you want to compute the evolutionary wavelet spectrum for. |
filter.number |
Wavelet filter number underlying the analysis
of the spectrum (see |
family |
Wavelet family. Again, see |
UseLocalSpec |
As |
DoSWT |
As |
WPsmooth |
If |
WPsmooth.type |
The type of periodogram smoothing.
If this argument is |
binwidth |
If the periodogram smoothing is |
verbose |
If |
smooth.filter.number |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the index number of
wavelet to use, exactly as |
smooth.family |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the family of
wavelet to use, exactly as |
smooth.levels |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the levels to
smooth, exactly as |
smooth.dev |
If wavelet smoothing of the wavelet
periodogram is used then this specifies deviance used
to compute smoothing thresholds, exactly as |
smooth.policy |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the policy
of wavelet shrinkage to use, exactly as |
smooth.value |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the value of the
smoothing parameter for some policies, exactly as |
smooth.by.level |
If wavelet smoothing of the wavelet
periodogram is used then this specifies whether level-by-level
thresholding is applied, or one threshold is applied to
all levels, exactly as |
smooth.type |
If wavelet smoothing of the wavelet
periodogram is used then this specifies the type of
thresholding, "hard" or "soft", exactly as |
smooth.verbose |
If wavelet smoothing of the wavelet
periodogram is used then this specifies whether or not
verbose messages are produced during the smoothing,
exactly as |
smooth.cvtol |
If wavelet smoothing of the wavelet
periodogram is used then this specifies a tolerance
for the cross-validation algorithm if it is specified
in the |
smooth.cvnorm |
Ditto to the previous argument, but this one supplies the norm used by the cross-validation. |
smooth.transform |
If wavelet smoothing of the wavelet
periodogram is used then this specifies whether a transform
is used to transform the periodogram before smoothing,
exactly as |
smooth.inverse |
Should be the mathematical inverse of
the |
AutoReflect |
Whether the series is internally reflected before
application of the wavelet transforms. So, |
Precisely the same kind of output as ewspec
.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Generate time series # x <- tvar1sim() # # Compute its evolutionary wavelet spectrum, with linear running mean smooth # x.ewspec3 <- ewspec3(x) # # Plot the answer, probably its a bit variable, because the default bandwidth # is 5, which is probably inappropriate for many series # ## Not run: plot(x.ewspec3$S) # # Try a larger bandwidth # x.ewspec3 <- ewspec3(x, binwidth=100) # # Plot the answer, should look a lot smoother # # Note, a lot of high frequency power on the right hand side of the plot, # which is expected as process looks like AR(1) with param of -0.9 # ## Not run: plot(x.ewspec3$S) # # Do smoothing like ewspec (but additionally AutoReflect) # x.ewspec3 <- ewspec3(x, WPsmooth.type="wavelet") # # Plot the results # ## Not run: plot(x.ewspec3$S) # # Another possibility is to use AutoBestBW which tries to find the best # linear smooth closest to a wavelet smooth. This makes use of ewspec3 #
# # Generate time series # x <- tvar1sim() # # Compute its evolutionary wavelet spectrum, with linear running mean smooth # x.ewspec3 <- ewspec3(x) # # Plot the answer, probably its a bit variable, because the default bandwidth # is 5, which is probably inappropriate for many series # ## Not run: plot(x.ewspec3$S) # # Try a larger bandwidth # x.ewspec3 <- ewspec3(x, binwidth=100) # # Plot the answer, should look a lot smoother # # Note, a lot of high frequency power on the right hand side of the plot, # which is expected as process looks like AR(1) with param of -0.9 # ## Not run: plot(x.ewspec3$S) # # Do smoothing like ewspec (but additionally AutoReflect) # x.ewspec3 <- ewspec3(x, WPsmooth.type="wavelet") # # Plot the results # ## Not run: plot(x.ewspec3$S) # # Another possibility is to use AutoBestBW which tries to find the best # linear smooth closest to a wavelet smooth. This makes use of ewspec3 #
This function uses the special HwdS
function
to compute the Haar wavelet transform with out boundary
conditions (neither periodic, interval, mirror reflection).
This is so all coefficients are genuine Haar coefficients without
involving extra/repeated data.
ewspecHaarNonPer(x, filter.number = 1, family = "DaubExPhase", UseLocalSpec = TRUE, DoSWT = TRUE, WPsmooth = TRUE, verbose = FALSE, smooth.filter.number = 10, smooth.family = "DaubLeAsymm", smooth.levels = 3:WPwst$nlevels - 1, smooth.dev = madmad, smooth.policy = "LSuniversal", smooth.value = 0, smooth.by.level = FALSE, smooth.type = "soft", smooth.verbose = FALSE, smooth.cvtol = 0.01, smooth.cvnorm = l2norm, smooth.transform = I, smooth.inverse = I)
ewspecHaarNonPer(x, filter.number = 1, family = "DaubExPhase", UseLocalSpec = TRUE, DoSWT = TRUE, WPsmooth = TRUE, verbose = FALSE, smooth.filter.number = 10, smooth.family = "DaubLeAsymm", smooth.levels = 3:WPwst$nlevels - 1, smooth.dev = madmad, smooth.policy = "LSuniversal", smooth.value = 0, smooth.by.level = FALSE, smooth.type = "soft", smooth.verbose = FALSE, smooth.cvtol = 0.01, smooth.cvnorm = l2norm, smooth.transform = I, smooth.inverse = I)
x |
A vector of dyadic length that contains the time series you want to form the EWS of. |
filter.number |
Should always be 1 (for Haar) |
family |
Should always be "DaubExPhase", for Haar. |
UseLocalSpec |
Should always be |
DoSWT |
Should always be |
WPsmooth |
Should alway be |
verbose |
If |
smooth.filter.number |
Wavelet filter number for doing the wavelet smoothing of the EWS estimate. |
smooth.family |
Wavelet family for doing the wavelet smoothing of the EWS estimate. |
smooth.levels |
Which levels of the EWS estimate to apply smoothing to. |
smooth.dev |
What kind of deviance to use. The default is madmad, an alternative might be var. |
smooth.policy |
What kind of smoothing to use. See help
page for |
smooth.value |
If a manual value has to be supplied according
to the |
smooth.by.level |
If |
smooth.type |
The type of wavelet smoothing "hard" or "soft" |
smooth.verbose |
If |
smooth.cvtol |
If cross-validation smoothing is used, this is the tolerance |
smooth.cvnorm |
If cross-validation smoothing used, this is the norm that's used |
smooth.transform |
A transform is applied before smoothing |
smooth.inverse |
The inverse transform is applied after smoothing |
This function is very similar
to ewspec
from wavethresh, and many arguments here perform
the same function as there.
The same value as for the ewspec
function.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Requires wavethresh, so not run directly in installation of package # ewspecHaarNonPer(rnorm(512))
# # Requires wavethresh, so not run directly in installation of package # ewspecHaarNonPer(rnorm(512))
Replaces all NAs in vector by 0
getridofendNA(x)
getridofendNA(x)
x |
Vector that might contain NAs |
Originally, this function did something more complex, but now it merely replaces NAs by 0
The same vector as x
but with NAs replaced by 0
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # # x <- c(3, 4, 6, NA, 3) getridofendNA(x) #[1] 3 4 6 0 3
# # # x <- c(3, 4, 6, NA, 3) getridofendNA(x) #[1] 3 4 6 0 3
Function uses the filter
function to achieve its aims.
HwdS(x)
HwdS(x)
x |
A vector of dyadic length that you wish to transform. |
The regular wd
function that can compute the non-decimated
transform uses different kinds of boundary conditions, which can
result in coefficients being used multiply for consideration in
a test of stationarity, and distort results. This function
only computes Haar coefficients on the data it can, without
wrapround.
An object of class wd
which contains the nondecimated
Haar transform of the input series, x
without periodic
boundary conditions (nor interval, nor reflection).
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
ewspecHaarNonPer
,
getridofendNA
# # Apply Haar transform to Gaussian data # HwdS(rnorm(32)) #Class 'wd' : Discrete Wavelet Transform Object: # ~~ : List with 8 components with names # C D nlevels fl.dbase filter type bc date # #$C and $D are LONG coefficient vectors # #Created on : Tue Jul 17 15:14:59 2012 #Type of decomposition: station # #summary(.): #---------- #Levels: 5 #Length of original: 32 #Filter was: Haar wavelet #Boundary handling: periodic #Transform type: station #Date: Tue Jul 17 15:14:59 2012
# # Apply Haar transform to Gaussian data # HwdS(rnorm(32)) #Class 'wd' : Discrete Wavelet Transform Object: # ~~ : List with 8 components with names # C D nlevels fl.dbase filter type bc date # #$C and $D are LONG coefficient vectors # #Created on : Tue Jul 17 15:14:59 2012 #Type of decomposition: station # #summary(.): #---------- #Levels: 5 #Length of original: 32 #Filter was: Haar wavelet #Boundary handling: periodic #Transform type: station #Date: Tue Jul 17 15:14:59 2012
Function computes Haar wavelet and scaling function coefficients for data set of any length. Algorithm computes every possible coefficient that it can for both decimated and nondecimated versions of the transform.
hwt(x, type = c("wavelet", "station"), reindex = FALSE)
hwt(x, type = c("wavelet", "station"), reindex = FALSE)
x |
A vector of length n, where n is a positive integer. This is the data that you wish to compute the Haar wavelet transform for. |
type |
The type of transform, either the decimated or nondecimated algorithm. |
reindex |
If TRUE then the routine attempts to match scales
with the usual dyadic transform, |
Essentially, this algorithm attempts to compute every
possible Haar wavelet coefficient. For example, if the length
of the input series was 6 then this means that three coefficients
at the finest scale can be computed using the first, second and
third pair of input data points using the weights
c(1, -1)/sqrt(2)
. However, from the three coefficients
that result from this, there is only one pair, so only one
"next coarser" coefficient can be computed.
The reindex
option is subtle. Essentially, it tries to
ensure that the returned coefficients end up at the same
scales as if a data set of the next highest dyadic length was
analyzed by the wd function. E.g. if the length of the
series was 10 then with reindex=FALSE
(default)
only three levels are returned for each of the wavelet and
scaling coefficients. If reindex=TRUE
then the number
of levels returned would be as if wd
analysed a data set
of length 16 (the smallest dyadic number larger than 10).
The wd levels would be zero to three and this is what
would be returned in this function if reindex=TRUE
.
However, note, in this case, the coarsest level coefficient
happens to be NULL (or not computable). One can view the algorithm
as computing a partial transform of 10 of the 16 elements and
substituting NA for anything it can't compute.
An object of class hwtANYN which is a list with the following components.
c |
The scaling function coefficients. This is a list of length
|
d |
A for |
nlevels |
The number of scale levels in the Haar wavelet decomposition.
if |
type |
Whether a decimated wavelet transform has been computed
( |
reindex |
Either |
G. P. Nason
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
Priestley, M.B. and Subba Rao (1969) A test for non-stationarity of time series. J. R. Statist. Soc. B, 31, 140-149.
von Sachs, R. and Neumann, M.H. (2000) A wavelet-based test for stationarity. J. Time Ser. Anal., 21, 597-613.
hwtos
,
plot.hwtANYN
, print.hwtANYN
,
summary.hwtANYN
# # Generate test data set of length 5 (note, NOT a power of two) # v2 <- rnorm(5) # # Compute its Haar transform # v2hwt <- hwt(v2) # # How many levels does it have? # nlevelsWT(v2hwt) # # What are the coarsest scale wavelet coefficients # v2hwt$d[[1]] # # What are the finest scale scaling function coefficients # v2hwt$c[[nlevels(v2hwt$c)-1]]
# # Generate test data set of length 5 (note, NOT a power of two) # v2 <- rnorm(5) # # Compute its Haar transform # v2hwt <- hwt(v2) # # How many levels does it have? # nlevelsWT(v2hwt) # # What are the coarsest scale wavelet coefficients # v2hwt$d[[1]] # # What are the finest scale scaling function coefficients # v2hwt$c[[nlevels(v2hwt$c)-1]]
NOTE: CURRENTLY THIS FUNCTION IS NOT INCLUDED IN THE PACKAGE.
USE hwtos2. This function computes the raw wavelet periodogram of the
arbitrary time series vector x
. The periodogram is then
subject to a hypothesis test to see if its expectation over time,
for different scales, is constant. The constancy test is carried out
using tests on its Haar wavelet coefficients. The overall test is
for second-order stationarity (e.g. constant variance, constant
acf function, mean is assumed zero).
hwtos(x, alpha = 0.05, lowlev = 1, WTscale = NULL, maxSD = NULL, verbose = FALSE, silent = FALSE, UseCForVarip2 = TRUE, OPLENGTH = 1e+05, mc.method = p.adjust.methods)
hwtos(x, alpha = 0.05, lowlev = 1, WTscale = NULL, maxSD = NULL, verbose = FALSE, silent = FALSE, UseCForVarip2 = TRUE, OPLENGTH = 1e+05, mc.method = p.adjust.methods)
x |
The time series you wish to test for second-order stationarity.
Minimum length series that this function will operate for is 20.
However, for short series the power of the test might not be good
and could be investigated via simulation that reflect your particular
circumstances.
This should be a stochastic series. The function
will report an error if |
alpha |
The (nominal) size of the hypothesis test. |
lowlev |
Controls the lowest scale of the wavelet periodogram that gets analyzed. Generally, leave this parameter alone. |
WTscale |
Controls the finest scale of the Haar wavelet transform of a particular wavelet periodogram scale. Generally, we have to stay away from the finest Haar wavelet transform scales of the periodogram as the test relies on a central limit theorem effect which only "kicks in" when the Haar wavelet scale is medium-to-coarse. Generally, leave this argument alone. |
maxSD |
Parameter which controls which scales go towards overall variance calculation. Generally, leave alone. |
verbose |
If |
silent |
If |
UseCForVarip2 |
If |
OPLENGTH |
Some of the internal functions require workspace to perform their calculations. In exceptional circumstances more static workspace might be required and so this argument might need to be higher than the default. However, the code will tell you how high this number will need to be. The code can, with default arguments, handle series that are up to 30000 in length. However, at 35000 the OPLENGTH parameter will need to be increased. |
mc.method |
Method to control overall size for test taking into
account multiple comparisons. The default argument is
|
This function computes all possible Haar wavelet coefficients
of the time series x
. Then, squares those to obtain the
raw wavelet periodogram. Then the test of stationarity works
by taking each level of the raw wavelet periodogram and subjecting
it to another (decimated) Haar wavelet transform and then assessing
whether any of those coefficients is significantly different to
zero. It does this by using a Gaussian approximation first
introduced by Neumann and von Sachs (2000). This is a multiple
testing problem: many individual wavelet coefficients need to
be assessed simultaneously and the user can choose the type of
assessment using the mc.method
argument.
An object of class tosANYN
. This is a list containing the
following components.
nreject |
The number of wavelet coefficients that reject the null hypothesis of being zero. |
mc.method |
The multiple comparison method used. |
AllTS |
All the t-statistics. This is a list containing J levels,
where J is the number of periodogram levels. Each slot in
the |
AllPVal |
As |
alpha |
The size of the test |
x |
The time series that was analyzed |
xSD |
The estimated mean spectrum value for each level of the spectrum, mean over time that is. |
allTS |
A vector containing all of the test statistics. So,
the information in |
allpvals |
As |
allbigscale |
The wavelet periodogram scale associated with each
t-statistic in |
alllitscale |
As for |
allindex |
As for |
alllv |
The maximum number of wavelet coefficients in a particular Haar wavelet scale of a particular scale of the wavelet periodogram. Note, this information is useful because the wavelet transforms are computed on arbitrary length objects and so keeping track of the number of coefficients per scale is useful later, e.g. for plotting purposes. This information is not required in the dyadic case because the coefficient vector lengths are completely predictable. |
allpvals.unadjust |
A vector of p-values that has not been adjusted by a multiple hypothesis test technique. |
G. P. Nason
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
Priestley, M.B. and Subba Rao (1969) A test for non-stationarity of time series. J. R. Statist. Soc. B, 31, 140-149.
von Sachs, R. and Neumann, M.H. (2000) A wavelet-based test for stationarity. J. Time Ser. Anal., 21, 597-613.
link{hwt}
,
hwtos2
,
plot.tosANYN
,
print.tosANYN
,
summary.tosANYN
# # Generate test data set of non-dyadic length # v3 <- rnorm(300) # # Run the test of stationarity # ## Not run: v3.TOS <- hwtos(v3) # #Scales get printed #8 7 6 5 4 3 2 # ## Not run: print(v3.TOS) #Class 'tosANYN' : Stationarity Object for Arbitrary Length Data : # ~~~~~~~ : List with 14 components with names # nreject mc.method AllTS AllPVal alpha x xSD allTS # allpvals allbigscale alllitscale allindex alllv # allpvals.unadjust # # #summary(.): #---------- #There are 54 hypothesis tests altogether #There were 0 reject(s) #P-val adjustment method was: holm # # Note, nothing got rejected. So accept the H_0 null hypothesis of stationarity. # This is precisely what you'd expect operating on iid Gaussians. # # Let's construct obvious example of non-stationarity. # v4 <- c(rnorm(150), rnorm(150,sd=3)) # # I.e. v4 has sharp variance change halfway along # Now compute test of stationarity # ## Not run: v4.TOS <- hwtos(v4) # # Print out results # ## Not run: print(v4.TOS) # #Class 'tosANYN' : Stationarity Object for Arbitrary Length Data : # ~~~~~~~ : List with 14 components with names # nreject mc.method AllTS AllPVal alpha x xSD allTS # allpvals allbigscale alllitscale allindex alllv # allpvals.unadjust # # #summary(.): #---------- #There are 54 hypothesis tests altogether #There were 5 reject(s) #P-val adjustment method was: holm #Listing rejects... #P: 7 HWTlev: 2 Max Poss Ix: 2 Indices: 2 #P: 7 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 6 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 5 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 4 HWTlev: 1 Max Poss Ix: 1 Indices: 1
# # Generate test data set of non-dyadic length # v3 <- rnorm(300) # # Run the test of stationarity # ## Not run: v3.TOS <- hwtos(v3) # #Scales get printed #8 7 6 5 4 3 2 # ## Not run: print(v3.TOS) #Class 'tosANYN' : Stationarity Object for Arbitrary Length Data : # ~~~~~~~ : List with 14 components with names # nreject mc.method AllTS AllPVal alpha x xSD allTS # allpvals allbigscale alllitscale allindex alllv # allpvals.unadjust # # #summary(.): #---------- #There are 54 hypothesis tests altogether #There were 0 reject(s) #P-val adjustment method was: holm # # Note, nothing got rejected. So accept the H_0 null hypothesis of stationarity. # This is precisely what you'd expect operating on iid Gaussians. # # Let's construct obvious example of non-stationarity. # v4 <- c(rnorm(150), rnorm(150,sd=3)) # # I.e. v4 has sharp variance change halfway along # Now compute test of stationarity # ## Not run: v4.TOS <- hwtos(v4) # # Print out results # ## Not run: print(v4.TOS) # #Class 'tosANYN' : Stationarity Object for Arbitrary Length Data : # ~~~~~~~ : List with 14 components with names # nreject mc.method AllTS AllPVal alpha x xSD allTS # allpvals allbigscale alllitscale allindex alllv # allpvals.unadjust # # #summary(.): #---------- #There are 54 hypothesis tests altogether #There were 5 reject(s) #P-val adjustment method was: holm #Listing rejects... #P: 7 HWTlev: 2 Max Poss Ix: 2 Indices: 2 #P: 7 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 6 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 5 HWTlev: 1 Max Poss Ix: 1 Indices: 1 #P: 4 HWTlev: 1 Max Poss Ix: 1 Indices: 1
The main function to perform a test of second-order stationarity as outlined in Nason (2012). Essentially, this routine computes an evolutionary wavelet spectral estimate and then computes the Haar wavelet coefficients of each scale of the spectral estimate. Any large Haar coefficients are indicative of nonstationarity. A multiple hypothesis test assesses whether any of the Haar coefficients are large enough to reject the null hypothesis of stationarity.
hwtos2(x, alpha = 0.05, filter.number = 1, family = "DaubExPhase", lowlev = 3, WTscale = NULL, maxSD = NULL, verbose = FALSE, silent = FALSE, UseCForVarip2 = TRUE, OPLENGTH = 1e+05)
hwtos2(x, alpha = 0.05, filter.number = 1, family = "DaubExPhase", lowlev = 3, WTscale = NULL, maxSD = NULL, verbose = FALSE, silent = FALSE, UseCForVarip2 = TRUE, OPLENGTH = 1e+05)
x |
The time series you want to test for second order
stationarity. This should be a stochastic series. The function
will report an error if |
alpha |
The overall (nominal) size of the test. |
filter.number |
The index number of the wavelet used to compute the evolutionary spectral estimate with. |
family |
The family of wavelet used to compute the evolutionary spectral estimate. |
lowlev |
Do not compute Haar wavelet coefficients on
evolutionary wavelet spectra at level lower than |
WTscale |
The theory of the test shows that the Haar wavelet
coefficients of the raw wavelet periodogram are asymptotically
normal as long as the scale of the Haar wavelet is
‘coarse’ enough. Roughly, speaking |
maxSD |
As part of its execution, this function computes an
evolutionary wavelet spectral estimate from the time series.
Since the test is based on the assumption of stationarity, the
EWS is averaged over time. There will be |
verbose |
If |
silent |
If |
UseCForVarip2 |
If |
OPLENGTH |
The |
This function looks at the Haar wavelet coefficients of an evolutionary wavelet spectrum. This is a modification of the principle of von Sachs and Neumann (2000) which worked with the Haar wavelet coefficients of a local Fourier spectrum.
See also, the stationarity
test which implements
the Priestley-Subba Rao (1969) test. This function
is contained in the fractal
package.
An object of class tos
, a list containing the following
components:
nreject |
The number of FDR rejections |
rejpval |
The p-value associated with FDR rejections |
spvals |
A vector of p-values from all of the tests, sorted in ascending order. |
sTS |
A vector of sorted test statistics from all of the tests,
sorted into the same order as |
AllTS |
A list containing all of the test statistics.
The first entry contains test statistics corresponding
to the coarsest scale, the last entry corresponds to the
finest scale. Each component in the list is either empty
(because the scale was omitted because it was less than
|
AllPVal |
As |
alpha |
The nominal size of the overall hypothesis test. |
x |
The original time series that was analyzed |
xSD |
A vector containing |
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
Priestley, M.B. and Subba Rao (1969) A test for non-stationarity of time series. J. R. Statist. Soc. B, 31, 140-149.
von Sachs, R. and Neumann, M.H. (2000) A wavelet-based test for stationarity. J. Time Ser. Anal., 21, 597-613.
varip2
, stationarity
# # First, test a set of iid Gaussians: should be stationary! # hwtos2(rnorm(256)) # 8 7 6 5 4 3 #Class 'tos' : Stationarity Object : # ~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 186 hypothesis tests altogether #There were 0 FDR rejects #No p-values were smaller than the FDR val of: #Using Bonferroni rejection p-value is 0.0002688172 #And there would be 0 rejections. # # NOTE: the summary indicates that nothing was rejected: hence stationary! # # Second, example. Concatenated Gaussians with different variances # hwtos2(c(rnorm(256), rnorm(256,sd=2))) # 9 8 7 6 5 4 3 #Class 'tos' : Stationarity Object : # ~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 441 hypothesis tests altogether #There were 5 FDR rejects #The rejection p-value was 3.311237e-06 #Using Bonferroni rejection p-value is 0.0001133787 #And there would be 5 rejections. #Listing FDR rejects... (thanks Y&Y!) #P: 5 HWTlev: 0 indices on next line...[1] 1 #P: 6 HWTlev: 0 indices on next line...[1] 1 #P: 7 HWTlev: 0 indices on next line...[1] 1 #P: 8 HWTlev: 0 indices on next line...[1] 1 #P: 9 HWTlev: 0 indices on next line...[1] 1 # # NOTE: This time 5 Haar wavelet coefficients got rejected: hence series # is not stationary.
# # First, test a set of iid Gaussians: should be stationary! # hwtos2(rnorm(256)) # 8 7 6 5 4 3 #Class 'tos' : Stationarity Object : # ~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 186 hypothesis tests altogether #There were 0 FDR rejects #No p-values were smaller than the FDR val of: #Using Bonferroni rejection p-value is 0.0002688172 #And there would be 0 rejections. # # NOTE: the summary indicates that nothing was rejected: hence stationary! # # Second, example. Concatenated Gaussians with different variances # hwtos2(c(rnorm(256), rnorm(256,sd=2))) # 9 8 7 6 5 4 3 #Class 'tos' : Stationarity Object : # ~~~~ : List with 9 components with names # nreject rejpval spvals sTS AllTS AllPVal alpha x xSD # # #summary(.): #---------- #There are 441 hypothesis tests altogether #There were 5 FDR rejects #The rejection p-value was 3.311237e-06 #Using Bonferroni rejection p-value is 0.0001133787 #And there would be 5 rejections. #Listing FDR rejects... (thanks Y&Y!) #P: 5 HWTlev: 0 indices on next line...[1] 1 #P: 6 HWTlev: 0 indices on next line...[1] 1 #P: 7 HWTlev: 0 indices on next line...[1] 1 #P: 8 HWTlev: 0 indices on next line...[1] 1 #P: 9 HWTlev: 0 indices on next line...[1] 1 # # NOTE: This time 5 Haar wavelet coefficients got rejected: hence series # is not stationary.
Return the index of the last zero in a vector, otherwise
stop and return errror message. A helper routine for
mkcoef
.
idlastzero(v)
idlastzero(v)
v |
Vector you wish to investigate |
The index within v
of the last (right-most or one with
the largest index) zero.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
idlastzero(c(3,4,5,0,9)) #[1] 4
idlastzero(c(3,4,5,0,9)) #[1] 4
Compute localized autocovariance function for nonstationary
time series. Note: this function is borrowed from the costat
package, and modified to have linear smoothing, and when that package is complete, it will be removed
from this package.
lacf(x, filter.number = 10, family = "DaubLeAsymm", smooth.dev = var, AutoReflect = TRUE, lag.max = NULL, WPsmooth.type = "RM", binwidth, tol=0.1, maxits=5, ABBverbose=0, verbose=FALSE, ...)
lacf(x, filter.number = 10, family = "DaubLeAsymm", smooth.dev = var, AutoReflect = TRUE, lag.max = NULL, WPsmooth.type = "RM", binwidth, tol=0.1, maxits=5, ABBverbose=0, verbose=FALSE, ...)
x |
The time series you wish to analyze |
filter.number |
Wavelet filter number you wish to use to
analyse the time series (to form the wavelet periodogram, etc)
See |
family |
Wavelet family to use, see |
smooth.dev |
Change variance estimate for smoothing. Note: |
AutoReflect |
If |
lag.max |
The maximum lag of acf required. If NULL then the
same default as in the regular |
WPsmooth.type |
The type of smoothing used to produce the
estimate. See |
binwidth |
If necessary, the |
tol |
Tolerance argument for |
maxits |
Maximum iterations argument for |
ABBverbose |
Verbosity of execution of |
verbose |
If |
... |
Other arguments for |
In essence, this routine is fairly simple. First, the EWS of the time series is computed. Then formula (14) from Nason, von Sachs and Kroisandr (2000) is applied to obtain the time-localized autocovariance from the spectral estimate.
An object of class lacf
which contains the
autocovariance. This object can be handled by functions
from the costat
package. The idea in this package
is that the function gets used internally and much of the
same functionality can be achieved by running
Rvarlacf
and plot.lacfCI
. However,
running lacf
on its own is much faster than
Rvarlacf
as the CI computation is intenstive.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
Nason, G.P., von Sachs, R. and Kroisandt, G. (2000) Wavelet processes and adaptive estimation of the evolutionary wavelet spectrum. J. R. Statist. Soc. Ser B, 62, 271-292.
# # With wavethresh attached, note binwidth is fabricated here, # just to make the example work. The lacf implementation in # the costat package performs wavelet (ie maybe better) smoothing automatically # v <- lacf(rnorm(256), binwidth=40) # # With costat attached also # ## Not run: plot(v)
# # With wavethresh attached, note binwidth is fabricated here, # just to make the example work. The lacf implementation in # the costat package performs wavelet (ie maybe better) smoothing automatically # v <- lacf(rnorm(256), binwidth=40) # # With costat attached also # ## Not run: plot(v)
Computes a variance estimate for hwtos2
Merely takes a wavelet periodogram (actually wd
class
object), and a level argument. Then extracts the wavelet periodogram
coefficients at that level and returns twice the mean of their
squares.
littlevar(WP, ll)
littlevar(WP, ll)
WP |
The wavelet periodogram that you wish to analyze (actually
a |
ll |
A valid level for the periodogram |
Twice the mean of the square of the coefficients at the level extracted.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Not intended for direct user use #
# # Not intended for direct user use #
For a given wavelet computes a list with each entry of the list containing that discrete wavelet at a different scale. The first entry corresponds to the finest wavelet, the next entry to the next finest, and so on.
mkcoef(J, filter.number = 10, family = "DaubLeAsymm")
mkcoef(J, filter.number = 10, family = "DaubLeAsymm")
J |
A NEGATIVE integer. -J is the maximum number of levels to compute. |
filter.number |
The filter number (number of vanishing moments) of the underlying wavelet to use. |
family |
The family of the wavelet. See |
A list of length J. The first entry contains the discrete wavelet at the finest scale, the 2nd entry contains the next most finest wavelet, and so on.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # E.g. compute discrete Haar wavelets on scales 1, 2, 3. # mkcoef(-3, 1, "DaubExPhase") #[[1]] #[1] 0.7071068 -0.7071068 # #[[2]] #[1] 0.5 0.5 -0.5 -0.5 # #[[3]] #[1] 0.3535534 0.3535534 0.3535534 0.3535534 -0.3535534 -0.3535534 -0.3535534 #[8] -0.3535534
# # E.g. compute discrete Haar wavelets on scales 1, 2, 3. # mkcoef(-3, 1, "DaubExPhase") #[[1]] #[1] 0.7071068 -0.7071068 # #[[2]] #[1] 0.5 0.5 -0.5 -0.5 # #[[3]] #[1] 0.3535534 0.3535534 0.3535534 0.3535534 -0.3535534 -0.3535534 -0.3535534 #[8] -0.3535534
hwtANYN
object.
An hwtANYN
object contains the results of a Haar
wavelet transform computed on an object of non-dyadic length.
It is the equivalent of the wd
object for non-dyadic
vectors for Haar wavelets. Note, the plot can only be carried
out where the reindex
slot of the object is TRUE
.
## S3 method for class 'hwtANYN' plot(x, xlabvals, xlabchars, ylabchars, first.level = 1, main = "Haar Wavelet Coefficients", scaling = c("global", "by.level"), rhlab = FALSE, sub, NotPlotVal = 0.005, xlab = "Translate", ylab = "wd-equivalent Resolution Level", miss.coef.col = 2, miss.coef.cex = 0.5, miss.coef.pch = 2, ...)
## S3 method for class 'hwtANYN' plot(x, xlabvals, xlabchars, ylabchars, first.level = 1, main = "Haar Wavelet Coefficients", scaling = c("global", "by.level"), rhlab = FALSE, sub, NotPlotVal = 0.005, xlab = "Translate", ylab = "wd-equivalent Resolution Level", miss.coef.col = 2, miss.coef.cex = 0.5, miss.coef.pch = 2, ...)
x |
The |
xlabvals |
Coordinates of x-axis labels you wish to add. |
xlabchars |
Labels to be printed at the x-axis labels specified. |
ylabchars |
Y-axis labels |
first.level |
Specifies the coarsest level to be plotted. |
main |
Specify a different main title for the plot. |
scaling |
How coefficients will be scaled on the plot.
This can be two arguments |
rhlab |
If |
sub |
Specify a different subtitle for the plot. |
NotPlotVal |
Coefficients will not be plotted if their scaled
height is less than |
xlab |
Specify the x-axis label. |
ylab |
Specify the y-axis label. |
miss.coef.col |
What color to plot "missing coefficients" in. |
miss.coef.cex |
How big to plot the "missing coefficients" symbol. |
miss.coef.pch |
The type of plotting character used to plot the "missing coefficients". |
... |
Other arguments to plot. |
A plot of the different wavelet coefficients at the scales
ranging from first.level
to the finest scale. Note, in this
plot the coefficients are NOT aligned with time at different
scales in the same way as in the wd
type plot
- except the finest scale.
The Haar wavelet transform objects that this function plots are obtained originally from vectors of non-dyadic length. One can think of such a vector as a sub-vector of a longer vector of dyadic length. E.g. if your vector is of length 35 then it is a sub-vector of a vector of 64 (the next highest power of two). So, you can think of the Haar wavelet transform being of a vector of length 64 where 64-35=29 of the observations are missing. These missing observations "contribute" to wavelet (and scaling function) coefficients that are missing. This function has the ability to plot the "missing" coefficients, by default as small red triangles. The user can control the colour, size and plotting character of the missing observations.
A single vector of length the number of levels plotted containing the value of the maximum absolute coefficient value.
G. P. Nason
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
Priestley, M.B. and Subba Rao (1969) A test for non-stationarity of time series. J. R. Statist. Soc. B, 31, 140-149.
von Sachs, R. and Neumann, M.H. (2000) A wavelet-based test for stationarity. J. Time Ser. Anal., 21, 597-613.
# # Generate test data of length 82 # v3 <- rnorm(82) # # Compute Haar wavelet transform, note reindex has to be true for subsequent # plot. # v3.hwt <- hwt(v3, reindex=TRUE) # # ## Not run: plot(v3.hwt)
# # Generate test data of length 82 # v3 <- rnorm(82) # # Compute Haar wavelet transform, note reindex has to be true for subsequent # plot. # v3.hwt <- hwt(v3, reindex=TRUE) # # ## Not run: plot(v3.hwt)
Produces various ways of looking at a localized autocovariance (lacf) object.
## S3 method for class 'lacf' plot(x, plotcor = TRUE, type = "line", lags = 0:min(as.integer(10 * log10(nrow(x$lacf))), ncol(x$lacf) - 1), tcex = 1, lcol = 1, llty = 1, the.time = NULL, plot.it=TRUE, xlab, ylab, ...)
## S3 method for class 'lacf' plot(x, plotcor = TRUE, type = "line", lags = 0:min(as.integer(10 * log10(nrow(x$lacf))), ncol(x$lacf) - 1), tcex = 1, lcol = 1, llty = 1, the.time = NULL, plot.it=TRUE, xlab, ylab, ...)
x |
The localized autocovariance object you want to plot (lacf) |
plotcor |
If TRUE then plot autocorrelations, otherwise plot autocovariances. |
type |
The lacf objects are fairly complex and so there are
different ways you can plot them. The |
lags |
The |
tcex |
In the |
lcol |
Controls the colours of the lines in the |
llty |
Controls the line types of the lines in the |
the.time |
If the |
plot.it |
If |
xlab |
X-axis label, constructed internally if not supplied |
ylab |
Y-axis label, constructed internally if not supplied |
... |
Other arguments to plot. |
This function produces pictures of the
two-dimensional time-varying autocovariance
or autocorrelation, ,
of a locally stationary time series.
There are three types of plot depending on the argument to
the
type
argument.
The line
plot draws the autocorrelations as a series of
lines, one for each lag, as lines over time. E.g. a sequence
#of lines is drawn, one for each
.
The zeroth lag line is the autocorrelation at lag 0 which is
always 1. By default all the lags are drawn which can result
in a confusing picture. Often, one is only interested in the low
level lags, so only these can be plotted by changing the
lags
argument and any selection of lags can be plotted. The colour
and line type of the plotted lines can be changed with the
lcol
and the llty
arguments.
The acf
plot produces pictures similar to the standard
R acf()
function plot. However, the regular acf is a
1D function, since it is defined to be constant over all time.
The time-varying acf supplied to this function is not constant
over all time (except for stationary processes, theoretically).
So, this type of plot requires the user to specify a fixed
time at which to produce the plot, and this is supplied by
the the.time
argument.
The persp
plot plots the 2D function
as a perspective plot.
For the acf
type plot the acf values are returned
invisibly. For the other types nothing is returned.
G.P. Nason
Cardinali, A. and Nason, G.P. (2012) Costationarity of Locally
Stationary Time Series using costat
.
Cardinali, A. and Nason, G.P. (2010) Costationarity of locally stationary time series. J. Time Series Econometrics, 2, Issue 2, Article 1.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=30) # # Now let's do some plotting of the localized autocovariance # ## Not run: plot(vlacf, lags=0:6) # # Should get a plot where lag 0 is all up at value 1, and all other # autocorrelations are near zero (since its white noise). # # # How about just looking at lags 0, 2 and 4, and some different colours. # ## Not run: plot(vlacf, lags=c(0,2,4), lcol=c(1,2,3)) # # O.k. Let's concentrate on time t=200, let's look at a standard acf # plot near there. # ## Not run: plot(vlacf, type="acf", the.time=200) # # Now plot the autocovariance, rather than the autocorrelation. # ## Not run: plot(vlacf, type="acf", the.time=200, plotcor=FALSE) # # Actually, the plot doesn't look a lot different as the series is white # noise, but it is different if you look closely.
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=30) # # Now let's do some plotting of the localized autocovariance # ## Not run: plot(vlacf, lags=0:6) # # Should get a plot where lag 0 is all up at value 1, and all other # autocorrelations are near zero (since its white noise). # # # How about just looking at lags 0, 2 and 4, and some different colours. # ## Not run: plot(vlacf, lags=c(0,2,4), lcol=c(1,2,3)) # # O.k. Let's concentrate on time t=200, let's look at a standard acf # plot near there. # ## Not run: plot(vlacf, type="acf", the.time=200) # # Now plot the autocovariance, rather than the autocorrelation. # ## Not run: plot(vlacf, type="acf", the.time=200, plotcor=FALSE) # # Actually, the plot doesn't look a lot different as the series is white # noise, but it is different if you look closely.
Plot the localized autocovariance and approximate confidence intervals.
## S3 method for class 'lacfCI' plot(x, plotcor = TRUE, type = "line", lags = 0:as.integer(10 * log10(nrow(x$lacf))), tcex = 1, lcol = 1, llty = 1, ylim = NULL, segwid = 1, segandcross = TRUE, conf.level = 0.95, plot.it = TRUE, xlab, ylab, sub, ...)
## S3 method for class 'lacfCI' plot(x, plotcor = TRUE, type = "line", lags = 0:as.integer(10 * log10(nrow(x$lacf))), tcex = 1, lcol = 1, llty = 1, ylim = NULL, segwid = 1, segandcross = TRUE, conf.level = 0.95, plot.it = TRUE, xlab, ylab, sub, ...)
x |
The |
plotcor |
If |
type |
This can be one of three values |
lags |
The lags that you wish to display. This should be a list of non-negative integers, but not necessarily consecutive. |
tcex |
On the |
lcol |
On the |
llty |
As |
ylim |
The vertical limits of the plot. |
segwid |
On the |
segandcross |
If |
conf.level |
The confidence level of the confidence intervals. |
plot.it |
If |
xlab |
X-axis label, constructed internally if not supplied |
ylab |
Y-axis label, constructed internally if not supplied |
sub |
A subtitle for the plot |
... |
Other arguments to the main |
This function can plot the localized autocovariance in
three ways. Like a regular acf plot (but obviously a slice
out of a time-varying autocovariance, not the regular acf),
a line plot which shows the acfs over time and a perspective
plot which can plot the estimate of as a
2D function. Currently, the confidence intervals can only
be displayed on the
"acf"
type plot.
A vector of the extracted acfvals invisibly returned.
Note: what is returned depends on the arguments, what is
returned is what would have been plotted if plot.it
were TRUE
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Simulate a TVAR(1) process # x <- tvar1sim() # # Computes its time-localized autocovariance and confidence intervals # Note: smoothing is done automatically! # x.lacf <- Rvarlacf(x=x, nz=50, var.lag.max=20) # # Now plot this, plot covariances as an acf plot, with the CIs # ## Not run: plot(x.lacf, type="acf", plotcor=FALSE) # # Now plot it as a line plot, as correlations and can't do CIs # ## Not run: plot(x.lacf)
# # Simulate a TVAR(1) process # x <- tvar1sim() # # Computes its time-localized autocovariance and confidence intervals # Note: smoothing is done automatically! # x.lacf <- Rvarlacf(x=x, nz=50, var.lag.max=20) # # Now plot this, plot covariances as an acf plot, with the CIs # ## Not run: plot(x.lacf, type="acf", plotcor=FALSE) # # Now plot it as a line plot, as correlations and can't do CIs # ## Not run: plot(x.lacf)
tos
object.
After a test of stationarity for dyadic data
(e.g. hwtos2
)
is applied to a time series it generates a results object of
class tos
. This function takes objects of that
class and produces a graphical representation of the test.
## S3 method for class 'tos' plot(x, mctype = "FDR", sub = NULL, xlab = "Time", arrow.length = 0.05, verbose = FALSE, ...)
## S3 method for class 'tos' plot(x, mctype = "FDR", sub = NULL, xlab = "Time", arrow.length = 0.05, verbose = FALSE, ...)
x |
The |
mctype |
Whether you wish to see rejections (if they exist)
according to a Bonferroni assessment ( |
sub |
An argument to change the subtitle. |
xlab |
An argument to change the x-axis label. |
arrow.length |
The length of the edges of the arrow
head (in inches). Note that this is the argument that is
supplied as the |
verbose |
If |
... |
Other arguments to the main |
The following things are usually plotted. 1. The time series that was investigated. The left-hand axes is that for the time series. The horizontal axis is time (but just integers indexing). If the series was deemed stationary by the test then that's it except that the subtitle indicates that no Haar wavelet coefficients were rejected as being nonzero.
If the test indicated that the series was nonstationary then
the subtitle indicates this by stating the number of rejections
(this might be according to FDR or Bonferroni depending on
the setting of the mctype
argument. Then graphical
representations of any significant Haar wavelet coefficients
are plotted as double-headed red horizontal arrows on the plot.
The horizontal extent corresponds to the support of the underlying
wavelet. The vertical position of the arrows gives an indication
of the wavelet periodogram scale where the significant coefficient
was found. The wavelet periodogram scales are indexed by the right
hand axis, and beware, the numbers might not be consecutive, but
they will be ordered (so e.g. if no signficant coefficients were
discovered at wavelet periodogram scale level 6, then that scale/axis
label will not appear). The scale within the Haar wavelet transform
is indicated by the vertical position WITHIN ticks between
wavelet periodogram scales (ie, there are TWO scales: the wavelet
periodogram scale that is currently being analyzed, and the
Haar wavelet transform scale within the periodogram scale).
So, if two right hand axis labels are, e.g., 4 and 5, and
horizontal arrows appear between these two they actually correspond
to different Haar wavelet transform scales AT wavelet periodogram
level 4. It is not usually possible to tell precisely which
Haar wavelet transform scale the coefficients can come from,
but the information can be extracted from the summary.tos
function which lists this.
None.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Produces an interesting plot with high probability # # # Note that the input time series is two concatenated white noise # sequences with very different variances. # answer <- hwtos2(c(rnorm(256), rnorm(256, sd=5))) ## Not run: plot(answer)
# # Produces an interesting plot with high probability # # # Note that the input time series is two concatenated white noise # sequences with very different variances. # answer <- hwtos2(c(rnorm(256), rnorm(256, sd=5))) ## Not run: plot(answer)
tosANYN
object.
After a test of stationarity (e.g. hwtos
)
is applied to a time series it generates a results object of
class tosANYN
. This function takes objects of that
class and produces a graphical representation of the test.
## S3 method for class 'tosANYN' plot(x, sub = NULL, xlab = "Time", arrow.length = 0.05, verbose = FALSE, ...)
## S3 method for class 'tosANYN' plot(x, sub = NULL, xlab = "Time", arrow.length = 0.05, verbose = FALSE, ...)
x |
The |
sub |
An argument to change the subtitle. |
xlab |
An argument to change the x-axis label. |
arrow.length |
The length of the edges of the arrow
head (in inches). Note that this is the argument that is
supplied as the |
verbose |
If |
... |
Other arguments to the main |
The following things are usually plotted. 1. The time series that was investigated. The left-hand axes is that for the time series. The horizontal axis is time (but just integers indexing). If the series was deemed stationary by the test then that's it except that the subtitle indicates that no Haar wavelet coefficients were rejected as being nonzero.
If the test indicated that the series was nonstationary then
the subtitle indicates this by stating the number of rejections.
Then graphical
representations of any significant Haar wavelet coefficients
are plotted as double-headed red horizontal arrows on the plot.
The horizontal extent corresponds to the support of the underlying
wavelet. The vertical position of the arrows gives an indication
of the wavelet periodogram scale where the significant coefficient
was found. The wavelet periodogram scales are indexed by the right
hand axis, and beware, the numbers might not be consecutive, but
the will be ordered (so e.g. if no signficant coefficients were
discovered at wavelet periodogram scale level 6, then that scale/axis
label will not appear). The scale within the Haar wavelet transform
is indicated by the vertical position WITHIN ticks between
wavelet periodogram scales (ie, there are TWO scales: the wavelet
periodogram scale that is currently being analyzed, and the
Haar wavelet transform scale within the periodogram scale).
So, if two right hand axis labels are, e.g., 4 and 5, and
horizontal arrows appear between these two they actually correspond
to different Haar wavelet transform scales AT wavelet periodogram
level 4. It is not usually possible to tell precisely which
Haar wavelet transform scale the coefficients can come from,
but the information can be extracted from the summary.tosANYN
function which lists this.
None.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Produces an interesting plot with high probability # # # Note that the input time series is two concatenated white noise # sequences with very different variances. # ## Not run: answer <- hwtos(c(rnorm(256), rnorm(256, sd=5))) ## Not run: plot(answer)
# # Produces an interesting plot with high probability # # # Note that the input time series is two concatenated white noise # sequences with very different variances. # ## Not run: answer <- hwtos(c(rnorm(256), rnorm(256, sd=5))) ## Not run: plot(answer)
hwtANYN
class object, eg from the link{hwt}
function.
Prints out very basic information on an object that represents a Haar wavelet transform of a data set of non-dyadic length.
## S3 method for class 'hwtANYN' print(x, ...)
## S3 method for class 'hwtANYN' print(x, ...)
x |
The object you wish to print. |
... |
Other arguments |
This function calls the summary.hwtANYN
function as its last action. So, the return from this
function is the return from summary.hwtANYN
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Generate test vector of length 5 # v2 <- rnorm(5) # # Compute Haar wavelet transform # v2.hwt <- hwt(v2) # # Print out the answer # print(v2.hwt) #Class 'hwtANYN' : Haar Wavelet for Arbitrary Length Data object: # ~~~~~~~ : List with 5 components with names # c d nlevels type reindex # # #summary(.): #---------- #Levels: 2 #Filter was: Haar #Transform type: wavelet #Object was reindex to match wd: FALSE
# # Generate test vector of length 5 # v2 <- rnorm(5) # # Compute Haar wavelet transform # v2.hwt <- hwt(v2) # # Print out the answer # print(v2.hwt) #Class 'hwtANYN' : Haar Wavelet for Arbitrary Length Data object: # ~~~~~~~ : List with 5 components with names # c d nlevels type reindex # # #summary(.): #---------- #Levels: 2 #Filter was: Haar #Transform type: wavelet #Object was reindex to match wd: FALSE
Prints information about lacf class object.
## S3 method for class 'lacf' print(x, ...)
## S3 method for class 'lacf' print(x, ...)
x |
The lacf class object you want to print |
... |
Other arguments |
None
Guy Nason
Cardinali, A. and Nason, G.P. (2012) Costationarity of Locally
Stationary Time Series using costat
.
Cardinali, A. and Nason, G.P. (2010) Costationarity of locally stationary time series. J. Time Series Econometrics, 2, Issue 2, Article 1.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=30) # # Now let's print the lacf object # print(vlacf) #Class 'lacf' : Localized Autocovariance/correlation Object: # ~~~~ : List with 3 components with names # lacf lacr date # # #summary(.): #---------- #Name of originating time series: #Date produced: Thu Oct 25 12:11:29 2012 #Number of times: 256 #Number of lags: 30
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=30) # # Now let's print the lacf object # print(vlacf) #Class 'lacf' : Localized Autocovariance/correlation Object: # ~~~~ : List with 3 components with names # lacf lacr date # # #summary(.): #---------- #Name of originating time series: #Date produced: Thu Oct 25 12:11:29 2012 #Number of times: 256 #Number of lags: 30
lacfCI
object.
Prints basic information about a lacfCI
object, which
contains information on confidence intervals for localized
autocovariance.
## S3 method for class 'lacfCI' print(x, ...)
## S3 method for class 'lacfCI' print(x, ...)
x |
The |
... |
Other arguments |
The last action of this function is to compute
summary.tos
so the return code is whatever
that function returns.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example on Rvarlacf help page
# # See example on Rvarlacf help page
tos
class object, eg from the link{hwtos2}
function.
Prints out very basic information on an object that represents the output from a test of stationarity.
## S3 method for class 'tos' print(x, ...)
## S3 method for class 'tos' print(x, ...)
x |
The object you wish to print. |
... |
Other arguments |
This function calls the summary.tos
function as its last action. So, the return from this
function is the return from summary.tos
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example at end of help for hwtos2 #
# # See example at end of help for hwtos2 #
tosANYN
class object, eg from the link{hwtos}
function.
Prints out very basic information on an object that represents the output from a test of stationarity.
## S3 method for class 'tosANYN' print(x, ...)
## S3 method for class 'tosANYN' print(x, ...)
x |
The object you wish to print. |
... |
Other arguments |
This function calls the summary.tosANYN
function as its last action. So, the return from this
function is the return from summary.tosANYN
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example at end of help for hwtos #
# # See example at end of help for hwtos #
This function essentially uses the running.mean
function from the igraph
package. However, adjustments
are made to ensure that the output is always the same length
as the input (by fiddling at the boundaries).
runmean(x, binwidth)
runmean(x, binwidth)
x |
Vector that you wish to smooth using a running mean. |
binwidth |
Number of ordinates over which you wish to average |
For example, if binwidth=2
and x=1:6
then
the function averages each pair to get 1.5, 2.5, 3.5, 4.5, 5.5.
However, this is only 5 numbers and the input had 6. So, in this
case the function arranges for the output to be extended (in this
case 1 gets padded onto the front. For vectors of length > 3
the padding depends on whether the vector is even or odd.
The running mean of the input at the given bandwidth.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
runmean(1:6, 2) # # [1] 1.0 1.5 2.5 3.5 4.5 5.5 # runmean(1:14, 4) # # [1] 1.75 2.50 3.50 4.50 5.50 6.50 7.50 8.50 9.50 10.50 11.50 12.5 # [13] 13.25 13.50 #
runmean(1:6, 2) # # [1] 1.0 1.5 2.5 3.5 4.5 5.5 # runmean(1:14, 4) # # [1] 1.75 2.50 3.50 4.50 5.50 6.50 7.50 8.50 9.50 10.50 11.50 12.5 # [13] 13.25 13.50 #
Compute a localized autocovariance and associated confidence intervals for a locally stationary time series. The underlying theory assumes a locally stationary wavelet time series, but will work well for other time series that are not too far away.
Rvarlacf(x, nz, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, lag.max = NULL, WPsmooth.type = "RM", binwidth = 0, mkcoefOBJ, ThePsiJ, Cverbose = 0, verbose = 0, OPLENGTH = 10^5, var.lag.max = 3, ABB.tol = 0.1, ABB.plot.it = FALSE, ABB.verbose = 0, ABB.maxits = 10, truedenom=FALSE, ...)
Rvarlacf(x, nz, filter.number = 1, family = "DaubExPhase", smooth.dev = var, AutoReflect = TRUE, lag.max = NULL, WPsmooth.type = "RM", binwidth = 0, mkcoefOBJ, ThePsiJ, Cverbose = 0, verbose = 0, OPLENGTH = 10^5, var.lag.max = 3, ABB.tol = 0.1, ABB.plot.it = FALSE, ABB.verbose = 0, ABB.maxits = 10, truedenom=FALSE, ...)
x |
The time series you wish to analyze |
nz |
The time point at which you wish to compute the localized autocovariance for. |
filter.number |
The analysis wavelet for many things, including
smoothing. See |
family |
The analysis wavelet family. See |
smooth.dev |
The deviance function used to perform smoothing of the evolutionary wavelet spectrum. |
AutoReflect |
The internal wavelet transforms assume periodic
boundary conditions. However, most time series are not
periodic (in terms of their support, e.g. the series at time
1 is not normally anywhere near the value of the series at
time T). This argument, if |
lag.max |
The maximum number of lags to compute the localized
autocovariance for. The default is the same as in the
regular |
WPsmooth.type |
The type of smoothing of the evolutionary
wavelet spectrum and the localized autocovariance. See the
arguments to |
binwidth |
The smoothing bandwidth associated with the
smoothing controlled by |
mkcoefOBJ |
Optionally, the appropriate discrete wavelet transform object can be supplied. If it is not supplied then the routine automatically computes it. There is a small saving in providing it, so for everyday use probably not worth it. |
ThePsiJ |
As for |
Cverbose |
If positive integer then the called C code produces verbose messages. Useful for debugging. |
verbose |
If positive integer >0 then useful messages are printed. Higher values give more information. |
OPLENGTH |
Parameter that controls storage allocated to
the |
var.lag.max |
Number of lags that you want to compute confidence
intervals for. Usually, it is quick to compute for more lags,
so this could usually be set to be the value of |
ABB.tol |
The routine selects the automatic bandwidth via a golden section search. This argument controls the optimization tolerance. |
ABB.plot.it |
Whether or not to plot the iterations of the
automatic bandwidth golden section search. ( |
ABB.verbose |
Positive integer controlling the amount of detail from the automatic bandwidth golden section search algorithm. If zero nothing is produced. |
ABB.maxits |
The maximum number of iterations in the automatic bandwidth golden section search. |
truedenom |
If TRUE use the actual number of terms in the sum as the denominator in the formula for the calculation of the covariance of the smoothed periodogram. If FALSE use the eqn(2s+1)^-2 (this was the default in versions prior to 1.7.4) |
... |
Other arguments |
1. If binwidth=0
the function first computes the
‘best’ linear running mean binwidth (bandwidth)
for the smooth of the localized autocovariance.
2. The function computes the localized autocovariance
smoothed with a running mean with the selected binwidth.
Then, the variance of is
computed for the selected value of time z=nz and for the
lags specified (in
var.lag.max
). The results are
returned in an object of class lacfCI
.
Note, this function
computes and plots localized autocovariances for a particular
and fixed time location. Various other plots, including
perspective plots or the localized autocovariance function
over all time can be found in the costat
package.
(Indeed, this function returns a lacfCI
object that
contains a lacf
object, and interesting plots
can be plotted using the plot.lacf
function within
costast
.
An object of class lacfCI
. This is a list with
the following components.
lag |
The lags for which the localized autocovariance variance is computed |
cvar |
The variances associated with each localized autocovariance |
the.lacf |
The |
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
plot.lacfCI
, print.lacfCI
,
summary.lacfCI
# # Do localized autocovariance on a iid Gaussian sequence # tmp <- Rvarlacf(rnorm(256), nz=125) # # Plot the localized autocovariances over time (default plot, doesn't # produce CIs) # ## Not run: plot(tmp) # # You should get a plot where the lag 0 acs are all near 1 and all the # others are near zero, the acfs over time. # ## Not run: plot(tmp, plotcor=FALSE, type="acf") # # This plots the autocovariances (note: \code{plotcor=FALSE}) and the # type of plot is \code{"acf"} which means like a regular ACF plot, except # this is c(125, tau), ie the acf localized to time=125 The confidence # intervals are also plotted. # The plot subtitle indicates that it is c(125, tau) that is being plotted #
# # Do localized autocovariance on a iid Gaussian sequence # tmp <- Rvarlacf(rnorm(256), nz=125) # # Plot the localized autocovariances over time (default plot, doesn't # produce CIs) # ## Not run: plot(tmp) # # You should get a plot where the lag 0 acs are all near 1 and all the # others are near zero, the acfs over time. # ## Not run: plot(tmp, plotcor=FALSE, type="acf") # # This plots the autocovariances (note: \code{plotcor=FALSE}) and the # type of plot is \code{"acf"} which means like a regular ACF plot, except # this is c(125, tau), ie the acf localized to time=125 The confidence # intervals are also plotted. # The plot subtitle indicates that it is c(125, tau) that is being plotted #
The computation of the variance of the lacf estimator is intensive and we try to speed that up by reusing calculations. These calculations are stored in internal C arrays. This function interrogates those arrays and can provide details on how well the storage is working and provide hints if more storage needs to be allocated. For very large time series it is possible that values need to be calculated that can be stored and this function can monitor this.
StoreStatistics()
StoreStatistics()
The function prints out the state of the storage. Three numbers are reported on. 1. The number of values that were calculated but not stored "outside framework". Ideally you want this number to be low, if it gets persistently high then more storage needs to be allocated in the C code (notably MAXELL, MAXJ, MAXK, MAXD for the ThmStore and ValExists arrays).
The other two numbers are "Number stored" and "Number found". The first number corresponds to the number of values calculated once and then stored. The second number contains the number of times the software interogated the store and found a value that it did not have to then calculate. So, ideally, you'd like the latter number to be a high percentage of the former number, as this means the store is working efficiently.
Note, this function is definitely not intended for casual users. However, for users of very large series, who have the computational resources, these storage parameters might need to be increased.
The values will be zero if Rvarlacf
has not
yet been called, and only refer to the last call to that function
(as the function zeroes the store on invocation).
None.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Simulate some data # x <- tvar1sim() # # Calculate lacf and confidence intervals # x.lacf <- Rvarlacf(x=x, nz=50, var.lag.max=20) # # Find out how the store did # StoreStatistics() #Number calculated outside framework: 0 #Number calculated then stored: 154440 #Number found in store: 14980680 # #Overall % calculated: 1.020408 #% outside framework: 0
# # Simulate some data # x <- tvar1sim() # # Calculate lacf and confidence intervals # x.lacf <- Rvarlacf(x=x, nz=50, var.lag.max=20) # # Find out how the store did # StoreStatistics() #Number calculated outside framework: 0 #Number calculated then stored: 154440 #Number found in store: 14980680 # #Overall % calculated: 1.020408 #% outside framework: 0
This function summarizes the results of a hwtANYN
object that contains the results of a Haar wavelet transform that
had been carried out on an original vector of (potentially) non-dyadic
length.
## S3 method for class 'hwtANYN' summary(object, ...)
## S3 method for class 'hwtANYN' summary(object, ...)
object |
The object that you want a summary of. The object might be
the results from, e.g., |
... |
Other arguments |
None.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See help for print.hwtANYN
# # See help for print.hwtANYN
Summarizes a lacf object
## S3 method for class 'lacf' summary(object, ...)
## S3 method for class 'lacf' summary(object, ...)
object |
The lacf object you wish summarized. |
... |
Other arguments |
None
Guy Nason
Cardinali, A. and Nason, G.P. (2012) Costationarity of Locally
Stationary Time Series using costat
.
Cardinali, A. and Nason, G.P. (2010) Costationarity of locally stationary time series. J. Time Series Econometrics, 2, Issue 2, Article 1.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=20) # # Now let's summarize the lacf object # summary(vlacf) #Name of originating time series: #Date produced: Thu Oct 25 12:11:29 2012 #Number of times: 256 #Number of lags: 20
# # Make some dummy data, e.g. white noise # v <- rnorm(256) # # Compute the localized autocovariance (ok, the input is stationary # but this is just an example. More interesting things could be achieved # by putting the results of simulating from a LSW process, or piecewise # stationary by concatenating different stationary realizations, etc. # vlacf <- lacf(v, lag.max=20) # # Now let's summarize the lacf object # summary(vlacf) #Name of originating time series: #Date produced: Thu Oct 25 12:11:29 2012 #Number of times: 256 #Number of lags: 20
lacfCI
object
Produces brief summary of the contents of a lacfCI
object.
## S3 method for class 'lacfCI' summary(object, ...)
## S3 method for class 'lacfCI' summary(object, ...)
object |
The |
... |
Other arguments. |
No value
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example in the Rvarlacf function
# # See example in the Rvarlacf function
tos
object.
This function summarizes the results of a tos
object that contains information about a test of stationarity.
The summary function prints out information about how many
individual hypothesis tests there were, how many were rejected
and what the (equivalent) rejection p-value was (in the last cases
both for FDR and Bonferroni). If the hypothesis of stationarity
is rejected then the routine also prints out a list of the Haar
wavelet coefficients (and their scales, locations and scale of
the wavelet periodogram) that were significant.
The function also returns a lot of this information (invisibly).
## S3 method for class 'tos' summary(object, size = 0.05, quiet = FALSE, mctype = "FDR", ...)
## S3 method for class 'tos' summary(object, size = 0.05, quiet = FALSE, mctype = "FDR", ...)
object |
The output from a function that carries out a test
of stationarity, e.g. |
size |
The nominal overall significance level of the test. |
quiet |
If this argument is |
mctype |
This argument can be |
... |
Other arguments |
The function returns a list which contain a list of the
rejected coefficients. Each list item contains the index
of a particular rejected coefficient, which is a vector
of at least three elements. The first element corresponds to
the scale of the wavelet periodogram, the second is the level of
the Haar wavelet transform, and all remaining values are the
index of the significant wavelet coefficients at that Haar wavelet
transform scale. The list also contains the total number of
Haar wavelet coefficients rejected and the mctype
argument also.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example for hwtos2, this contains two examples where # summary.tos (as summary(.) is used in the output.
# # See example for hwtos2, this contains two examples where # summary.tos (as summary(.) is used in the output.
tosANYN
class object.
This function summarizes the results of a tosANYN
object that contains information about a test of stationarity.
The summary function prints out information about how many
individual hypothesis tests there were, how many were rejected.
If the hypothesis of stationarity
is rejected then the routine also prints out a list of the Haar
wavelet coefficients (and their scales, locations and scale of
the wavelet periodogram) that were significant.
The function also returns a lot of this information (invisibly).
## S3 method for class 'tosANYN' summary(object, quiet = FALSE, ...)
## S3 method for class 'tosANYN' summary(object, quiet = FALSE, ...)
object |
The output from a function that carries out a test
of stationarity, e.g. |
quiet |
If this argument is |
... |
Other arguments |
The function returns a list which contain a list of the
rejected coefficients. Each list item contains the index
of a particular rejected coefficient, which is a vector
of at least three elements. The first element corresponds to
the scale of the wavelet periodogram, the second is the level of
the Haar wavelet transform, and all remaining values are the
index of the significant wavelet coefficients at that Haar wavelet
transform scale. The list also contains the total number of
Haar wavelet coefficients rejected and the mctype
argument also.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # See example for hwtos, this contains two examples where # summary.tosANYN (as summary(.) is used in the output.
# # See example for hwtos, this contains two examples where # summary.tosANYN (as summary(.) is used in the output.
Simulates a realization from a TVAR(1) model where
the AR(1) parameter moves from 0.9 to -0.9 in equal steps
over 512 time points. The realization is also of length 512.
The innovations are normally distributed with mean zero and
standard deviation of sd
.
tvar1sim(sd = 1)
tvar1sim(sd = 1)
sd |
This is the standard deviation of the Gaussian innovation. |
This function is easily converted into one that does the same thing but for a different sample size.
A realization of the aforementioned TVAR(1) process.
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Generate realization from the TVAR(1) process # x <- tvar1sim() # # Maybe plot it # ## Not run: ts.plot(x)
# # Generate realization from the TVAR(1) process # x <- tvar1sim() # # Maybe plot it # ## Not run: ts.plot(x)
Performs a direct computation of an estimate of the variance of the Haar wavelet coefficients of the raw wavelet periodogram of a time series.
varip2(i, p, ll, S, P)
varip2(i, p, ll, S, P)
i |
Scale parameter of Haar wavelet analyzing periodogram. Scale 1 is the finest scale. |
p |
Location parameter of Haar wavelet analyzing periodogram |
ll |
Scale of the raw wavelet periodogram being analyzed |
S |
Estimate of the spectrum, under the assumption of stationarity.
So, this is just a vector of (possibly) J scales (which is often
the usual spectral estimate averaged over time). Note: that the
main calling function, |
P |
Is an autocorrelation wavelet object, returned by the
|
Computes the variance of the Haar wavelet coefficients of the raw wavelet periodogram. Note, that this is merely an estimate of the variances.
A list with the following components:
covAA |
A component of the variance |
covAB |
A component of the variance |
covBB |
A component of the variance |
ans |
The actual variance |
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
# # Generate autocorrelation wavelets # P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # # Now compute varip2: this is the variance of the Haar wavelet coefficient # at the finest scale, location 10 and P1 autocorrelation wavelet. # Note, I've used S to be the exact coefficients which would be for white noise. # In practice, S would be an *estimate* calculated from the data. # varip2(i=1, p=10, ll=2, S=c(1/2, 1/4, 1/8, 1/16, 1/32), P=P1) # # Ans component is 1.865244
# # Generate autocorrelation wavelets # P1 <- PsiJ(-5, filter.number=1, family="DaubExPhase") # # # Now compute varip2: this is the variance of the Haar wavelet coefficient # at the finest scale, location 10 and P1 autocorrelation wavelet. # Note, I've used S to be the exact coefficients which would be for white noise. # In practice, S would be an *estimate* calculated from the data. # varip2(i=1, p=10, ll=2, S=c(1/2, 1/4, 1/8, 1/16, 1/32), P=P1) # # Ans component is 1.865244
mkcoef
Helps mkcoef
by finding out how many
more levels are required to compute a set of discrete
wavelets to a given (other) level.
whichlevel(J, filter.number = 10, family = "DaubLeAsymm")
whichlevel(J, filter.number = 10, family = "DaubLeAsymm")
J |
The level that |
filter.number |
The wavelet number (see |
family |
The wavelet family (see |
When computing the discrete wavelets up to a given scale we use the inverse wavelet transform to do this. However, to generate a wavelet within the range of a wavelet decomposition you have to use more scales in the inverse wavelet transform than first requested. This is because wavelet coefficients at the coarsest scales are associated with wavelets whose support is greater than the whole extent of the series. Hence, you have to have a larger wavelet transform, with more levels, insert a coefficient mid-level to generate a discrete wavelet whose support lies entirely within the extent of the series. This function figures out what the extra number of levels should be.
Simply returns the required number of levels
Guy Nason.
Nason, G.P. (2013) A test for second-order stationarity and approximate confidence intervals for localized autocovariances for locally stationary time series. J. R. Statist. Soc. B, 75, 879-904. doi:10.1111/rssb.12015
whichlevel(6) # [1] 11 # # E.g. mkcoef wanted to generate 6 levels of discrete wavelets and # whichlevel tells it that it needs to generate a wavelet transform # of at least 11 levels.
whichlevel(6) # [1] 11 # # E.g. mkcoef wanted to generate 6 levels of discrete wavelets and # whichlevel tells it that it needs to generate a wavelet transform # of at least 11 levels.
Take a vector of any length and then intersperse zeroes between existing elements (and add a further zero to the end).
zeropad(x)
zeropad(x)
x |
Vector that you want to intersperse zeros into. |
Title says it all.
A vector whose odd elements are just x
and whose
even elements are zeroes.
G.P. Nason
# # Operate on a test set # v <- 1:3 zeropad(v) #[1] 1 0 2 0 3 0
# # Operate on a test set # v <- 1:3 zeropad(v) #[1] 1 0 2 0 3 0