{"id":25109994,"url":"https://github.com/smac-group/gmwm","last_synced_at":"2025-10-11T19:42:51.155Z","repository":{"id":23503469,"uuid":"26869159","full_name":"SMAC-Group/gmwm","owner":"SMAC-Group","description":"Generalized Method of Wavelet Moments (GMWM) is an estimation technique for the parameters of time series models. It uses the wavelet variance in a moment matching approach that makes it particularly suitable for the estimation of certain state-space models.","archived":false,"fork":false,"pushed_at":"2023-12-01T10:58:29.000Z","size":53132,"stargazers_count":30,"open_issues_count":71,"forks_count":15,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-22T10:23:02.098Z","etag":null,"topics":["armadillo","r","rcpp","robust","time-series","wavelet-variance"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SMAC-Group.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-11-19T16:02:00.000Z","updated_at":"2025-01-05T13:09:28.000Z","dependencies_parsed_at":"2023-12-01T12:17:38.605Z","dependency_job_id":"cd21d6a3-9ab8-4938-b4ac-bedbcb9093a6","html_url":"https://github.com/SMAC-Group/gmwm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/SMAC-Group/gmwm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fgmwm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fgmwm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fgmwm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fgmwm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SMAC-Group","download_url":"https://codeload.github.com/SMAC-Group/gmwm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SMAC-Group%2Fgmwm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270580001,"owners_count":24610124,"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","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["armadillo","r","rcpp","robust","time-series","wavelet-variance"],"created_at":"2025-02-08T00:34:12.176Z","updated_at":"2025-10-11T19:42:46.135Z","avatar_url":"https://github.com/SMAC-Group.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\nbibliography: references.bib\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r, echo=FALSE, message=FALSE, warning=FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  dpi = 300,\n  out.width = \"100%\",\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\"\n)\n\nlibrary(gmwm)\n```\n\n[![Travis-CI Build Status](https://travis-ci.org/SMAC-Group/gmwm.svg?branch=master)](https://travis-ci.org/SMAC-Group/gmwm)\n[![Project Status: Active](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)\n[![Licence](https://img.shields.io/badge/licence-AGPL--3.0-blue.svg)](https://opensource.org/licenses/AGPL-3.0)\n[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.4.0-6666ff.svg)](https://cran.r-project.org/)\n[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/gmwm)](http://www.r-pkg.org/pkg/gmwm)\n[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/grand-total/gmwm)](http://www.r-pkg.org/pkg/gmwm)\n[![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](https://github.com/SMAC-Group/gmwm)\n\n\n# `gmwm` R Package \u003ca href=\"https://data-analytics-lab.net/\"\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" alt=\" \" width=\"230\"\u003e\u003c/a\u003e\n\nThis repository holds the Generalized Method of Wavelet Moments (GMWM) R package. This estimation technique was introduces in @guerrier2013wavelet and uses the wavelet variance in a moment-matching spirit to estimate parameters of time series models such as ARMA or state-space models. \n\nThe GMWM was initially motivated by the need to estimate the parameters of complex state-space models used in various engineering applications. In short, this approach uses the quantity called Wavelet Variance (WV) in the spirit of a GMM estimator. This method is often the only feasible estimation approach that can be applied for complex models which are used in engineering and natural sciences. In particular, the GMWM is computationally efficient and, unlike most likelihood-based techniques, it can be applied to massive time dependent datasets which are becoming increasingly common. For example, one of the first applications of this method was in the field of engineering where the GMWM was used to solve \"sensor calibration\" problems which are of great interest in different domains such as Aerospace, Robotics or Geomatics and entails large amounts of data (typically tens of millions of observations). In this context the GMWM has been demonstrated to represent a considerable improvement compared to benchmark methods [see e.g. @stebler2014generalized for details] both in terms of statistical accuracy and computational efficiency. \n\nBuilding on the generality and flexibility of the GMWM, the estimation framework was enlarged to also include robust estimators, leading to a robust version of GMWM (RGMWM), in @guerrier2020robust. Due to its computational efficiency, the GMWM is able to easily estimate complex time series and spatial models in circumstances where traditional methods have considerable computational and numerical issues, adding the robust estimation layer with only a marginal increase in computational complexity.\n\nBelow are examples of the features of the `gmwm` package.\n\nTo start, let's generate a time series from a simple model, which is a AR(1) process with measurement error (white noise):\n\n```{r}\n# Sample size\nn = 10^4\n\n# Specify model\nmodel = AR1(phi = .98, sigma2 = .02) + WN(sigma2 = 1)\n\n# Generate Data\nXt = gen_gts(n = n, model = model)\n```\n\nOnce we have data, we can see what the wavelet variance looks like:\n\n```{r, fig.align='center', fig.width=4, fig.height=3}\n# Compute Haar WV\nwv_Xt = wvar(Xt)\nplot(wv_Xt)\n```\n\n```{r, eval = F}\nwv_Yt = wvar(Yt)\nIn the second time series, we introduce a few (1%) of \"extreme\" (outliers):\n# Copy data and add \"outliers\"\nYt = Xt\nYt[sample(1:n, round(0.01*n))] = rnorm(round(0.01*n), 0, 3^2)\n\n# Plot the data\nplot(wv.classical)\n\n# Calculate robust wavelet variance\nwv.robust = wvar(d, robust = TRUE, eff = 0.6)\n\n# Compare both versions\ncompare_wvar(wv.classical, wv.robust)\n```\n\nNow, let's try to estimate it with specific (e.g. user supplied) and guessed (e.g. program generated) parameters.\n\n```{r, eval = F}\n## Estimation Modes ##\n\n# Use a specific initial starting value\no.specific = gmwm_imu(AR1(phi=.98,sigma2=.05) + WN(sigma2=.95), data = d)\n\n# Let the program guess a good starting value\no.guess = gmwm_imu(AR1()+WN(), data = d)\n```\n\nTo run inference or view the parameter estimates, we do:\n\n```{r, eval = F}\n## View Model Info ##\n\n# Standard summary\nsummary(o.specific)\n\n# View with asymptotic inference\nsummary(o.specific, inference = T)\n\n# View with bootstrapped inference\nsummary(o.specific, inference = T, bs.gof = T)\n```\n\nAlternatively, we can let the program try to figure out the best model for the data using the Wavelet Information Criteria (WIC):\n\n```{r, eval = F}\n## Model selection ##\n\n# Separate Models - Compares 2*AR1() and AR1() + WN() under common model 2*AR1() + WN()\n# Note: This function created a shared model (e.g. 2*AR1() + WN()) if not supplied to obtain the WIC. \nms.sep = rank_models(AR1()+WN(), 2*AR1(), data = d, model.type=\"imu\")\n\n# Nested version - Compares AR1() + WN(), AR1(), WN()\nms.nested = rank_models(AR1()+WN(), data = d, nested = TRUE, model.type = \"imu\")\n\n# Bootstrapped Optimism\nms.bs = rank_models(AR1()+WN(), WN(), data = d, bootstrap = TRUE, model.type = \"imu\")\n\n# See automatic selection fit\nplot(ms.sep)\n\n# View model picked:\nsummary(ms.sep)\n```\n\nLast, but certainly not least, we can also approximate a contaminated sample with robust methodology:\n\n```{r, eval = F}\n## Data generation ##\n# Specify model\nmodel = AR1(phi = .99, sigma2 = .01) + WN(sigma2 = 1)\n\n# Generate Data\nset.seed(213)\nN = 1e3\nsim.ts = gen_gts(n, model)\n\n# Contaminate Data\ncont.eps = 0.01\ncont.num = sample(1:N, round(N*cont.eps))\nsim.ts[cont.num,] = sim.ts[cont.num,] + rnorm(round(N*cont.eps),0,sqrt(100))\n\n# Plot the data\nplot(sim.ts)\n\n# Classical Wavelet Variance\nwv.classic = wvar(sim.ts)\n\n# Robust Wavelet Variance\nwv.robust = wvar(sim.ts, robust = TRUE, eff = 0.6)\n\n# Plot the Classical vs. Robust WV\ncompare_wvar(wv.classic, wv.robust, split = FALSE)\n\n# Run robust estimation\no = gmwm_imu(model, sim.ts, robust = TRUE, eff = 0.6)\n\n# Robust information\nsummary(o)\n```\n\n\n## Installing the package through CRAN (Stable)\nThe installation process with CRAN is the simplest\n\n```{r, eval = F}\ninstall.packages(\"gmwm\")\n```\n\nInstalling the package this way gives you access to stable features. Furthermore, the installation itself does not require a compiler or preinstalling any dependencies. However, we are limited to updating the package on CRAN to once every month. Thus, there may be some lag between when features are developed and when they are available on this version.\n\n## Installing the package through GitHub (Developmental)\n\nFor users who are interested in having the latest and greatest developments withing wavelets or GMWM methodology, this option is ideal. Though, there is considerably more work that a user must do to have a stable version of the package. **The setup to obtain the development version is platform dependent.**\n\nSpecifically, one **must** have a compiler installed on your system that is compatible with R.\n\nFor help on obtaining a compiler consult:\n\n* [OS X](http://thecoatlessprofessor.com/programming/r-compiler-tools-for-rcpp-on-os-x/)\n* [Windows](https://cran.r-project.org/bin/windows/Rtools/)\n\nDepending on your operating system, further requirements exist such as:\n\n**OS X**\n\nSome user report the need to use X11 to suppress shared library errors. To install X11, visit [xquartz.org](http://www.xquartz.org/)\n\n**Linux**\n\nBoth curl and libxml are required.\n\nFor **Debian** systems, enter the following in terminal:\n\n```{r, eval = F, engine='bash'}\nsudo apt-get install curl libcurl3 libcurl3-dev libxml2 libxml2-dev\n```\n\nFor **RHEL** systems, enter the following in terminal:\n\n```{r, eval = F, engine='bash'}\nsudo yum install curl curl-devel libxml2 libxml2-dev\n```\n\n**All Systems**\n\nWith the system dependency taken care of, we continue on by installing the R specific package dependencies and finally the package itself by doing the following in an R session: \n\n```{r, eval = F}\n# Install dependencies\ninstall.packages(c(\"RcppArmadillo\",\"ggplot2\",\"reshape2\",\"devtools\",\"knitr\",\"rmarkdown\"))\n\n# Install the package from GitHub without Vignettes/User Guides\ndevtools::install_github(\"SMAC-Group/gmwm\")\n\n# Install the package from GitHub with Vignettes/User Guides\n# Note: This will be a longer install as the vignettes must be built.\ndevtools::install_github(\"SMAC-Group/gmwm\", build_vignettes = TRUE)\n```\n\n# Licensing\n\nThe license this source code is released under is the GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) v3.0. In some cases, the GPL license does apply. However, in the majority of the cases, the license in effect is the GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) v3.0 as the computational code is heavily dependent on Armadilllo, which use the MPL license that enables us to recast our code to use the GNU AFFERO GENERAL PUBLIC LICENSE (AGPL) v3.0. See the LICENSE file for full text. Otherwise, please consult [TLDR Legal](https://tldrlegal.com/license/gnu-affero-general-public-license-v3-(agpl-3.0)) or [GNU](https://www.gnu.org/licenses/agpl-3.0.en.html) which will provide a synopsis of the restrictions placed upon the code. Please note, this does NOT excuse you from talking about licensing with a lawyer!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmac-group%2Fgmwm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmac-group%2Fgmwm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmac-group%2Fgmwm/lists"}