The BayesSplineUR package provides a unified framework
for Bayesian unit root hypothesis testing in autoregressive time series
models featuring non-linear trends. The primary method implements the
linear spline trend Bayesian unit root test derived by Kumar et
al. (2020) (Statistics, Optimization & Information
Computing, 8(2), 425-461, DOI: 10.19139/soic-2310-5070-786).
Additionally, the package supports the maintained polynomial trend
Bayesian unit root test proposed by Chaturvedi and Kumar
(2005) (Statistics & Probability Letters, 74(1),
109-115, DOI: 10.1016/j.spl.2005.04.044).
Consider an AR(1) process with non-linear trend approximated by a linear spline function with \(r\) join points (knots) \(1 < t_1 < t_2 < \dots < t_r < T\):
\[y_t = \delta_0 + \delta t + \sum_{i=1}^r \psi_i s_i(t) + u_t, \quad u_t = \rho u_{t-1} + \epsilon_t, \quad \epsilon_t \sim i.i.d. N(0, \tau^{-1})\]
where \(s_i(t) = (t - t_i)_+ = \max(0, t - t_i)\). Under the unit root hypothesis \(H_0: \rho = 1\), the model reduces to first differences:
\[\Delta y_t = \delta + \sum_{i=1}^r \psi_i [s_i(t) - s_i(t-1)] + \epsilon_t\]
The testing decision relies on the Posterior Odds Ratio (POR) \(\beta_{01} = \frac{P(H_0|y)}{P(H_1|y)}\), Bayes factor \(BF_{01}\), and posterior probabilities \(P(H_0|y)\) vs \(P(H_1|y)\).
We first demonstrate the linear spline unit root test on simulated time series data.
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)
#>
#> Kumar et al. (2020) Bayesian Unit Root Test with Linear Spline Trend
#>
#> data: y_stat
#> Posterior Odds Ratio (B01) = 9.6798
#> Bayes Factor (BF01) = 9.6798
#> Posterior Prob P(H0|y) = 0.90637
#> Posterior Prob P(H1|y) = 0.093634
#> parameters: knots = (35), a = 0, prior P(H0) = 0.5
#> alternative hypothesis: stationary process with trend (rho in (a, 1))
#>
#> Conclusion: Evidence in favor of Unit Root (H0: rho = 1).
summary(res_spline)
#> =========================================================
#> BAYESIAN UNIT ROOT TEST SUMMARY
#> =========================================================
#>
#> Model Method : Kumar et al. (2020) Bayesian Unit Root Test with Linear Spline Trend
#> Data Series : y_stat
#> Spline Knots (r=1): 35
#> Prior Interval (a,1): (0, 1)
#> Prior P(H0) : 0.5
#>
#> --- HYPOTHESIS TESTING RESULTS ---
#> Posterior Odds Ratio (B01) : 9.67983e+00
#> Bayes Factor (BF01) : 9.67983e+00
#> Posterior Probability P(H0): 0.90637
#> Posterior Probability P(H1): 0.09363
#>
#> --- POSTERIOR SUMMARY FOR RHO (UNDER H1) ---
#> Mean Std.Dev Median 2.5% 97.5%
#> 0.95881 0.15387 0.98997 0.21243 0.99999
#>
#> --- EVIDENCE INTERPRETATION (Kass & Raftery Scale) ---
#> Substantial evidence for Unit Root (H0).When knot locations are unknown, select_knots()
automatically identifies optimal join points based on AIC or BIC
criteria:
# Automatic knot selection
res_auto <- bayes_ur_test(y_stat, trend_type = "spline", r = 1)
summary(res_auto)
#> =========================================================
#> BAYESIAN UNIT ROOT TEST SUMMARY
#> =========================================================
#>
#> Model Method : Kumar et al. (2020) Bayesian Unit Root Test with Linear Spline Trend
#> Data Series : y
#> Spline Knots (r=1): 30
#> Prior Interval (a,1): (0, 1)
#> Prior P(H0) : 0.5
#>
#> --- HYPOTHESIS TESTING RESULTS ---
#> Posterior Odds Ratio (B01) : 6.72817e+00
#> Bayes Factor (BF01) : 6.72817e+00
#> Posterior Probability P(H0): 0.87060
#> Posterior Probability P(H1): 0.12940
#>
#> --- POSTERIOR SUMMARY FOR RHO (UNDER H1) ---
#> Mean Std.Dev Median 2.5% 97.5%
#> 0.97860 0.08352 0.98797 0.95189 0.99999
#>
#> --- EVIDENCE INTERPRETATION (Kass & Raftery Scale) ---
#> Substantial evidence for Unit Root (H0).The package includes the arf_imports dataset analyzed in
Section 5 of Kumar et al. (2020):
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)
#> =========================================================
#> BAYESIAN UNIT ROOT TEST SUMMARY
#> =========================================================
#>
#> Model Method : Kumar et al. (2020) Bayesian Unit Root Test with Linear Spline Trend
#> Data Series : india_imports
#> Spline Knots (r=3): 14, 32, 52
#> Prior Interval (a,1): (0, 1)
#> Prior P(H0) : 0.5
#>
#> --- HYPOTHESIS TESTING RESULTS ---
#> Posterior Odds Ratio (B01) : 2.59070e+00
#> Bayes Factor (BF01) : 2.59070e+00
#> Posterior Probability P(H0): 0.72150
#> Posterior Probability P(H1): 0.27850
#>
#> --- POSTERIOR SUMMARY FOR RHO (UNDER H1) ---
#> Mean Std.Dev Median 2.5% 97.5%
#> 0.97758 0.01000 0.97795 0.95791 0.99398
#>
#> --- EVIDENCE INTERPRETATION (Kass & Raftery Scale) ---
#> Barely worth mentioning evidence.The S3 plot() method displays the normalized posterior
density of \(\rho\) under \(H_1\), the uniform prior density \(U(a, 1)\), the posterior mean estimate, and
the point mass assigned to the unit root hypothesis \(H_0\):