{"id":25109941,"url":"https://github.com/smac-group/wv","last_synced_at":"2025-04-22T07:24:54.682Z","repository":{"id":19842962,"uuid":"87861426","full_name":"SMAC-Group/wv","owner":"SMAC-Group","description":":alarm_clock: This R package provides the tools to perform standard and robust wavelet variance analysis for time series (signal processing). Among others, aside from computing the wavelet variance and cross-covariance (classic and robust), the package provides inference tools (e.g. confidence intervals) and plotting tools allowing to perform some visual analysis and assess the properties of the underlying time series.","archived":false,"fork":false,"pushed_at":"2023-08-30T08:10:15.000Z","size":107494,"stargazers_count":17,"open_issues_count":13,"forks_count":10,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T22:18:57.465Z","etag":null,"topics":["signal-processing","time-series","wavelet-variance"],"latest_commit_sha":null,"homepage":"https://smac-group.github.io/wv/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SMAC-Group.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-10T21:59:00.000Z","updated_at":"2024-11-18T12:02:03.000Z","dependencies_parsed_at":"2023-02-14T12:31:03.754Z","dependency_job_id":null,"html_url":"https://github.com/SMAC-Group/wv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fwv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fwv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fwv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fwv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SMAC-Group","download_url":"https://codeload.github.com/SMAC-Group/wv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249837167,"owners_count":21332405,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["signal-processing","time-series","wavelet-variance"],"created_at":"2025-02-08T00:33:40.139Z","updated_at":"2025-04-20T01:29:30.145Z","avatar_url":"https://github.com/SMAC-Group.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n![example\nworkflow](https://github.com/SMAC-Group/wv/actions/workflows/R-CMD-check.yaml/badge.svg)\n[![Licence](https://img.shields.io/badge/licence-AGPL--3.0-blue.svg)](https://opensource.org/licenses/AGPL-3.0)\n[![minimal R\nversion](https://img.shields.io/badge/R%3E%3D-3.4.0-6666ff.svg)](https://cran.r-project.org/)\n[![CRAN](http://www.r-pkg.org/badges/version/wv)](https://cran.r-project.org/package=wv)\n[![CRAN RStudio mirror\ndownloads](http://cranlogs.r-pkg.org/badges/wv)](https://www.r-pkg.org/pkg/wv)\n[![CRAN RStudio mirror\ndownloads](https://cranlogs.r-pkg.org/badges/grand-total/wv)](https://www.r-pkg.org/pkg/wv)\n\n# `wv` Overview \u003ca href=\"https://smac-group.com/\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" style=\"width: 20%; height: 20%\"/\u003e\u003c/a\u003e\n\nThis repository is dedicated to the Wavelet Variance (`wv`) R package\nwhere different tools to perform wavelet variance analysis are provided\n(both standard and robust analysis). Below are instructions and examples\non how to install and make use of the `wv` package.\n\n*Currently the only implemented wavelet filter in the package is the\nHaar wavelet filter.*\n\n## Install Instructions\n\nThe `wv` package is available on both CRAN and GitHub. The CRAN version\nis considered stable while the GitHub version is subject to\nmodifications/updates which may lead to installation problems or broken\nfunctions. You can install the stable version of the `wv` package with:\n\n``` r\ninstall.packages(\"wv\")\n```\n\nFor users who are interested in having the latest developments, the\n[GitHub](https://github.com/SMAC-Group/wv) version is ideal although\nmore dependencies are required to run a stable version of the package.\nMost importantly, users **must** have a (C++) compiler installed on\ntheir machine that is compatible with R (e.g. Clang). Once you’ve made\nsure that you have a compatible C++ compiler installed on your computer,\nrun the following code in an R session and you will be ready to use the\ndevlopment version of `wv`.\n\n``` r\n# Install dependencies\ninstall.packages(c(\"devtools\"))\n\n# Install/Update the package from GitHub\ndevtools::install_github(\"SMAC-Group/wv\")\n\n# Install the package with Vignettes/User Guides \ndevtools::install_github(\"SMAC-Group/wv\", build_vignettes = TRUE)\n```\n\n## Wavelet Variance Analysis\n\nBelow are some examples of how to make use of some of the main functions\nin the `wv` package. Firstly, we highlight the functions that perform\nthe wavelet decomposition of a time series (both the discrete and\nmaximum-overlap discrete wavelet transforms) based on which the\nfollowing functions can compute the wavelet variance and its\ncorresponding confidence intervals for inference. These are particularly\nuseful, for example, when comparing the wavelet variance of different\ntime series in order to understand if they share common properties or\nnot.\n\n### Discrete Wavelet Transform (DWT)\n\nThe DWT performs a wavelet decomposition by applying the wavelet filter\nto non-overlapping windows of the time series. Below is an example of\nhow to perform this decomposition on a simulated Gaussian random walk\nprocess.\n\n``` r\n# Load packages\nlibrary(wv)\nlibrary(simts)\n#\u003e \n#\u003e Attaching package: 'simts'\n#\u003e The following object is masked from 'package:wv':\n#\u003e \n#\u003e     unitConversion\n\n# Set seed for reproducibility \nset.seed(999)\n\n# Simulate a Gaussian random walk\nn = 10^3\nmodel = RW(gamma2 = 1)\nXt = gen_gts(n = n, model = model)\n\n# Plot the simulated random walk\nplot(Xt)\n```\n\n![](man/figures/README-unnamed-chunk-4-1.png)\u003c!-- --\u003e\n\nBased on the above code, we have simulated a random walk with null\nexpectation unit innovation variance. The functions to compute the DWT,\naccess its output and plot the related wavelet coefficients can be found\nbelow.\n\n\u003c!-- For the moment this method will only work with Haar wavelets.  --\u003e\n\n``` r\n# DWT\nXt.dwt = dwt(Xt)\n#\u003e Warning in dwt(Xt): The data has been truncated so that it is divisible by\n#\u003e `nlevels` (e.g. 2^*)\n\n# Print the Wavelet Coefficients \nsummary(Xt.dwt)\n#\u003e \n#\u003e Results of DWT using haar filter with 8 levels:\n#\u003e Displaying only the first 6 coefficients...\n#\u003e Level 1 Wavelet Coefficients\n#\u003e  -0.9281198 0.1909687 -0.4002392 -0.8957566 -0.7926733 0.09473632 ...\n#\u003e Level 2 Wavelet Coefficients\n#\u003e  0.2739394 -2.795066 0.8319477 0.3625764 -0.08550498 0.108777 ...\n#\u003e Level 3 Wavelet Coefficients\n#\u003e  -2.384147 2.388987 -2.733086 -1.928826 -2.133592 -2.809311 ...\n#\u003e Level 4 Wavelet Coefficients\n#\u003e  -6.282995 -5.729953 -7.616116 1.635971 1.2219 4.605007 ...\n#\u003e Level 5 Wavelet Coefficients\n#\u003e  -10.03819 -6.631445 -0.6948675 -19.01644 12.1667 -5.350667 ...\n#\u003e Level 6 Wavelet Coefficients\n#\u003e  -23.08426 -18.32217 18.40802 -8.680854 -4.335243 6.224648 ...\n#\u003e Level 7 Wavelet Coefficients\n#\u003e  -34.68146 -7.485961 -5.448519 -30.51181 ...\n#\u003e Level 8 Wavelet Coefficients\n#\u003e  -50.81154 1.13322 ...\n\n# Plot of Discrete Wavelet Coefficients\nplot(Xt.dwt)\n```\n\n\u003cdiv class=\"figure\" style=\"text-align: center\"\u003e\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-5-1.png\" alt=\"Discrete Wavelet Transform (DWT) for scales 1 to 4 for a simulated Gaussian white noise.\"  /\u003e\n\u003cp class=\"caption\"\u003e\nDiscrete Wavelet Transform (DWT) for scales 1 to 4 for a simulated\nGaussian white noise.\n\u003c/p\u003e\n\n\u003c/div\u003e\n\n### Maximum Overlap Discrete Wavelet Transformation (MODWT)\n\nCompared to the DWT, the MODWT applies the wavelet filter to overlapping\nwindows of the time series (more specifically it slides the filter by\none observation at a time). As for the DWT, the functions to perform the\nMODWT are below.\n\n``` r\n# MODWT\nXt.modwt = modwt(Xt)\n\n# Summary of Maximum Overlap Discrete Wavelet Coefficients \nsummary(Xt.modwt)\n#\u003e \n#\u003e Results of MODWT using haar filter with 9 levels:\n#\u003e Displaying only the first 6 coefficients...\n#\u003e Level 1 Wavelet Coefficients\n#\u003e  -0.6562798 0.397592 0.1350352 -0.1386532 -0.2830119 -0.9393291 ...\n#\u003e Level 2 Wavelet Coefficients\n#\u003e  0.1369697 0.2645046 -0.2126415 -0.822003 -1.397533 -1.344998 ...\n#\u003e Level 3 Wavelet Coefficients\n#\u003e  -0.8429231 -1.362249 -2.044266 -1.991537 -1.571604 -0.827054 ...\n#\u003e Level 4 Wavelet Coefficients\n#\u003e  -1.570749 -1.175945 -0.7167598 -0.3172241 -0.04720348 0.01135659 ...\n#\u003e Level 5 Wavelet Coefficients\n#\u003e  -1.774519 -1.731545 -1.702113 -1.711879 -1.649612 -1.530804 ...\n#\u003e Level 6 Wavelet Coefficients\n#\u003e  -2.885532 -2.821419 -2.829503 -2.839451 -2.783538 -2.726905 ...\n#\u003e Level 7 Wavelet Coefficients\n#\u003e  -3.065437 -3.069304 -3.063743 -3.03344 -2.997907 -2.955661 ...\n#\u003e Level 8 Wavelet Coefficients\n#\u003e  -3.175721 -3.114701 -3.064177 -3.0097 -2.956361 -2.910441 ...\n#\u003e Level 9 Wavelet Coefficients\n#\u003e  -6.967706 -6.925613 -6.884283 -6.838645 -6.79024 -6.735489 ...\n\n# Plot of Maximum Overlap Discrete Wavelet Coefficients\nplot(Xt.modwt, index = \"all\")\n```\n\n\u003cdiv class=\"figure\" style=\"text-align: center\"\u003e\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-6-1.png\" alt=\"Maximum Overlap Discrete Wavelet Transform  (MODWT) for scales 1 to 9 for a simulated Gaussian white noise.\"  /\u003e\n\u003cp class=\"caption\"\u003e\nMaximum Overlap Discrete Wavelet Transform (MODWT) for scales 1 to 9 for\na simulated Gaussian white noise.\n\u003c/p\u003e\n\n\u003c/div\u003e\n\n### Wavelet Variance\n\nIf the interest of the user lies solely in the wavelet variance (issued\nfrom either DWT or MODWT), then the package provides functions that\ndirectly compute this quantity and deliver the tools necessary to\nanalyse it (confidence intervals and plots). Below is a code that\nsimulates a white noise and a random walk process and directly plots\ntheir respective wavelet variances in a log-log plot applying the\n`plot()` function to the package function `wvar()`.\n\n``` r\n# Set seed for reproducibility \nset.seed(999)\n\n# Simulate Gaussian White noise\nn = 10^4\nXt = gen_gts(n = n, model = WN(sigma2 = 1))\n\n# Simulate Gaussian Random walk\nYt = gen_gts(n = n, model = RW(gamma2 = 1))\n\n# Plot WV\npar(mfrow = c(1,2), mar = c(4,5,1,1))\nplot(wvar(Xt), main = \"White noise\")\nplot(wvar(Yt), main = \"Random walk\", legend_position = NULL)\n```\n\n\u003cdiv class=\"figure\" style=\"text-align: center\"\u003e\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-7-1.png\" alt=\"Wavelet variance of two simulated processes, i.e white noise (left panel) and random walk (right panel).\"  /\u003e\n\u003cp class=\"caption\"\u003e\nWavelet variance of two simulated processes, i.e white noise (left\npanel) and random walk (right panel).\n\u003c/p\u003e\n\n\u003c/div\u003e\n\nAs indicated in the legends, the light shaded blue area represents the\n95% confidence intervals for each scale of estimated wavelet variance.\nHowever, there could be many practical settings where the time series\ncan suffer from some “contamination” (e.g. outliers) which can seriously\nbias the standard estimator of wavelet variance. The code below randomly\nreplaces one percent of the observations from the above simulated random\nwalk with observations from a white noise process with larger variance.\n\n``` r\n# Add contamination\ngamma = 0.01\nYt2 = Yt\nYt2[sample(1:n,round(gamma*n))] = rnorm(round(gamma*n),0,5)\npar(mfrow = c(1,2), mar = c(4,5,1,1))\nrobust_eda(Yt, main = \"RW without contamination\")\nrobust_eda(Yt2, legend_position = NULL, main = \"RW with contamination\")\n```\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-8-1.png\" style=\"display: block; margin: auto;\" /\u003e\n\nIt can be seen how the classic and robust wavelet variance estimates\nagree when there is no contamination (left plot) but they classic\nestimates are heavily biased (especially at the first more informative\nscales) when the random walk has only 1% contamination.\n\nWhen dealing with different time series, it is possible to compare their\nrespective wavelet variances to understand if they have similar\nbehaviour/properties. An example is given below where four different\nfirst-order autoregressive processes (with different values of the\nautoregressive parameters) are simulated and succesively their wavelet\nvariance is computed.\n\n``` r\n# Simulate AR processes\nn = 10^5\nXt = gen_gts(n = n, model = AR1(phi = 0.10, sigma2 = 1))\nYt = gen_gts(n = n, model = AR1(phi = 0.35, sigma2 = 1))\nZt = gen_gts(n = n, model = AR1(phi = 0.79, sigma2 = 1))\nWt = gen_gts(n = n, model = AR1(phi = 0.95, sigma2 = 1))\n\n# Compute WV\nwv_Xt = wvar(Xt)\nwv_Yt = wvar(Yt)\nwv_Zt = wvar(Zt)\nwv_Wt = wvar(Wt)\n\n# Plot results\ncompare_wvar(wv_Xt, wv_Yt, wv_Zt, wv_Wt)\n```\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-9-1.png\" style=\"display: block; margin: auto;\" /\u003e\n\nAs seen above, the function `compare_wvar()` allows to plot different\noutputs of the `wvar()` function and it can be seen how the four time\nseries deliver different wavelet variances (as the autoregressive\nparameter approaches zero, the shape of the wavelet variance plot\napproaches the behaviour of the wavelet variance of a white noise\nprocess).\n\n### Wavelet Variance on IMU Data\n\nIn the package, we also add some datasets which are the wavelet variance\ncomputed based on real IMU data. Currently the package includes datasets\n`adis_wv`, `imar_wv`, `kvh1750_wv`, `ln200_wv` and `navchip_av`. We can\nplot these wavelet variance simply with the `plot` function. As an\nexample:\n\n``` r\ndata(\"kvh1750_wv\")\nplot(kvh1750_wv)\n```\n\n\u003cimg src=\"man/figures/README-unnamed-chunk-10-1.png\" style=\"display: block; margin: auto;\" /\u003e\n\n# User Guides\n\nVarious guides ship with package or are available on\n\u003chttps://smac-group.com/\u003e to provide insight into how to use the\ndifferent methods. At the present time, the following vignettes are\navailable:\n\n1.  Process to Haar Wavelet Variance\n    [(Online)](https://smac-group.com/computing/2016/05/23/process-to-haar-wavelet-variance-formulae.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmac-group%2Fwv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmac-group%2Fwv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmac-group%2Fwv/lists"}