## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE, comment = "#>",
  fig.width = 6.4, fig.height = 4.0, fig.align = "center",
  dpi = 150
)
# CRAN policy: do not leave the user's options() changed. Capture the
# old value here; the last chunk of this vignette restores it.
old_options <- options(digits = 4)
library(ardldml)

## ----bracket, fig.cap = "As the effective integrated count falls, the limiting null slides from the I(1) endpoint to the I(0) endpoint. Classical bounds testing is the right-hand end."----
plot_bracket(k = 10, k_tilde = 6)

## ----data---------------------------------------------------------------------
df <- passthrough_regime("1999-2007")
dim(df)
CONTROLS
DEFAULT_INTEGRATED

## ----fit----------------------------------------------------------------------
W <- as.matrix(df[, CONTROLS])
fit <- dml_bounds(df$cpi, df$neer, W,
                  lags = 4, n_blocks = 5, buffer = 6,
                  integrated = DEFAULT_INTEGRATED)
fit

## ----design-------------------------------------------------------------------
des <- build_balanced_design(df$cpi, df$neer, W, lags = 4,
                             integrated = DEFAULT_INTEGRATED)
des

## ----sampleuse----------------------------------------------------------------
round(sample_use_table(nrow(df)), 3)

## ----boot---------------------------------------------------------------------
fit <- dml_bootstrap(fit, B = 49, seed = 20260625)
summary(fit)

## ----nullplot, fig.cap = "The bootstrap null against the borrowed classical bound. The gap between the two is the argument for not using a table."----
plot(fit)

## ----absorb-------------------------------------------------------------------
ta <- trend_absorption(df$cpi, df$neer, W, drop = REDUCED_DROP,
                       B = 19, seed = 1,
                       lags = 4, n_blocks = 5, buffer = 6,
                       integrated = DEFAULT_INTEGRATED)
ta

## ----sweep--------------------------------------------------------------------
sw <- penalty_sensitivity(df$cpi, df$neer, W,
                          lags_grid = 4, n_blocks = 5, buffer = 6,
                          integrated = DEFAULT_INTEGRATED)
sw
attr(sw, "theta_sign_flips")

## ----pss----------------------------------------------------------------------
sim <- simulate_pss_bounds(k = 1, case = 3, TT = 1000, nsim = 300, seed = 11)
sim
pss_reference(k = 1, case = 3)

## ----classical----------------------------------------------------------------
cb <- classical_bounds_test(df$cpi, cbind(neer = df$neer), lags = 4,
                            nsim = 300, seed = 11)
cb

## ----restore-options, include = FALSE-----------------------------------------
options(old_options)

