Transparent unit-root testing in R: one interface for classical unit-root and stationarity tests, plus deterministic-specification strategies that record every step of the decision. Developed for Applied Time Series Econometrics (ATSE) at Universidad Carlos III de Madrid; companion to the Python package UnitRoot-Tools.
Status: teaching version (v0.3.2). The functions listed under What it does are implemented and validated. Interfaces may still change before version 1.0.
The package is installed from GitHub. In R (or RStudio), run once:
install.packages("remotes")
remotes::install_github("maarranz/UnitRoot-Tools-R", build_vignettes = TRUE)build_vignettes = TRUE also builds the tutorial described below. It needs
pandoc, which comes with RStudio. If you do not use
RStudio and do not have pandoc, install without the vignette (it can be read
on the web):
remotes::install_github("maarranz/UnitRoot-Tools-R")or, equivalently, with pak:
install.packages("pak")
pak::pak("maarranz/UnitRoot-Tools-R")To update to the latest version, run the same command again. To install a
fixed release instead, add its tag, e.g.
remotes::install_github("maarranz/UnitRoot-Tools-R@v0.3.4", build_vignettes = TRUE)
(releases are listed in NEWS.md). The package needs
R 4.1 or later; its only non-base dependency,
generics, is installed automatically.
- On the web (nothing to build): the API reference (source) and the vignette, a tutorial that goes through all the functions with Enders' U.S. real GDP example.
- In R: help on each function, e.g.
?adfor?ur_strategy, and, if you installed withbuild_vignettes = TRUE,vignette("unitroottools").
library(unitroottools)
gdp <- read.csv(system.file("fixtures", "enders_rgdp.csv", package = "unitroottools"))
lgdp <- ts(log(gdp$rgdp), start = c(1947, 1), frequency = 4)
adf(lgdp, trend = "ct") # ADF test, lags chosen by MAIC
summary(adf(lgdp, trend = "ct")) # sources, phi statistics, lag table
ur_strategy(lgdp, "original", lags = 1) # Enders' testing sequence
ur_strategy(lgdp, "hamilton", trending = TRUE) # your judgement, then one testEvery result states the hypotheses in words, the deterministic terms, how many lags were used and how they were chosen, the effective sample, the critical values and where they come from, and the decision.
| Function | Purpose |
|---|---|
adf() |
Augmented Dickey-Fuller test: τ statistic and the φ statistics, each with critical values and p-value |
select_lags() |
Lag order by AIC, BIC, MAIC or MBIC, all candidates on the same sample, with the full table |
union_test() |
Union of rejections (Harvey-Leybourne-Taylor): ADF and DF-GLS, with constant and with trend, one test of known size when the deterministic terms are uncertain; own finite-sample critical values and p-value |
ur_strategy() |
Choosing the deterministic terms: "original" (Dolado-Jenkinson-Sosvilla-Rivero / Enders), "conservative", "hamilton"; full history of every step |
pp() |
Phillips-Perron Z_τ test, with its p-value, and Z_α with its own critical values |
kpss() |
KPSS test, with stationarity as the null hypothesis; critical values and p-value from its limiting distribution, computed numerically |
dfgls() |
DF-GLS test (Elliott-Rothenberg-Stock), lags chosen by MAIC as recommended by Perron and Qu (2007), with finite-sample critical values and p-value from the package's own simulation |
ng_perron() |
Ng-Perron M tests (MZ_α, MZ_t, MSB, MP_T) on GLS-detrended data, lags by MAIC (Perron and Qu, 2007), own finite-sample critical values and p-value |
ers_pt() |
Elliott-Rothenberg-Stock point-optimal test P_T, same conventions |
boot_ur() |
Bootstrap ADF and union-of-rejections tests through the bootUR package (optional; p-value only) |
residual_check() |
Are the residuals of the test regression white noise? Correlogram (AC, PAC, Ljung-Box Q) and Breusch-Godfrey test, with a plot; lags follow the frequency of the data |
recursive_adf() |
Recursive (fixed start) or rolling ADF statistics against pointwise critical values, with a plot |
tidy(), glance() |
Results as one-row-per-statistic or one-row-per-test data frames, easy to combine across series |
simulate_df() |
Monte Carlo of the Dickey-Fuller distribution, with a plot against N(0,1) |
Details that matter in practice:
- Critical values. τ (and Z_τ), the φ statistics, DF-GLS, the
Ng-Perron and ERS tests, Z_α and the union test use this package's own finite-sample
response surfaces in the sample size and the number of lags, estimated by
Monte Carlo (code in
data-raw/); critical values and p-values come from the same surface. Without lags the τ values agree with MacKinnon's (2010), which are shown for comparison. KPSS uses its limiting distribution. Every result records its source and has a p-value. - Lags. Chosen over 0, ..., kmax with kmax = ⌊12(T/100)^¼⌋ (Schwert), all
candidates on the same sample; the test regression is then estimated on all
the observations available for the chosen order (
final_sample = "common"keeps the selection sample). - Strategies. The history separates rejections of the unit root from rejections that only decide the path (the φ tests and the tests of the deterministic terms). No p-value is reported for a whole sequence, because its size is not known. Hamilton's rule has no default: you must declare whether the series is trending.
- Data. Numeric vectors,
ts,zoo,xts, data frames, tibbles and tsibbles; with several columns, choose one withvar = "name". Missing values are never dropped silently. - Validation. Statistics are checked against independent
lm()computations and urca, against 120-digit reference calculations shared with the Python package, critical values against statsmodels, and the strategies against Enders' published GDP example. - Long-run variance (for
pp()andkpss()): Bartlett, Parzen or Quadratic Spectral kernel; Schwert's rules, a fixed number of autocovariances, or automatic bandwidths (Andrews, Newey-West). - What is computed elsewhere. Only
boot_ur(), which delegates the statistic and the bootstrap to bootUR. Everything else, including every test statistic, critical value and p-value, is computed by the package. - Approximations. KPSS critical values are asymptotic (from the limiting distribution, computed numerically). Phillips-Perron uses the finite-sample Dickey-Fuller distributions, which share the limits of Z_τ and Z_α but not their finite-sample distributions under serial correlation. Own calibrations are for a fixed lag order; with selected lags (the default), the size of the whole procedure can differ (e.g. about 3-4% instead of 5% with MAIC at T = 100).
| Phase | Content |
|---|---|
| v0.4: bootstrap | Own bootstrap engine (sieve, wild sieve, stationary and moving block schemes), able to bootstrap any statistic, including a whole testing strategy |
| v0.5: specification uncertainty | Monte Carlo tools (size, power, branch frequencies); bootstrap union test (own engine); bootstrap-calibrated strategies; Hamilton's Case 3 (drift under the null), introduced with the Monte Carlo tools |
| v0.6: robustness | Unit-root tests robust to additive outliers; tests allowing for structural breaks |
The econometric conventions (statistics, lag selection, critical values, the
result format and the strategies) are defined in a language-neutral
specification, spec/specification.qmd, shared with
the Python package UnitRoot-Tools. The two packages are independent
implementations of that specification and are validated against shared
numerical fixtures (inst/fixtures).
MIT © Miguel A. Arranz