DPTM

DPTM is an R package for estimating dynamic panel threshold models with fixed effects. It supports both dynamic panel linear models and dynamic panel multiple-threshold models, with tools for threshold estimation, model comparison, bootstrap testing, and convergence diagnostics.

The package is designed for applied panel-data work where the effect of one or more regressors may change across regimes determined by an observed threshold variable.

Features

Installation

Install from GitHub after replacing <owner> with the account or organization that hosts the repository:

install.packages("remotes")
remotes::install_github("<owner>/DPTM")

You can also install a local source archive:

install.packages("DPTM_4.0.1.tar.gz", repos = NULL, type = "source")

Or install from a local package directory:

remotes::install_local("path/to/DPTM")

Quick Start

library(DPTM)

data(d1)
head(d1)

The example dataset d1 is a simulated balanced panel with individual and time indexes, a dependent variable, a lagged dependent variable, a threshold variable, a regressor with threshold effects, and a control variable.

Dynamic Panel Linear Model

Use DPML() to estimate the linear dynamic panel model with fixed effects.

linear_model <- DPML(
  y ~ x + z,
  data = d1,
  index = c("id", "year")
)

print(linear_model)

Add time fixed effects with timeFE = TRUE.

linear_time_fe <- DPML(
  y ~ x + z,
  data = d1,
  index = c("id", "year"),
  timeFE = TRUE
)

One-Threshold Model

Use DPTS() to estimate a dynamic panel threshold model. The first formula contains regressors with threshold-varying effects. The second formula contains controls whose effects are common across regimes.

set.seed(42)

one_threshold <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 1,
  iterations = 1000
)

print(one_threshold)

The printed result includes the threshold estimate, regime-specific coefficients, the negative log-likelihood value, confidence intervals for thresholds when MCMC search is used, and Gelman-Rubin diagnostics.

Multiple-Threshold Model

Set Th > 1 to estimate multiple thresholds.

set.seed(42)

two_thresholds <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 2,
  iterations = 1000
)

print(two_thresholds)

This specification partitions the sample into three regimes:

Choosing the Threshold Search Method

By default, DPTS() searches thresholds with an MCMC-MLE procedure based on BayesianTools. This is useful when the number of thresholds is greater than one, since exhaustive grid search can become expensive.

model_mcmc <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 2,
  iterations = 2000
)

For deterministic threshold search, set grid_search = TRUE.

model_grid <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 1,
  grid_search = TRUE,
  grids = 100
)

For multiple thresholds, choose between joint and sequential grid search.

model_joint <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 2,
  grid_search = TRUE,
  grids = 100,
  grid_search_type = "jointly",
  grid_search_iter = 1
)

model_sequential <- DPTS(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 2,
  grid_search = TRUE,
  grids = 100,
  grid_search_type = "sequential",
  grid_search_iter = 1
)

grid_search_iter controls coordinate-refinement cycles after the initial search. For two thresholds, one refinement cycle re-estimates the first threshold conditional on the second and then re-estimates the second conditional on the first.

Testing Threshold Effects

Threshold_Test() implements bootstrap tests for threshold existence and for the number of thresholds.

set.seed(42)

test_one <- Threshold_Test(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 1,
  bt = 50,
  iterations = 500
)

test_one

Interpretation of Th in Threshold_Test():

The same grid-search options used by DPTS() are available in Threshold_Test().

test_grid <- Threshold_Test(
  y ~ x,
  y ~ z,
  data = d1,
  index = c("id", "year"),
  q = d1$q,
  Th = 1,
  bt = 50,
  grid_search = TRUE,
  grids = 100,
  grid_search_type = "sequential"
)

Model Specification Guide

DPTS() uses two formula arguments:

Examples:

# Threshold effects in x; common effect for z
DPTS(y ~ x, y ~ z, data = d1, index = c("id", "year"), q = d1$q)

# Threshold effects in x, but no threshold effects in lagged y
DPTS(y ~ x, y ~ z, data = d1, index = c("id", "year"), q = d1$q, NoY = TRUE)

# Threshold effects only in lagged y; x and z are controls
DPTS(NULL, y ~ x + z, data = d1, index = c("id", "year"), q = d1$q)

Useful arguments:

Returned Objects

DPML() and DPTS() return objects of class "DPTM". Important fields include:

Threshold_Test() returns an "htest" object with:

Included Data

Practical Notes

License

This package is released under the GPL (>= 3) license.