A lightweight R package for computing the Maximal Overlap Discrete Wavelet Transform (MODWT) and À Trous DWT. This package was originally developed to aid forecasting research in water resources (streamflow forecasting, urban water demand forecasting, etc.)
You can install the latest version of fastWavelets with
install.packages("fastWavelets")
You can also install the development version of fastWavelets from GitHub with:
# install.packages("devtools")
devtools::install_github("johnswyou/fastWavelets")
Here we decompose a white noise series using MODWT:
library(fastWavelets)
set.seed(839) # make this example reproducible
N <- 1e4 # number of time series points
J <- 9 # decomposition level
my.filter <- 'coif1' # filter
X <- matrix(rnorm(N),N,1) # white noise
modwt.X <- mo_dwt(X,my.filter,J,remove_boundary_coefs=FALSE)
colnames(modwt.X) <- c(paste0("W", 1:J), paste0("V", J))
nbc <- n_boundary_coefs(my.filter, J) # number of boundary affected coefficients
# Visualizations
plot.ts(X, main = "White noise series", ylab="")
plot.ts(modwt.X, nc=1, main="MODWT coefficients")
abline(v=nbc, lwd=2, col="blue", lty=2)
In the context of forecasting, everything to the left of the vertical dashed blue line would be removed prior to training a forecasting model using the MODWT coefficients. It is often useful to view wavelet decomposition methods such as the MODWT as a “feature generation” or “feature engineering” method.
Here’s how to remove the boundary coefficients:
modwt.X <- mo_dwt(X,"coif1",J,remove_boundary_coefs=TRUE)
The set of possible values for the argument filter
(see functions
mo_dwt()
and atrous_dwt()
):
c('bl7', 'bl9', 'bl10',
'beyl',
'coif1', 'coif2', 'coif3', 'coif4', 'coif5',
'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12',
'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23',
'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33',
'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45',
'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22',
'han2_3', 'han3_3', 'han4_5', 'han5_5',
'dmey',
'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3',
'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14',
'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27',
'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40',
'sym41', 'sym42', 'sym43', 'sym44', 'sym45',
'vaid',
'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
Quilty, J., & Adamowski, J. (2018). Addressing the incorrect usage of wavelet-based hydrological and water resources forecasting models for real-world applications with best practices and a new forecasting framework. Journal of Hydrology, 563, 336–353. https://doi.org/10.1016/j.jhydrol.2018.05.003
Bašta, M. (2014). Additive decomposition and boundary conditions in wavelet-based forecasting approaches. Acta Oeconomica Pragensia, 22(2), 48–70. https://doi.org/10.18267/j.aop.431
Benaouda, D., Murtagh, F., Starck, J.-L., & Renaud, O. (2006). Wavelet-based nonlinear multiscale decomposition model for electricity load forecasting. Neurocomputing, 70(1-3), 139–154. https://doi.org/10.1016/j.neucom.2006.04.005
Maheswaran, R., & Khosa, R. (2012). Comparative study of different wavelets for hydrologic forecasting. Computers & Geosciences, 46, 284–295. https://doi.org/10.1016/j.cageo.2011.12.015