WPTOSpickout: Find nonstationarities in a time series

View source: R/WPTOSpickout.R

WPTOSpickoutR Documentation

Find nonstationarities in a time series

Description

The nonstationarities are located by looking for significant Haar wavelet coefficients of a b-spectrum of a time series (a b-spectrum is the expectation of a wavelet packet periodgram). The significant Haar coefficients can locate discontinuities in space and time.

Usage

WPTOSpickout(x, level, index, filter.number = 1, family = "DaubExPhase",
	plot.it = FALSE, verbose = FALSE, lowlev = 3, highlev, nomsize = 0.05)

Arguments

x

The time series you wish to analyse.

level

The level of the b-spectrum you want to examine. See help for BootWPTOS for more information on levels.

index

The index of the b-spectrum you want to examine. See help for BootWPTOS for more information on indices you can chose.

filter.number

The filter number of the underlying wavelet you wish to examine.

family

The family of the underlying wavelet you wish to examine.

plot.it

If TRUE this plots the time series x as supplied. Then, superimposed in red, is the raw wavelet packet periodogram. The Haar wavelet coefficients of the red signal are examined for whether they are deemed non-zero or not using asymptotic normality results. If FALSE then no such plot is produced.

verbose

If TRUE then a single line indicating the number of significant coefficients found is printed. If FALSE then the function prints nothing.

lowlev

Keep away from coarse scales. Typically, Haar wavelet coefficients at the coarse scales are contaminated by boundary effects. These won't usually cause a problem at scales 3 or higher, or maybe 2. Only coefficients at scales lowlev or finer will be selected for testing.

highlev

Keep away from fine scales. The testing of Haar wavelet coeffients depends on utilizing enough data points to enable asymptotic normality to kick in. At the finest scale only TWO single points are compared and the distribution of each point might be far from normality. At coarser scales TWO averages are compared and those averages will consist of many points. E.g. at the third finest scale each average will consist of four points, at the fourth finest scale each average will consist of 8 points, etc. By default this argument is set to be roughly the use a scale one level finer than the halfway number of levels. So, if J=10, then highlev is 6. The formula is floor(J/2)+1. Note: highlev and lowlev should be specified in the WaveThresh scaling (e.g. scale 0 is the coarsest scale)

nomsize

The nominal size of the test as a number between 0 and 1. So, if you want a 5

Details

This function computes the nondecimated wavelet packet transform of the packet you specified by level and index. Note: you can only specify one number for each of these. Then the b-spectrum (raw wavelet packet periodogram) is formed by squaring the nondecimated wavelet packet transform. Then the Haar wavelet coefficients are obtained for the b-spectrum and a multiple hypothesis test is performed on all the Haar wavelet coefficients between scales lowlev and highlev. The function return information about any significant wavelet coefficients.

Value

A list of class toswp containing the following components:

x

The time series that was analyzed

level

The level of the b-spectrum that we wanted

index

The index of the b-spectrum that we wanted

sigcoefs

A wd class object containing the significant Haar wavelet coefficients, if there are any

nreject

The number of significant Haar wavelet coefficients

ntests

The total number of hypothesis tests carried out in the multiple hypothesis test

bonsize

The Bonferroni corrected rate for the multiple hypothesis test

Author(s)

G.P. Nason

References

Cardinali, A. and Nason, G.P. (2016) Practical Powerful Wavelet Packet Tests for Second-Order Stationarity. Applied and Computational Harmonic Analysis, 2016 doi: 10.1016/j.acha.2016.06.006

See Also

BootWPTOS, plot.toswp, print.toswp, summary.toswp

Examples

#
# Create some simulated data
#
x2 <- c(rnorm(256), rnorm(256, 2))
#
# The following call to BootWPTOS (generic tester) 
#
# [We're not running them in R package testing as they can be quite intensive]
#
## Not run: x2.tos <- BootWPTOS(x2, levs=5, indices=1, Bsims=500)
## Not run: x2.tos
#
#	WPBootTOS test of stationarity
#
#data:  x2
#= 5.2826, p-value < 2.2e-16
#
# So, test indicates that strong evidence for nonstationarity. 
#
# Now let's do the multiple Haar hypothesis test.
#
x2.po <- WPTOSpickout(x=x2, level=7, index=1)
x2.po
#Class 'toswp' : Wavelet Packet Test of Stationarity Object :
#       ~~~~  : List with 7 components with names
#              x level index sigcoefs nreject ntests bonsize 
#
#
#summary(.):
#----------
#Number of individual tests: 56 
#Bonferroni p-value was: 0.0008928571 
#Tests rejected: 2 
#Listing Bonferroni rejects...
#Wavelet Packet  (5,1): HWTlev: 4. Indices: 8  
#Wavelet Packet  (5,1): HWTlev: 5. Indices: 16 
#
# So, this test also shows nonstationarities. For this packet (5,1)
# two significant Haar coefficients were identified. One was at level 4
# position 8 and the other was at scale level 5 position 16.
#
# You can plot them also
#
plot(x2.po)
#
# You should get a nice plot of the time series with double-headed red
# arrows indicating the location and extent of the nonstationarities.
# For this example, where the spectrum changes dramatically at the halfway
# point - this is where the arrows should be located. Of course, with random
# data you might see other arrows in other locations, but this should be
# unlikely and on repeating the above they should not persist.

BootWPTOS documentation built on May 20, 2022, 5:05 p.m.