Package {BayesSplineUR}


Type: Package
Title: Bayesian Unit Root Test for AR(1) Model with Trend Approximated by Linear Spline Function
Version: 0.1.0
Description: Performs Bayesian unit root testing for autoregressive time series models with non-linear trend components approximated by linear spline functions, as proposed by Kumar et al. (2020) <doi:10.19139/soic-2310-5070-786>. The package 'BayesSplineUR' computes posterior odds ratios, Bayes factors, and posterior probabilities for the unit root hypothesis against trend-stationary alternatives in models with linear spline trends or maintained polynomial trends as developed by Chaturvedi and Kumar (2005) <doi:10.1016/j.spl.2005.04.044>. Includes automatic knot selection using information criteria (AIC/BIC) and theoretical foundations for Bayesian unit root testing under structural breaks and maintained trends drawing from Schotman and van Dijk (1991) <doi:10.1016/0304-4076(91)90038-F>, Phillips and Perron (1988) <doi:10.1093/biomet/75.2.335>, Ouliaris et al. (1988) <doi:10.1007/978-94-009-2953-1_10>, and Perron (1989) <doi:10.2307/1913683>.
License: GPL (≥ 3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.3
Depends: R (≥ 3.5.0)
Imports: stats, graphics
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2026-07-29 01:06:10 UTC; shikhar tyagi
Author: Shikhar Tyagi ORCID iD [aut, cre], Arvind Pandey [aut], Bhupendra Singh [aut], Vrijesh Tripathi [aut]
Maintainer: Shikhar Tyagi <shikhar1093tyagi@gmail.com>
Repository: CRAN
Date/Publication: 2026-08-06 13:30:02 UTC

Monthly Import Series of ASEAN Regional Forum (ARF) Countries

Description

Monthly import data (in Billion US Dollars) for 14 selected ASEAN Regional Forum (ARF) countries covering the period April 2012 to August 2018 (77 monthly observations). Analyzed in Section 5 of Kumar et al. (2020) for empirical illustration of the Bayesian unit root test with linear spline trend.

Usage

arf_imports

Format

A data frame with 77 rows and 15 variables:

Date

Date of observation (monthly, April 2012 to August 2018).

Australia

Monthly imports for Australia (Billion USD).

Hong_Kong

Monthly imports for Hong Kong (Billion USD).

Japan

Monthly imports for Japan (Billion USD).

South_Korea

Monthly imports for South Korea (Billion USD).

New_Zealand

Monthly imports for New Zealand (Billion USD).

Taiwan

Monthly imports for Taiwan (Billion USD).

China

Monthly imports for China (Billion USD).

India

Monthly imports for India (Billion USD).

Indonesia

Monthly imports for Indonesia (Billion USD).

Malaysia

Monthly imports for Malaysia (Billion USD).

Philippines

Monthly imports for Philippines (Billion USD).

Singapore

Monthly imports for Singapore (Billion USD).

Thailand

Monthly imports for Thailand (Billion USD).

Viet_Nam

Monthly imports for Viet Nam (Billion USD).

Source

International Monetary Fund (IMF) and International Financial Statistics (IFS) data portal.

References

Kumar, J., Agiwal, V., Kumar, D., & Chaturvedi, A. (2020). Bayesian unit root test for AR(1) model with trend approximated by linear spline function. Statistics, Optimization & Information Computing, 8(2), 425–461. doi:10.19139/soic-2310-5070-786

Examples

data(arf_imports)
india_imports <- arf_imports$India
res <- bayes_ur_spline_test(india_imports, knots = c(14, 32, 52))
print(res)

Bayesian Unit Root Test for AR(1) Model with Linear Spline Trend

Description

Computes the posterior odds ratio, Bayes factor, and posterior probability for testing the unit root hypothesis (H0: rho = 1) against the trend-stationary alternative (H1: rho in (a, 1)) in an autoregressive AR(1) model where the non-linear time trend is approximated by a linear spline function, as derived by Kumar et al. (2020).

Usage

bayes_ur_spline_test(
  y,
  knots = NULL,
  r = 1,
  a = 0,
  p0 = 0.5,
  vartheta = 1,
  Omega = NULL,
  psi0 = NULL,
  y0 = NULL,
  n_grid = 500
)

kumar_spline_test(
  y,
  knots = NULL,
  r = 1,
  a = 0,
  p0 = 0.5,
  vartheta = 1,
  Omega = NULL,
  psi0 = NULL,
  y0 = NULL,
  n_grid = 500
)

Arguments

y

A numeric vector or univariate time series.

knots

Optional numeric vector of knot locations (indices 1 < t1 < ... < tr < T). If NULL, knot locations are automatically selected using select_knots.

r

Positive integer specifying the number of spline knots if knots = NULL (default is 1).

a

Lower bound of the prior interval (a, 1) for autoregressive parameter rho under H1 (default is 0). Must satisfy -1 < a < 1.

p0

Prior probability of the unit root hypothesis H0 (default is 0.5). Must satisfy 0 < p0 < 1.

vartheta

Prior hyperparameter scaling parameter for trend precision (default is 1.0). Must be positive.

Omega

Optional prior precision matrix (r x r) for spline coefficients (default is identity matrix I_r).

psi0

Optional prior mean vector (r x 1) for spline coefficients (default is column means of spline design matrix).

y0

Optional initial observation value y_0 (default is y[1]).

n_grid

Integer specifying the number of evaluation grid points for rho (default is 500).

Value

An object of class "bayes_ur_test" and "htest" containing:

statistic

The posterior odds ratio (B01) in favor of the unit root hypothesis H0.

p.value

The posterior probability P(H0|y) of the unit root hypothesis.

bayes_factor

The Bayes factor (BF01) in favor of H0 relative to H1.

posterior_h0

Posterior probability of the unit root hypothesis H0.

posterior_h1

Posterior probability of the stationary alternative hypothesis H1.

rho_summary

Vector of summary statistics for rho under H1 (mean, sd, median, 2.5%, 97.5% quantiles).

rho_grid

Vector of evaluation grid points for rho in (a, 1).

rho_density

Vector of normalized posterior density values for rho under H1.

parameter

Named vector of test settings (r, knots, a, p0).

method

Character string describing the test method.

data.name

Character string providing the data name.

estimates

Named vector of estimated parameter values.

References

Kumar, J., Agiwal, V., Kumar, D., & Chaturvedi, A. (2020). Bayesian unit root test for AR(1) model with trend approximated by linear spline function. Statistics, Optimization & Information Computing, 8(2), 425–461. doi:10.19139/soic-2310-5070-786

Schotman, P., & van Dijk, H. K. (1991). A Bayesian analysis of the unit root in real exchange rates. Journal of Econometrics, 49(1-2), 195–238. doi:10.1016/0304-4076(91)90038-F

Phillips, P. C. B., & Perron, P. (1988). Testing for a unit root in time series regression. Biometrika, 75(2), 335–346. doi:10.1093/biomet/75.2.335

Examples

set.seed(123)
# Simulated AR(1) time series with linear spline trend
t_vec <- 1:60
y_sim <- 5 + 0.1 * t_vec + pmax(0, t_vec - 30) * 0.4 + rnorm(60)
res <- bayes_ur_spline_test(y_sim, knots = c(30))
print(res)
summary(res)

Master Function for Bayesian Unit Root Test

Description

Computes the posterior odds ratio, Bayes factor, and posterior probabilities for testing the unit root hypothesis (H0: rho = 1) in autoregressive time series models with non-linear linear spline trends (Kumar et al., 2020) or maintained polynomial trends (Chaturvedi & Kumar, 2005).

Usage

bayes_ur_test(
  y,
  trend_type = c("spline", "polynomial"),
  knots = NULL,
  r = 1,
  p = 1,
  k = 1,
  a = 0,
  p0 = 0.5,
  vartheta = 1,
  V = NULL,
  n_grid = 500,
  ...
)

chaturvedi_test(y, p = 1, k = 1, a = 0, p0 = 0.5, V = NULL, n_grid = 500)

Arguments

y

A numeric vector or univariate time series.

trend_type

Character string specifying the trend model: "spline" (default, Kumar et al., 2020) or "polynomial" (Chaturvedi & Kumar, 2005).

knots

Optional numeric vector of knot locations for linear spline trend. If NULL and trend_type = "spline", knots are selected automatically.

r

Positive integer specifying the number of spline knots when knots = NULL (default is 1).

p

Degree of polynomial trend when trend_type = "polynomial" (default is 1).

k

Lag augmentation order when trend_type = "polynomial" (default is 1).

a

Lower bound of prior interval (a, 1) for rho under H1 (default is 0). Must satisfy -1 < a < 1.

p0

Prior probability of unit root hypothesis H0 (default is 0.5). Must satisfy 0 < p0 < 1.

vartheta

Prior hyperparameter scaling parameter for trend precision (default is 1.0).

V

Optional prior precision matrix for polynomial trend coefficients or scaling factor.

n_grid

Number of evaluation grid points for rho (default is 500).

...

Additional arguments passed to bayes_ur_spline_test.

Value

An object of class "bayes_ur_test" and "htest".

References

Kumar, J., Agiwal, V., Kumar, D., & Chaturvedi, A. (2020). Bayesian unit root test for AR(1) model with trend approximated by linear spline function. Statistics, Optimization & Information Computing, 8(2), 425–461. doi:10.19139/soic-2310-5070-786

Chaturvedi, A., & Kumar, J. (2005). Bayesian unit root test for model with maintained trend. Statistics & Probability Letters, 74(1), 109–115. doi:10.1016/j.spl.2005.04.044

Examples

set.seed(123)
y_sim <- cumsum(rnorm(50))
# Spline trend unit root test (Kumar et al., 2020)
res_spline <- bayes_ur_test(y_sim, trend_type = "spline", r = 1)
print(res_spline)

# Polynomial trend unit root test (Chaturvedi & Kumar, 2005)
res_poly <- bayes_ur_test(y_sim, trend_type = "polynomial", p = 1, k = 1)
print(res_poly)

Polynomial Trend Bayesian Unit Root Test (Chaturvedi & Kumar, 2005)

Description

Internal/Helper function for Bayesian unit root test with maintained polynomial trend.

Usage

chaturvedi_poly_test(y, p = 1, k = 1, a = 0, p0 = 0.5, V = NULL, n_grid = 500)

Arguments

y

A numeric vector.

p

Polynomial degree.

k

Augmentation order.

a

Lower bound of prior.

p0

Prior probability.

V

Prior precision matrix.

n_grid

Grid evaluation points.

Value

S3 object of class "bayes_ur_test".


Simulated Macroeconomic Time Series Data

Description

A simulated univariate time series vector containing 100 observations exhibiting a random walk with drift, suitable for demonstrating unit root testing.

Usage

macro_data

Format

A numeric vector of length 100.

Source

Simulated dataset generated for package documentation and examples.

Examples

data(macro_data)
res <- bayes_ur_test(macro_data, trend_type = "spline", r = 1)
print(res)

Plot Method for Bayesian Unit Root Test

Description

Plots the posterior density of the autoregressive parameter rho under H1 along with prior density and unit root probability point mass.

Usage

## S3 method for class 'bayes_ur_test'
plot(x, ...)

Arguments

x

An object of class "bayes_ur_test".

...

Further graphical arguments.

Value

No return value, called for side effects (plotting).


Print Method for Bayesian Unit Root Test

Description

Prints a concise summary of the Bayesian unit root test results.

Usage

## S3 method for class 'bayes_ur_test'
print(x, ...)

Arguments

x

An object of class "bayes_ur_test".

...

Further arguments passed to or from other methods.

Value

Invisibly returns the input object x.


Knot Selection for Linear Spline Trend Model

Description

Identifies the optimal number and locations of join points (knots) in a time series with a linear spline trend based on Akaike Information Criterion (AIC) or Bayesian Information Criterion (BIC), as described in Section 5 of Kumar et al. (2020).

Usage

select_knots(y, max_r = 3, criterion = c("AIC", "BIC"), min_gap = 5)

Arguments

y

A numeric vector or univariate time series.

max_r

Positive integer specifying the maximum number of knots to evaluate (default is 3).

criterion

Character string specifying the selection criterion: "AIC" (default) or "BIC".

min_gap

Positive integer specifying minimum observations between consecutive knots (default is 5).

Value

A list containing:

r

Selected optimal number of knots.

knots

Vector of selected optimal knot locations (indices).

aic

Minimum AIC value achieved.

bic

Minimum BIC value achieved.

model_summary

Data frame summarizing evaluated models across different knot configurations.

References

Kumar, J., Agiwal, V., Kumar, D., & Chaturvedi, A. (2020). Bayesian unit root test for AR(1) model with trend approximated by linear spline function. Statistics, Optimization & Information Computing, 8(2), 425–461. doi:10.19139/soic-2310-5070-786

Examples

set.seed(123)
t_vec <- 1:60
y_sim <- 10 + 0.2 * t_vec + pmax(0, t_vec - 25) * 0.5 + rnorm(60)
res_knots <- select_knots(y_sim, max_r = 2, criterion = "AIC")
print(res_knots$knots)

Summary Method for Bayesian Unit Root Test

Description

Provides detailed summary output for a Bayesian unit root test object.

Usage

## S3 method for class 'bayes_ur_test'
summary(object, ...)

Arguments

object

An object of class "bayes_ur_test".

...

Further arguments passed to or from other methods.

Value

Invisibly returns the input object object.