threshold.wd(wd, levels = 3:(wd$nlevels - 1), type = "soft", policy = "sure", by.level = F, value = 0, dev = madmad, boundary = F, verbose = F, return.threshold = F, force.sure = F, cvtol = 0.01, Q = 0.05, alpha = 0.05, alpha = 0.5, beta = 1, C1 = NA, C2 = NA, C1.start = 100)
nlevels(wd)-1
inclusive.
Only the levels in this vector contribute to the computation of the
threshold and its application.
"hard"
or "soft"
.
"universal"
,
"LSuniversal"
,
"sure"
,
"BayesThresh"
,
"cv"
,
"fdr"
,
"op1"
,
"op2"
,
"manual"
,
"mannum"
and
"probability"
.
The policies are described in detail below.
levels
. If TRUE a threshold
is computed and applied separately to each scale level.
policy="manual"
then value
is the actual
threshold value; if the
policy="mannum"
then value
conveys the total number of ordered coefficients kept (from the largest);
if
policy="probability"
then value
conveys
the the user supplied quantile level.
var()
function. A popular, useful and
robust alternative is the madmad function.
"cv"
policy.
"fdr"
policy.
"op1"
and "op2"
policies.
"BayesThresh"
policy.
"BayesThresh"
policy.
"BayesThresh"
policy.
"BayesThresh"
policy.
"BayesThresh"
policy.
return.threshold
option is set to TRUE then the threshold
values will be returned rather than the thresholded object.
The basic idea of thresholding is very simple. In a signal plus noise
model the wavelet transform of signal is very sparse, the wavelet
transform of noise is not (in particular, if the noise is iid Gaussian
then so if the noise contained in the wavelet coefficients). Thus since
the signal gets concentrated in the wavelet coefficients and the noise
remains "spread" out it is "easy" to separate the signal from noise
by keeping large coefficients (which correspond to signal) and
delete the small ones (which correspond to noise). However, one has
to have some idea of the noise level (computed using the dev
option in threshold functions). If the noise level is very large then
it is possible, as usual, that no signal "sticks up" above the noise.
There are many components to a successful thresholding procedure. Some components have a larger effect than others but the effect is not the same in all practical data situations. Here we give some rough practical guidance, although you must refer to the papers below when using a particular technique. You cannot expect to get excellent performance on all signals unless you fully understand the rationale and limitations of each method below. I am not in favour of the "black-box" approach. The thresholding functions of WaveThresh3 are not a black box: experience and judgement are required!
Some issues to watch for:
levels = 3:(wd$nlevels - 1)
for the
levels
option most certainly does not work globally for
all data problems and situations. The level at which thresholding begins
(i.e. the given threshold and finer scale wavelets) is called the
primary resolution and is unique to a particular problem.
In some ways choice of the primary resolution is very similar to choosing
the bandwidth in kernel regression albeit on a logarithmic scale.
See Hall and Patil, (1995) and
Hall and Nason (1997) for more information.
For each data problem you need to work out which is the best
primary resolution. This can be done by gaining experience at what works
best, or using prior knowledge. It is possible to "automatically" choose
a "best" primary resolution using cross-validation (but not in WaveThresh).
Secondly the levels argument computes and applies the threshold at the
levels specified in the levels
argument. It does this for
all the levels specified. Sometimes, in wavelet shrinkage, the threshold
is computed using only the finest scale coefficients (or more precisely
the estimate of the overall noise level). If you want your threshold
variance estimate only to use the finest scale coefficients (e.g.
with universal thresholding) then you will have to apply the
threshold.wd
function twice. Once (with levels set equal to
nlevels(wd)-1
and with
return.threshold=TRUE
to return the threshold computed on
the finest scale and then apply the threshold function with the
manual
option supplying the value of the previously computed
threshold as the value
options.
value
to pass the
value of the threshold. The value
argument should be a vector.
If it is of length 1 then it is replicated to be the same length as the
levels
vector, otherwise it is repeated as many times as is
necessary to be the levels
vector's length. In this way,
different thresholds can be supplied for different levels. Note that the
by.level
option has no effect with this policy.
value
.
probability
policy works as follows. All coefficients that
are smaller than the value
th quantile of the coefficients are
set to zero. If by.level
is false, then the quantile is computed
for all coefficients in the levels specified by the "levels" vector;
if by.level
is true, then each level's quantile is estimated separately.
The probability policy is pretty stupid - do not use it.
# # Generate some test data # test.data <- example.1()$y tsplot(test.data) # # Generate some noisy data # ynoise <- test.data + rnorm(512, sd=0.1) # # Plot it # tsplot(ynoise) # # Now take the discrete wavelet transform # N.b. I have no idea if the default wavelets here are appropriate for # this particular example. # ynwd <- wd(ynoise) plot(ynwd) # # Now do thresholding. We'll use a universal policy, # and madmad deviance estimate on the finest # coefficients and return the threshold. We'll also get it to be verbose # so we can watch the process. # ynwdT1 <- threshold(ynwd, policy="universal", dev=madmad, levels= nlevels(ynwd)-1, return.threshold=TRUE, verbose=TRUE) # threshold.wd: # Argument checking # Universal policy...All levels at once # Global threshold is: 0.328410967430135 # # Why is this the threshold? Well in this case n=512 so sqrt(2*log(n)), # the universal threshold, # is equal to 3.53223. Since the noise is about 0.1 (because that's what # we generated it to be) the threshold is about 0.353. # # Now let's apply this threshold to all levels in the noisy wavelet object # ynwdT1obj <- threshold(ynwd, policy="manual", value=ynwdT1, levels=0:(nlevels(ynwd)-1)) # # And let's plot it # plot(ynwdT1obj) # # You'll see that a lot of coefficients have been set to zero, or shrunk. # # Let's try a Bayesian example this time! # ynwdT2obj <- threshold(ynwd, policy="BayesThresh") # # And plot the coefficients # plot(ynwdT2obj) # # Let us now see what the actual estimates look like # ywr1 <- wr(ynwdT1obj) ywr2 <- wr(ynwdT2obj) # # Here's the estimate using universal thresholding # tsplot(ywr1) # # Here's the estimate using BayesThresh # tsplot(ywr2)