Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

R Package for Bootstrap Unit Root Tests

License

NotificationsYou must be signed in to change notification settings

smeekes/bootUR

Repository files navigation

CRAN_Version_BadgeCRAN_Downloads_BadgeLicense_GPLv2_BadgeLicense_GPLv3_BadgeR-CMD-check

The R packagebootUR implements several bootstrap tests for unitroots, both for single time series and for (potentially) large systemsof time series.

Installation and Loading

Installation

The package can be installed from CRAN using

install.packages("bootUR")

The development version of thebootUR package can be installed fromGitHub 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, orthese tools on Mac).

If you want the vignette to appear in your package when installing fromGitHub, 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 bootstrapcode 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 suitableto be bootstrapped.

Inspect Data for Missing Values

The bootstrap tests inbootUR do not work with missing data, althoughmultivariate time series with different start and end dates (unbalancedpanels) are allowed.bootUR provides a simple function to check ifyour data contain missing values. We will illustrate this on theMacroTS dataset of macroeconomic time series that comes with thepackage.

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 thussome series containNAs 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 asfollows:

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 haveggplot2 installed, you can also plot the missing datapatterns in your series to get a quick overview. You may need tomanipulate some arguments to get the plot properly sized (therefore itis 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 implementationof the standard, non-bootstrap, augmented Dickey-Fuller (ADF) test(though its use is not recommended if sample sizes are small). For thispurpose theadf() function can be used. The function allows to setmany options. First, one can choose between the classical single-stepprocedure (two_step = FALSE), in which deterministic components aredirectly included in the test regression, and the more flexible andmodern two-step procedure (two_step = TRUE) where deterministiccomponents are first removed before applying the unit root test todetrended data. For the standard ADF test, the two specificationsgenerally yield nearly identical results.

Lag selection

Lag length selection is done automatically in the ADF regression; thedefault is by the modified Akaike information criterion (MAIC) proposedby Ng and Perron (2001) with the correction of Perron and Qu (2008).Other options include the regular Akaike information criterion (AIC), aswell as the Bayesian information criterion and its modified variant. Inaddition, the rescaling suggested by Cavaliere et al. (2015) isimplemented to improve the power of the test under heteroskedasticity;this can be turned off by settingcriterion_scale = FALSE. Tooverwrite data-driven lag length selection with a pre-specified laglength, simply set both the minimummin_lag and maximum lag lengthmax_lag for the selection algorithm equal to the desired lag length.

Implementation

We illustrate the ADF test here on Dutch GDP for the two-stepspecification, 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 singletime series, use theboot_adf() function. The function allows to setmany options, including the bootstrap method used (optionbootstrap),the deterministic components included (optiondeterministics) and thetype of detrending used (optiondetrend). Whiledetrend = "OLS"gives the standard ADF test,detrend = "QD" provides the powerfulDF-GLS test of Elliott, Rothenberg and Stock (1996). Here we use theterminology Quasi-Differencing (QD) rather than GLS as this conveys themeaning less ambiguously and is the same terminology used by Smeekes andTaylor (2012) and Smeekes (2013). In all cases, two-step detrending isused.

Implementation

We illustrate the bootstrap ADF test here on Dutch GDP, with the sievebootstrap (bootstrap = SB) as in the specification used by Palm,Smeekes and Urbain (2008) and Smeekes (2013). To get the well-known testproposed by Paparoditis and Politis (2003), setbootstrap = "MBB". Weset only 399 bootstrap replications (B = 399) to prevent the code fromrunning too long. We add an intercept and a trend(deterministics = "trend") and OLS detrending. The console gives youlive updates on the bootstrap progress. To turn these off, setshow_progress = FALSE. The bootstrap loop can be run in parallel bysettingdo_parallel = TRUE (the default).

As random number generation is required to draw bootstrap samples, wefirst set the seed of the random number generator to obtain replicableresults.

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

Useboot_union() for a test based on the union of rejections of 4tests with different number of deterministic components and differenttype of detrending (Smeekes and Taylor, 2012). The advantage of theunion test is that you don’t have to specify these (rather influential)specification tests. This makes the union test a safe option for quickor automatic unit root testing where careful manual specification setupis not viable. Here we illustrate it with the sieve wild bootstrap asproposed 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 functionboot_panel performs a test on a multivariate (panel) timeseries by testing the null hypothesis that all series have a unit root.A rejection is typically interpreted as evidence that a ‘significantproportion’ of the series is stationary, although how large thatproportion is - or which series are stationary - is not given by thetest. The test is based on averaging the individual test statistics,also called the Group-Mean (GM) test in Palm, Smeekes and Urbain (2011).

Palm, Smeekes and Urbain (2011) introduced this test with the movingblock bootstrap (bootstrap = "MBB"). However, this resampling-basedmethod cannot handle unbalancedness, and will therefore give an errorwhen applied toMacroTS:

boot_panel(MacroTS,bootstrap="MBB",B=399,do_parallel=FALSE)#> Error in check_inputs(data = data, boot_sqt_test = boot_sqt_test, boot_ur_test = boot_ur_test, : Resampling-based bootstraps MBB and SB cannot handle unbalanced series.

Therefore, you should switch to one of the wild bootstrap methods. Herewe illustrate it with the dependent wild bootstrap (DWB) of Shao (2010)and Rho and Shao (2019).

By default the union test is used for each series (union = TRUE), ifthis is set toFALSE the deterministic components and detrendingmethods can be specified as in the univariate Dickey-Fuller test.

Although the sieve bootstrap method"SB" and"SWB" can be used(historically they have been popular among practitioners), Smeekes andUrbain (2014b) show that these are not suited to capture general formsof dependence across units. The code will give a warning to recommendusing a different bootstrap method.

boot_panel(MacroTS,bootstrap="DWB",B=399,do_parallel=FALSE)#> Progress: |------------------|#>           ********************#>#>  Panel DWB bootstrap group-mean union test#>#> data: MacroTS#> null hypothesis: All series have a unit root#> alternative hypothesis: Some series are stationary#>#>         estimate largest root statistic p-value#> MacroTS                    NA   -0.8621  0.1103

Tests for Multiple Time Series

Individual ADF Tests

To perform individual ADF tests on multiple time series simultaneously,the functionboot_ur() can still be used. As the bootstrap isperformed for all series simultaneously, resampling-based bootstrapmethods"MBB" and"SB" cannot be used directly in case of unbalancedpanels. If they are used anyway, the function will revert to splittingthe bootstrap up and performing it individually per time series. In thiscase a warning is given to alert the user.

ADFtests_out<- boot_ur(MacroTS[,1:5],bootstrap="MBB",B=399,union=FALSE,deterministics="trend",detrend="OLS",do_parallel=FALSE)#> Warning in check_inputs(data = data, boot_sqt_test = boot_sqt_test,#> boot_ur_test = boot_ur_test, : Missing values cause resampling bootstrap to be#> executed for each time series individually.#> Progress: |------------------|#>           ********************print(ADFtests_out)#>#>  MBB bootstrap ADF test (with intercept and trend) on each individual#>  series (no multiple testing correction)#>#> data: MacroTS[, 1:5]#> null hypothesis: Series has a unit root#> alternative hypothesis: Series is stationary#>#> Tests performed on each series:#>        estimate largest root statistic p-value#> GDP_BE                0.9304    -2.792  0.1955#> GDP_DE                0.8911    -2.774  0.1003#> GDP_FR                0.9655    -2.049  0.5113#> GDP_NL                0.9471    -2.515  0.1930#> GDP_UK                0.9600    -2.449  0.2882

Note thatboot_ur (intentionally) does not provide a correction formultiple testing; of course, if we perform each test with a significancelevel of 5%, the probability of making a mistake in all these testsbecomes (much, ifN is large) more than 5%. To explicitly account formultiple testing, use the functionsboot_sqt() orboot_fdr().

Bootstrap Sequential Tests

The functionboot_sqt() performs the Bootstrap Sequential QuantileTest (BSQT) proposed by Smeekes (2015). Here we split the series ingroups which are consecutively tested for unit roots, starting with thegroup most likely to be stationary (having the smallest ADF statistics).If the unit root hypothesis cannot be rejected for the first group, thealgorithm stops; if there is a rejection, the second group is tested,and so on.

Most options are the same as forboot_panel. The parameterSQT_levelcontrols the significance level of the individual tests performed in thesequence, with a default value of 0.05. The other important newparameter to set here is the group sizes. These can either be set inunits, or in fractions of the total number of series (i.e. quantiles,hence the name) via the parametersteps. If we haveN time series,settingsteps = 0:N means each unit should be tested sequentially. Tosplit the series in four equally sized groups (regardless of many seriesthere are), usesteps = 0:4 / 4. By convention and in accordance withnotation in Smeekes (2015), the first entry of the vector should beequal to zero, while the second entry indicates the end of the firstgroup, and so on. However, if the initial zero is accidentally omitted,it is automatically added by the function. Similarly, if the final valueis not equal to1 (in case of quantiles) orN to end the last group,this is added by the function.

Testing individual series consecutively is easiest for interpretation,but is only meaningful ifN is small. In this case the method isequivalent to the bootstrap StepM method of Romano and Wolf (2005),which controls the familywise error rate, that is the probability ofmaking at least one false rejection. This can get very conservative ifN is large, and you would typically end up not rejecting any nullhypothesis. The method is illustrated with the autoregressive wildbootstrap of Smeekes and Urbain (2014a) and Friedrich, Smeekes andUrbain (2020).

N<- ncol(MacroTS)# Test each unit sequentiallyboot_sqt(MacroTS,steps=0:N,bootstrap="AWB",B=399,do_parallel=FALSE)#> Progress: |------------------|#>           ********************#>#>  AWB bootstrap sequential quantile union test#>#> data: MacroTS#> null hypothesis: Series has a unit root#> alternative hypothesis: Series is stationary#>#> Sequence of tests:#>        H0: # I(0) H1: # I(0)  tstat p-value#> Step 1          0          1 -1.661 0.02256#> Step 2          1          2 -1.413 0.12281# Split in four equally sized groups (motivated by the 4 series per country)boot_sqt(MacroTS,steps=0:4/4,bootstrap="AWB",B=399,do_parallel=FALSE)#> Progress: |------------------|#>           ********************#>#>  AWB bootstrap sequential quantile union test#>#> data: MacroTS#> null hypothesis: Series has a unit root#> alternative hypothesis: Series is stationary#>#> Sequence of tests:#>        H0: # I(0) H1: # I(0)  tstat p-value#> Step 1          0          5 -1.052 0.05013

Bootstrap FDR Controlling Tests

The functionboot_fdr() controls for multiple testing by controllingthe false discovery rate (FDR), which is defined as the expectedproportion of false rejections relative to the total number ofrejections. This scales with the total number of tests, making it moresuitable for largeN than the familywise error rate.

The bootstrap method for controlling FDR was introduced by Romano,Shaikh and Wolf (2008), who showed that, unlike the classical way tocontrol FDR, the bootstrap is appropriate under general forms ofdependence between series. Moon and Perron (2012) applied this method tounit root testing; it is essentially their method which is implementedinboot_fdr() though again with the option to change the bootstrapused (their suggestion was MBB). The arguments to be set are the same asfor the other multivariate unit root tests, with the exception ofFDR_level wihch controls the FDR level. As BSQT, the method onlyreport those tests until no rejection occurs.

We illustrate it here with the final available bootstrap method, theblock wild bootstrap of Shao (2011) and Smeekes and Urbain (2014a).

N<- ncol(MacroTS)boot_fdr(MacroTS[,1:10],FDR_level=0.1,bootstrap="BWB",B=399,do_parallel=FALSE)#> Progress: |------------------|#>           ********************#>#>  BWB bootstrap union test with false discovery rate control#>#> data: MacroTS[, 1:10]#> null hypothesis: Series has a unit root#> alternative hypothesis: Series is stationary#>#> Sequence of tests:#>         tstat critical value#> GDP_DE -1.077         -1.581

Determining Order of Integration

Generally the unit root tests above would only be used as a single stepin a larger algorithm to determine the orders of integration of the timeseries in the dataset. In particular, many economic datasets containvariables that have order of integration 2, and would so need to bedifferenced twice to eliminate all trends. A standard unit root testcannot determine this however. For this purpose, we add the functionorder_integration() which performs a sequence of unit root tests todetermine the orders of each time series.

How does it work

Starting from a maximum order (by default equal to 2), it differencesthe data time until there can be at most one unit root. If the test isnot rejected for a particular series, we know this series if of order .The series for which we do reject are integrated once (such that theyare differenced times from their original level), and the test isrepeated. By doing so until we have classified all series, we obtain afull specification of the orders of all time series.

Implementation

The function allows us to choose which unit root test we want to use.Here we takeboot_fdr. We don’t only get the orders out, but also theappropriately differenced data.

out_orders<- order_integration(MacroTS[,11:15],method="boot_fdr",B=399,do_parallel=FALSE)#> Progress: |------------------|#>           ********************#> Progress: |------------------|#>           ********************# Ordersout_orders$order_int#> HICP_BE HICP_DE HICP_FR HICP_NL HICP_UK#>       0       0       1       0       1# Differenced datastationary_data<-out_orders$diff_data

To achieve the differencing,order_integration() uses the functiondiff_mult() which is also available as stand-alone function in thepackage. Finally, a function is provided to plot the found orders (notrun):

plot_order_integration(out_orders)

References

  • Cavaliere, G., Phillips, P.C.B., Smeekes, S., and Taylor, A.M.R.(2015). Lag length selection for unit root tests in the presence ofnonstationary volatility.Econometric Reviews, 34(4), 512-536.
  • Elliott, G., Rothenberg, T.J., and Stock, J.H. (1996). Efficient testsfor an autoregressive unit root.Econometrica, 64(4), 813-836.
  • Friedrich, M., Smeekes, S. and Urbain, J.-P. (2020). Autoregressivewild bootstrap inference for nonparametric trends.Journal ofEconometrics, 214(1), 81-109.
  • Moon, H.R. and Perron, B. (2012). Beyond panel unit root tests: Usingmultiple testing to determine the non stationarity properties ofindividual series in a panel.Journal of Econometrics, 169(1),29-33.
  • Ng, S. and Perron, P. (2001). Lag Length Selection and theConstruction of Unit Root Tests with Good Size and Power.Econometrica, 69(6), 1519-1554,
  • Palm, F.C., Smeekes, S. and Urbain, J.-P. (2008). Bootstrap unit roottests: Comparison and extensions.Journal of Time Series Analysis,29(1), 371-401.
  • Palm, F. C., Smeekes, S., and Urbain, J.-.P. (2011). Cross-sectionaldependence robust block bootstrap panel unit root tests.Journal ofEconometrics, 163(1), 85-104.
  • Paparoditis, E. and Politis, D.N. (2003). Residual‐based blockbootstrap for unit root testing.Econometrica, 71(3), 813-855.
  • Perron, P. and Qu, Z. (2008). A simple modification to improve thefinite sample properties of Ng and Perron’s unit root tests.EconomicLetters, 94(1), 12-19.
  • Rho, Y. and Shao, X. (2019). Bootstrap-assisted unit root testing withpiecewise locally stationary errors.Econometric Theory, 35(1),142-166.
  • Romano, J.P., Shaikh, A.M., and Wolf, M. (2008). Control of the falsediscovery rate under dependence using the bootstrap and subsampling.Test, 17(3), 417.
  • Romano, J. P. and Wolf, M. (2005). Stepwise multiple testing asformalized data snooping.Econometrica, 73(4), 1237-1282.
  • Shao, X. (2010). The dependent wild bootstrap.Journal of theAmerican Statistical Association, 105(489), 218-235.
  • Shao, X. (2011). A bootstrap-assisted spectral test of white noiseunder unknown dependence.Journal of Econometrics, 162, 213-224.
  • Smeekes (2013). Detrending bootstrap unit root tests.EconometricReviews, 32(8), 869-891.
  • Smeekes, S. (2015). Bootstrap sequential tests to determine the orderof integration of individual units in a time series panel.Journal ofTime Series Analysis, 36(3), 398-415.
  • Smeekes, S. and Taylor, A.M.R. (2012). Bootstrap union tests for unitroots in the presence of nonstationary volatility.EconometricTheory, 28(2), 422-456.
  • Smeekes, S. and Urbain, J.-P. (2014a). A multivariate invarianceprinciple for modified wild bootstrap methods with an application tounit root testing. GSBE Research Memorandum No. RM/14/008, MaastrichtUniversity.
  • Smeekes, S. and Urbain, J.-P. (2014b). On the applicability of thesieve bootstrap in time series panels.Oxford Bulletin of Economicsand Statistics, 76(1), 139-151.

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp