## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 6,
  fig.height = 4
)
library(BayesSplineUR)

## ----spline_example-----------------------------------------------------------
set.seed(123)
t_vec <- 1:70
# Stationary AR(1) process with linear spline trend
u <- numeric(70)
for (t in 2:70) u[t] <- 0.45 * u[t - 1] + rnorm(1, 0, 1)
y_stat <- 10 + 0.15 * t_vec + pmax(0, t_vec - 35) * 0.4 + u

# Perform Bayesian unit root test with spline trend
res_spline <- bayes_ur_spline_test(y_stat, knots = c(35))
print(res_spline)
summary(res_spline)

## ----knot_selection-----------------------------------------------------------
# Automatic knot selection
res_auto <- bayes_ur_test(y_stat, trend_type = "spline", r = 1)
summary(res_auto)

## ----real_data----------------------------------------------------------------
data(arf_imports)
india_imports <- arf_imports$India

# Fit linear spline test with knots identified in paper (r=3 at t=14, 32, 52)
res_india <- bayes_ur_spline_test(india_imports, knots = c(14, 32, 52))
summary(res_india)

## ----plot_diagnostic, fig.width = 6, fig.height = 4---------------------------
plot(res_india)

