BootUR
R Package for Bootstrap Unit Root Tests
Install / Use
/learn @smeekes/BootURREADME
bootUR: Bootstrap Unit Root Tests
<!-- badges: start --> <!-- badges: end -->The R package bootUR implements several bootstrap tests for unit
roots, both for single time series and for (potentially) large systems
of time series.
Installation and Loading
Installation
The package can be installed from CRAN using
install.packages("bootUR")
The development version of the bootUR package can be installed from
GitHub using
# install.packages("devtools")
devtools::install_github("smeekes/bootUR")
When installing from GitHub, in order to build the package from source, you need to have the appropriate R development tools installed (Rtools on Windows, or these tools on Mac).
If you want the vignette to appear in your package when installing from GitHub, use
# install.packages("devtools")
devtools::install_github("smeekes/bootUR", build_vignettes = TRUE, dependencies = TRUE)
instead. As building the vignette may take a bit of time (all bootstrap code below is run), package installation will be slower this way.
Load Package
After installation, the package can be loaded in the standard way:
library(bootUR)
Preliminary Analysis: Missing Values
bootUR provides a few simple tools to check if your data are suitable
to be bootstrapped.
Inspect Data for Missing Values
The bootstrap tests in bootUR do not work with missing data, although
multivariate time series with different start and end dates (unbalanced
panels) are allowed. bootUR provides a simple function to check if
your data contain missing values. We will illustrate this on the
MacroTS dataset of macroeconomic time series that comes with the
package.
data("MacroTS")
check_missing_insample_values(MacroTS)
#> GDP_BE GDP_DE GDP_FR GDP_NL GDP_UK CONS_BE CONS_DE CONS_FR CONS_NL CONS_UK
#> FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
#> HICP_BE HICP_DE HICP_FR HICP_NL HICP_UK UR_BE UR_DE UR_FR UR_NL UR_UK
#> FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
Checking Start and End Points of Time Series
If your time series have different starting and end points (and thus
some series contain NAs at the beginning and/or end of your sample,
the resampling-based moving block bootstrap (MBB) and sieve bootstrap
(SB) cannot be used. bootUR lets you check the start and end points as
follows:
sample_check <- find_nonmissing_subsample(MacroTS)
# Provides the number of the first and last non-missing observation for each series:
sample_check$range
#> GDP_BE GDP_DE GDP_FR GDP_NL GDP_UK CONS_BE CONS_DE CONS_FR CONS_NL
#> first 1 1 1 5 1 1 1 1 5
#> last 100 100 100 100 100 100 100 100 100
#> CONS_UK HICP_BE HICP_DE HICP_FR HICP_NL HICP_UK UR_BE UR_DE UR_FR UR_NL
#> first 1 9 9 9 9 9 1 1 1 1
#> last 100 100 100 100 100 100 100 100 100 100
#> UR_UK
#> first 1
#> last 100
# Gives TRUE if the time series all start and end at the same observation:
sample_check$all_equal
#> [1] FALSE
Visualizing Missing Data
If you have ggplot2 installed, you can also plot the missing data
patterns in your series to get a quick overview. You may need to
manipulate some arguments to get the plot properly sized (therefore it
is not run here automatically).
plot_missing_values(MacroTS, show_names = TRUE, axis_text_size = 5, legend_size = 6)
Augmented Dickey-Fuller Test
As the standard test for unit roots, bootUR also has an implementation
of the standard, non-bootstrap, augmented Dickey-Fuller (ADF) test
(though its use is not recommended if sample sizes are small). For this
purpose the adf() function can be used. The function allows to set
many options. First, one can choose between the classical single-step
procedure (two_step = FALSE), in which deterministic components are
directly included in the test regression, and the more flexible and
modern two-step procedure (two_step = TRUE) where deterministic
components are first removed before applying the unit root test to
detrended data. For the standard ADF test, the two specifications
generally yield nearly identical results.
Lag selection
Lag length selection is done automatically in the ADF regression; the
default is by the modified Akaike information criterion (MAIC) proposed
by Ng and Perron (2001) with the correction of Perron and Qu (2008).
Other options include the regular Akaike information criterion (AIC), as
well as the Bayesian information criterion and its modified variant. In
addition, the rescaling suggested by Cavaliere et al. (2015) is
implemented to improve the power of the test under heteroskedasticity;
this can be turned off by setting criterion_scale = FALSE. To
overwrite data-driven lag length selection with a pre-specified lag
length, simply set both the minimum min_lag and maximum lag length
max_lag for the selection algorithm equal to the desired lag length.
Implementation
We illustrate the ADF test here on Dutch GDP for the two-step specification, including a linear trend in the specification.
GDP_NL <- MacroTS[, 4]
adf(GDP_NL, deterministics = "trend")
#>
#> Two-step ADF test (with trend) on a single time series
#>
#> data: GDP_NL
#> null hypothesis: Series has a unit root
#> alternative hypothesis: Series is stationary
#>
#> estimate largest root statistic p-value
#> GDP_NL 0.9471 -2.515 0.3202
Univariate Bootstrap Unit Root Tests
Augmented Dickey-Fuller Test
To perform a bootstrap version of the ADF unit root test on a single
time series, use the boot_adf() function. The function allows to set
many options, including the bootstrap method used (option bootstrap),
the deterministic components included (option deterministics) and the
type of detrending used (option detrend). While detrend = "OLS"
gives the standard ADF test, detrend = "QD" provides the powerful
DF-GLS test of Elliott, Rothenberg and Stock (1996). Here we use the
terminology Quasi-Differencing (QD) rather than GLS as this conveys the
meaning less ambiguously and is the same terminology used by Smeekes and
Taylor (2012) and Smeekes (2013). In all cases, two-step detrending is
used.
Implementation
We illustrate the bootstrap ADF test here on Dutch GDP, with the sieve
bootstrap (bootstrap = SB) as in the specification used by Palm,
Smeekes and Urbain (2008) and Smeekes (2013). To get the well-known test
proposed by Paparoditis and Politis (2003), set bootstrap = "MBB". We
set only 399 bootstrap replications (B = 399) to prevent the code from
running too long. We add an intercept and a trend
(deterministics = "trend") and OLS detrending. The console gives you
live updates on the bootstrap progress. To turn these off, set
show_progress = FALSE. The bootstrap loop can be run in parallel by
setting do_parallel = TRUE (the default).
As random number generation is required to draw bootstrap samples, we first set the seed of the random number generator to obtain replicable results.
set.seed(155776)
boot_adf(GDP_NL, B = 399, bootstrap = "SB", deterministics = "trend",
detrend = "OLS", do_parallel = FALSE)
#> Progress: |------------------|
#> ********************
#>
#> SB bootstrap OLS test (with intercept and trend) on a single time
#> series
#>
#> data: GDP_NL
#> null hypothesis: Series has a unit root
#> alternative hypothesis: Series is stationary
#>
#> estimate largest root statistic p-value
#> GDP_NL 0.9471 -2.515 0.1454
Union of Rejections Test
Use boot_union() for a test based on the union of rejections of 4
tests with different number of deterministic components and different
type of detrending (Smeekes and Taylor, 2012). The advantage of the
union test is that you don’t have to specify these (rather influential)
specification tests. This makes the union test a safe option for quick
or automatic unit root testing where careful manual specification setup
is not viable. Here we illustrate it with the sieve wild bootstrap as
proposed by Smeekes and Taylor (2012).
boot_union(GDP_NL, B = 399, bootstrap = "SWB", do_parallel = FALSE)
#> Progress: |------------------|
#> ********************
#>
#> SWB bootstrap union test on a single time series
#>
#> data: GDP_NL
#> null hypothesis: Series has a unit root
#> alternative hypothesis: Series is stationary
#>
#> estimate largest root statistic p-value
#> GDP_NL NA -0.7115 0.614
Panel Unit Root Test
The function boot_panel performs a test on a multivariate (panel) time
series by testing the null hypothesis that all series have a unit root.
A rejection is typically interpreted as evidence that a ‘significant
proportion’ of the series is stationary, although how large that
proportion is - or which series are stationary - is not given by the
test. The test is based on averagi
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
