prior_alpha_beta: Determine Hyperparameters for Bayesian Wavelet Thresholding

View source: R/priors.R

prior_alpha_betaR Documentation

Determine Hyperparameters for Bayesian Wavelet Thresholding

Description

The function prior_alpha_beta determines both the parameters alpha and beta that are used in bayesian wavelet thresholding of noisy data. Estimation is based on minimizing the avarage of forecast error.

Usage

prior_alpha_beta(
  x,
  h,
  k,
  lags,
  par = c(0.5, 1),
  lower = c(0, 0),
  upper = c(3, 3),
  control = list(),
  wtfunlist = list(),
  ...
)

Arguments

x

A vector or a time series containing the data (headline inflation).

h

An integer to set the desired horizon.

k

An integer to determine the number of observations to include in the out-of-sample set.

lags

A data frame generated by the function lags.

par

Initial values for the parameters to be optimized over.

lower

Bounds on the variables for the "L-BFGS-B" method. See stats::optim.

upper

Bounds on the variables for the "L-BFGS-B" method. See stats::optim.

control

A list of control parameters. See stats::optim.

wtfunlist

A named list of parameters to pass to function wavethresh::wd.

...

Additional parameters to pass to function smooth_wavelet. Do not pass the argument policy used in function wavethresh::threshold.wd.

Value

A numeric vector of length two.

Examples


# Example 1

pq <- lags(1, 1)
ipca <- coreinf_br$ipca
prior_alpha_beta(
x = ipca, h = 2, k = 5, lags = pq,
lower = c(0.2, 0.5),
wtfunlist = list(type = "wavelet"),
type = "hard"
)

# Example 2

## Not run: 

# Including the best priors for denoising

wthr_wd <- list(
filter.number = 1,
family = c("DaubExPhase"),
type = c("wavelet", "station")
)

# Note: initial alpha and beta must be included such
# that the appropriate structure of wthr_args is maitained
# after the inclusion of estimated priors

wthr_thr <- list(
  type = c("soft"),
  alpha = 0.5,
  beta = 1
)

wthr_args <- wav_args_wthr(wthr_wd, wthr_thr, 3)

# Best priors estimation and inclusion in wthr_args

args_tbl2 <- wthr_args$args_tbl %>%
dplyr::mutate(ab = purrr::pmap(., ~purrr::possibly(prior_alpha_beta, NA)(
  ipca, 2, 4, pq,
  lower = c(0.4, 0.6), upper = c(0.6, 1.1),
  control = list(reltol = 0.01),
  wtfunlist = list(..1, ..2, ..3),
  type = ..4, lr = ..7)),
  alpha = purrr::map_dbl(ab, ~`[`(.x, 1)),
  beta = purrr::map_dbl(ab, ~`[`(.x, 2))) %>%
  dplyr::select(-ab)

wthr_args[[1]] <- args_tbl2

# Denoising after including estimated priors

wav_smooth(ipca, wthr_args)

## End(Not run)


nelson16silva/wavcoreinf documentation built on Feb. 17, 2025, 7:10 p.m.