Title: Restricted Structural Change Models
Version: 1.0.7
Maintainer: Zhongjun Qu <qu@bu.edu>
Description: Methods for detecting structural breaks and estimating break locations for linear multiple regression models under general linear restrictions on the coefficient vector. Restrictions can be within regimes, across regimes, or both, and are supported in two forms: an affine parameterization (Form A: delta = S*theta + s) and explicit linear constraints (Form B: R*delta = r). Provides break date estimation with confidence intervals, a restricted sup-F test for the null of no structural change, simulation of critical values by Monte Carlo, and a bootstrap restart procedure to reduce the risk of convergence to spurious local optima. Also implements a generalized regression tree (linear model tree) procedure where each leaf contains a linear regression model rather than a local average. Reference: Perron, P., and Qu, Z. (2006). 'Estimating Restricted Structural Change Models.' Journal of Econometrics, 134(2), 373-399. <doi:10.1016/j.jeconom.2005.06.030>.
License: GPL (≥ 3)
Depends: R (≥ 4.3.0)
Suggests: knitr, parallel, pbapply, rmarkdown
VignetteBuilder: knitr
Encoding: UTF-8
NeedsCompilation: no
RoxygenNote: 7.3.2
Imports: MASS, stats
LazyData: true
Packaged: 2026-03-23 21:28:45 UTC; qu
Author: Zhongjun Qu [aut, cre], Cheolju Kim [aut]
Repository: CRAN
Date/Publication: 2026-03-27 10:20:03 UTC

Automatic Bandwidth Selection

Description

Computes automatic bandwidth based on AR(1) approximation for each column of the input matrix. Uses Andrews (1991) method. Corresponds to GAUSS procedure bandw.

Usage

bandw(vhat)

Arguments

vhat

Matrix of dimension (T x d)

Value

Optimal bandwidth


Bootstrap Restart Algorithm

Description

Implements the Bootstrap Restarting to avoid local minima

Usage

brbp(
  y,
  z,
  q,
  m,
  bigt,
  trm,
  T_init,
  B = 20,
  S = NULL,
  s = NULL,
  R = NULL,
  r = NULL,
  verbose = FALSE
)

Arguments

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

q

An integer of number of regressors.

m

An integer of number of breaks.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter.

T_init

A numeric vector (m \times 1) of initial break dates.

B

An integer of number of bootstrap replications (default is 20).

S

A numeric matrix of restriction for Form A. If NULL, uses unrestricted estimation.

s

A numeric vector of restriction for Form A. If NULL, uses unrestricted estimation.

R

A numeric matrix of restriction for Form B. If NULL, uses unrestricted estimation.

r

A numeric vector of restriction for Form B. If NULL, uses unrestricted estimation.

verbose

A logical. If TRUE, print progress (default is TRUE).

Value

A list containing dx, delta, rssr, all_break_dates, and all_rssr.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Residual Bootstrap Restarting Break-Point Algorithm

Description

Implements the Residual Bootstrap Restarting Break-Point algorithm to avoid local minima in restricted structural break estimation. Unlike the standard brbp algorithm, this method uses residual bootstrap instead of resampling observations, preserving the time ordering of the data.

Usage

brbp_residual(
  y,
  z,
  q,
  m,
  bigt,
  trm,
  T_init,
  B = 20,
  S = NULL,
  s = NULL,
  R = NULL,
  r = NULL,
  verbose = FALSE
)

Arguments

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

q

An integer of number of regressors.

m

An integer of number of breaks.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter.

T_init

A numeric vector (m \times 1) of initial break dates.

B

An integer of number of bootstrap replications (default is 20).

S

A numeric matrix of restriction for Form A. If NULL, uses unrestricted estimation.

s

A numeric vector of restriction for Form A. If NULL, uses unrestricted estimation.

R

A numeric matrix of restriction for Form B. If NULL, uses unrestricted estimation.

r

A numeric vector of restriction for Form B. If NULL, uses unrestricted estimation.

verbose

A logical. If TRUE, print progress (default is FALSE).

Value

A list containing dx, delta, rssr, all_break_dates, and all_rssr.


Build no-break (null) restrictions on \beta implied by R\delta = r

Description

Given linear restrictions on the break-model coefficient vector

R\delta = r, \qquad \delta \in \mathbb{R}^{(m+1)q},

this function constructs the implied restriction system under the no-break null, where all regimes share a common coefficient vector \beta\in\mathbb{R}^q.

Usage

build_null_from_R(R, r, m, q, tol)

Arguments

R

Numeric matrix of dimension k \times (m+1)q in R\delta = r.

r

Numeric vector of length k in R\delta = r.

m

Integer. Number of breaks (so number of regimes is m+1).

q

Integer. Number of regressors per regime.

tol

Numeric tolerance used in rank decisions. Default is 1e-10.

Details

Under no break, \delta = N\beta with N=\mathbf{1}_{m+1}\otimes I_q. Hence the implied null restrictions are

(RN)\beta = r.

The function reduces to independent rows and checks feasibility. It returns R_0\beta = r_0 with R_0 having q columns.

Value

A list with components:

Examples

m <- 1
q <- 2
R <- matrix(c(1, -1, 0, 0,
              0, 0, 1, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
out <- build_null_from_R(R, r, m = m, q = q)
out$p0
out$R0
out$r0


Build no-break (null) restrictions implied by \delta = S\theta + s

Description

Given an affine restriction set for the break-model coefficients,

\delta = S\theta + s,

this function computes an affine parameterization for the no-break (null) model in terms of the common coefficient vector \beta\in\mathbb{R}^q:

\beta = S_0\gamma + s_0.

Usage

build_null_from_S(S, s, m, q, tol)

Arguments

S

Numeric matrix of dimension (m+1)q \times p_A in \delta = S\theta + s.

s

Numeric vector of length (m+1)q in \delta = S\theta + s.

m

Integer. Number of breaks (so number of regimes is m+1).

q

Integer. Number of regressors per regime.

tol

Numeric tolerance used in rank decisions. Default is 1e-10.

Details

The null model is "no break" (all regimes share the same \beta) possibly with additional restrictions implied by S, s. The function returns S_0, s_0 and the number of free parameters under the null.

Under no break, the stacked coefficient vector satisfies

\delta = N\beta,\qquad N = \mathbf{1}_{m+1}\otimes I_q.

Combining with \delta = S\theta + s and eliminating \theta yields a linear system on \beta. This function constructs an affine parameterization \beta = S_0\gamma + s_0 for that system, or returns the unrestricted no-break model when no additional restrictions are implied.

The function stops with an error if the implied no-break system is infeasible.

Value

A list with components:

Examples

m <- 1
q <- 2
S <- matrix(c(1, 0,
              1, 0,
              0, 1,
              0, 1), nrow = 4, byrow = TRUE)
s <- rep(0, 4)
out <- build_null_from_S(S, s, m = m, q = q)
out$p0
out$S0
out$s0


Compute Restricted Sum of Squared Residuals (RSSR)

Description

Computes the sum of squared residuals for given break dates and coefficients, taking into account restrictions if any.

Usage

compute_rssr(y, z, T_break, delta, m)

Compute HAC Variance-Covariance Matrix

Description

Main procedure for computing robust standard errors with optional AR(1) prewhitening. Corresponds to GAUSS procedure correct.

Usage

correct(reg, res, prewhit)

Arguments

reg

Regressor matrix Z (T x d)

res

Residual vector u (T x 1)

prewhit

Integer; if 1, apply AR(1) prewhitening, if 0, no prewhitening

Value

HAC variance-covariance matrix (d x d)


Critical Values for Break Date Confidence Intervals

Description

Computes critical values for confidence intervals of break dates. Corresponds to GAUSS procedure cvg.

Usage

cvg(eta, phi1s, phi2s)

Arguments

eta

Parameter eta

phi1s

Parameter phi1s

phi2s

Parameter phi2s

Value

Vector of critical values (4 x 1) for 2.5%, 5%, 95%, 97.5% quantiles


Find Optimal Break Dates (Unrestricted)

Description

Finds break dates that globally minimize the sum of squared residuals (SSR) without any restrictions on coefficients, using dynamic programming.

Usage

dating(y, z, h, m, q, bigt)

Arguments

y

A numeric vector of dependent variables (T \times 1).

z

A numeric matrix of regressors (T \times q).

h

An integer of minimum number of observations in each segment.

m

An integer of number of breaks.

q

An integer of number of regressors.

bigt

An integer of sample size.

Details

This function implements the dynamic programming algorithm of Bai and Perron (1998, 2003) to efficiently find the optimal break dates. The algorithm:

Value

A list containing:

global

A numeric vector that contains minimized SSR for each number of breaks 1 to m (m \times 1)

datevec

An numeric upper triangular matrix of break dates (m \times m). (i, j) contains the i-th break date for a model with j breaks

bigvec

A numeric vector containing SSR for all possible segments.

References

Bai, J., and Perron, P. (1998). Estimating and testing linear models with multiple structural changes. Econometrica, 66(1), 47-78.

Bai, J., and Perron, P. (2003). Computation and analysis of multiple structural change models. Journal of Applied Econometrics, 18(1), 1-22.


Find Optimal Break Dates (Under Restrictions)

Description

Finds break dates that minimize the SSR given pre-estimated restricted coefficients, using dynamic programming.

Usage

dating2(bigvec2, h, m, bigt)

Arguments

bigvec2

A numeric vector. Squared residuals from ssr2 (T(m+1) \times 1)

h

An integer of minimum number of observations in each segment

m

An integer of number of breaks

bigt

An integer of sample size

Value

A list containing:

global

A numeric vector that contains minimized SSR for each number of breaks 1 to m (m \times 1)

datevec

An numeric upper triangular matrix of break dates (m \times m). (i, j) contains the i-th break date for a model with j breaks

References

Bai, J., and Perron, P. (1998). Estimating and testing linear models with multiple structural changes. Econometrica, 66(1), 47-78.

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Taylor Rule Deviation Data

Description

A dataset containing quarterly Taylor-rule deviations used in the restricted structural break illustration.

Usage

deviation

Format

A data frame with 193 rows and 2 variables:

date

Quarterly date labels.

y

Taylor-rule deviation series used in the application example.

Source

Constructed from the replication files for Nikolsko-Rzhevskyy et al. (2014).

References

Nikolsko-Rzhevskyy, A., Papell, D. H., and Prodan, R. (2014). Deviations from rules-based policy and their effects. Journal of Economic Dynamics and Control, 49, 4–17.

Examples

data(deviation)
head(deviation)


Estimate Breaks and Coefficients (Form A)

Description

Estimates break dates and coefficients under Form A restrictions \delta = S \theta + s without computing standard errors or confidence intervals.

Usage

est(y, z, q, m, bigt, trm, S, s, T_init = NULL)

Arguments

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

q

An integer of number of regressors.

m

An integer of number of breaks.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter

S

A numeric matrix of restriction. (must have full row rank)

s

A numeric vector of restriction.

T_init

Optional numeric vector of initial break dates. If NULL (default), initial break dates are found automatically using the unrestricted model.

Value

A list containing:

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Estimate Breaks and Coefficients (Form B)

Description

Estimates break dates and coefficients under Form B restrictions R \delta = r without computing standard errors or confidence intervals.

Usage

est2(y, z, q, m, bigt, trm, R, r, T_init = NULL)

Arguments

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

q

An integer of number of regressors.

m

An integer of number of breaks.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter.

R

A numeric matrix of restriction. (must have full row rank)

r

A numeric vector of restriction.

T_init

Optional numeric vector of initial break dates. If NULL (default), initial break dates are found automatically using the unrestricted model.

Value

A list containing:

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

See Also

estco2 for estimation with standard errors and confidence intervals


Estimation with Standard Errors and Confidence Intervals (Form A)

Description

Estimates break dates and coefficients under Form A restrictions, computes HAC standard errors, and constructs confidence intervals for break dates.

Usage

estco(m, q, z, y, trm, robust, prewhit, hetvar, S, s, Verbose)

Arguments

m

An integer of number of breaks.

q

An integer of number of regressors.

z

A numeric matrix (T \times q) of regressor.

y

A numeric vector (T \times 1) of dependent variable.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust=1).

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

S

Numeric matrix defining the linear reparameterization for Form A: \delta = S\theta + s, where \delta stacks the q coefficients for each of the m+1 regimes (so \delta \in \mathbb{R}^{(m+1)q}). Must have full column rank. If there are no restrictions, set S = diag((m+1) * q).

s

Numeric vector of constants in \delta = S\theta + s, of length (m+1)q. If there are no restrictions, set s = rep(0, (m+1) * q).

Verbose

Logical. If TRUE, print detailed output (default FALSE).

Value

A list (returned invisibly) with the following components:

breaks

An integer vector of length m giving the estimated break dates.

coefficients

A numeric vector of length (m+1)q giving the regime-specific coefficient estimates.

vcov

A (m+1)q \times (m+1)q variance-covariance matrix of coefficients.

ci_breaks

An m \times 4 matrix of confidence intervals for the break dates. The first two columns give the 95\ (lower bound, upper bound) and the last two columns give the 90\ (lower bound, upper bound).

References

Andrews, D. W. K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59(3), 817-858.

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
S <- matrix(c(1, 0,
              0, 1,
              1, 0,
              0, 1), nrow = 4, byrow = TRUE)
s <- rep(0, 4)
fit <- estco(m, q, z, y, trm, 0, 0, 1, S, s, FALSE)
fit$breaks


Estimation with Standard Errors and Confidence Intervals (Form B)

Description

Estimates break dates and coefficients under Form B restrictions, computes HAC standard errors, and constructs confidence intervals for break dates.

Usage

estco2(m, q, z, y, trm, robust, prewhit, hetvar, R, r, Verbose)

Arguments

m

An integer of number of breaks.

q

An integer of number of regressors.

z

A numeric matrix (T \times q) of regressor.

y

A numeric vector (T \times 1) of dependent variable.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust=1).

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

R

Numeric matrix defining linear restrictions for Form B, R\delta = r, where \delta \in \mathbb{R}^{(m+1)q} stacks the q coefficients for each of the m+1 regimes. Each row of R represents one linear restriction. Must have full row rank. Do not use this form if there are no restrictions; use Form A instead.

r

Numeric vector of restriction constants in R\delta = r, with length equal to nrow(R).

Verbose

Logical. If TRUE, print detailed output (default FALSE).

Value

A list (returned invisibly) with the following components:

breaks

An integer vector of length m giving the estimated break dates.

coefficients

A numeric vector of length (m+1)q giving the regime-specific coefficient estimates.

vcov

A (m+1)q \times (m+1)q variance-covariance matrix of coefficients.

ci_breaks

An m \times 4 matrix of confidence intervals for the break dates. The first two columns give the 95\ (lower bound, upper bound) and the last two columns give the 90\ (lower bound, upper bound).

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
R <- matrix(c(1, 0, -1, 0,
              0, 1,  0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
fit <- estco2(m, q, z, y, trm, 0, 0, 1, R, r, FALSE)
fit$breaks


Estimation with Standard Errors and Confidence Intervals (Form B)

Description

Estimates break dates and coefficients under Form B restrictions, computes HAC standard errors, and constructs confidence intervals for break dates.

Usage

estco2_fb(
  m,
  q,
  z,
  y,
  trm,
  T_init,
  robust,
  prewhit,
  hetvar,
  R,
  r,
  Verbose = FALSE
)

Arguments

m

An integer of number of breaks.

q

An integer of number of regressors.

z

A numeric matrix (T \times q) of regressor.

y

A numeric vector (T \times 1) of dependent variable.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust=1).

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

R

A numeric matrix of restriction (must have full row rank).

r

A numeric vector of restriction.

Value

A list (returned invisibly) containing breaks, coefficients, vcov, and ci_breaks.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Estimation with Standard Errors and Confidence Intervals (Form A), conditional on estimated breaks

Description

Estimates coefficients under Form A restrictions, computes HAC standard errors, and constructs confidence intervals for break dates.

Usage

estco_fb(
  m,
  q,
  z,
  y,
  trm,
  T_init,
  robust,
  prewhit,
  hetvar,
  S,
  s,
  Verbose = FALSE
)

Arguments

m

An integer of number of breaks.

q

An integer of number of regressors.

z

A numeric matrix (T \times q) of regressor.

y

A numeric vector (T \times 1) of dependent variable.

trm

A numeric value of trimming parameter.

T_init

Break dates

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust=1).

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

S

A numeric matrix of restriction (must have full row rank).

s

A numeric vector of restriction.

Value

A list (returned invisibly) containing breaks, coefficients, vcov, and ci_breaks.

References

Andrews, D. W. K. (1991). Heteroskedasticity and autocorrelation consistent covariance matrix estimation. Econometrica, 59(3), 817-858.

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Example Time Series Data

Description

A dataset containing 120 observations of a time series variable for illustrating restricted structural change models.

Usage

example

Format

A data frame with 120 rows and 1 variable:

y

Numeric vector containing the time series observations

Details

This dataset is used in the examples in Perron and Qu (2006).

Source

Included with the rbreak package for illustration purposes.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

# Load the example data
data(example)


# Example: Test for 3 breaks with intercept only model
y <- example$y
z <- matrix(1, length(y), 1)  # Intercept only

# Form B restrictions: coefficients in regimes 1 and 3 are equal
m <- 3
q <- 1
R <- matrix(c(1, 0, -1, 0, 0, 1, 0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)

result <- mainp(m = m, q = q, z = z, y = y, trm = 0.10,
                robust = 1, prewhit = 0, hetvar = 1,
                R = R, r = r,
                doestim = 1, dotest = 1, docv = 0,
                formb = 1)


Helper Function for Critical Value Calculation

Description

Evaluates the distribution function for computing critical values. Corresponds to GAUSS procedure funcg.

Usage

funcg(x, bet, alph, b, deld, gam)

Arguments

x

Numeric value

bet

Parameter beta

alph

Parameter alpha

b

Parameter b

deld

Parameter delta_d

gam

Parameter gamma

Value

Function value


Confidence Intervals for Break Dates

Description

Computes confidence intervals for estimated break dates using the shrinking shifts asymptotic framework.

Usage

interval(y, z, zbar, b, q, m, delta, robust, prewhit, hetomega)

Arguments

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

zbar

A numeric matrix (T \times (m+1)q) of diagonal partition of z matrix.

b

A numeric vector (m \times 1) of estimated break dates.

q

An integer of number of regressors.

m

An integer of number of breaks.

delta

A numeric vector ((m+1)q \times 1) of estimated coefficients.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening.

hetomega

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

Value

A numeric matrix (m \times 4) with confidence interval bounds for each break date.

References

Bai, J. (1997). Estimation of a change point in multiple regression models. Review of Economics and Statistics, 79(4), 551-563.

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.


Long-Run Covariance Matrix (Newey-West style)

Description

Computes the long-run covariance matrix using quadratic spectral kernel with automatic bandwidth selection. Corresponds to GAUSS procedure jhatpr.

Usage

jhatpr(vmat)

Arguments

vmat

Matrix of dimension (T x d), typically Z_t * u_t

Value

Long-run covariance matrix (d x d)


Quadratic Spectral Kernel

Description

Evaluates the quadratic spectral kernel at value x. Corresponds to GAUSS procedure kern.

Usage

kern(x)

Arguments

x

Numeric value

Value

Kernel weight


Linear Regression Tree

Description

Constructs a regression tree where each terminal node fits a linear model. The tree is built by greedy recursive binary partitioning: at each node, every partition variable is considered as a candidate split axis. For numeric variables, data are sorted by the candidate variable and an optimal one-break point is found (minimising SSR via ssr()). For categorical variables, all possible binary partitions of the levels are enumerated. BIC is used to decide whether splitting improves the fit. The process continues until no further BIC improvement is possible.

Usage

ltree(y, z, partition_vars, cat_vars, trm, max_depth, min_obs,
  prune, verbose)

Arguments

y

Numeric vector of length n. Dependent variable.

z

Numeric matrix (n \times q). Regressors for the linear model fitted in each segment. Include an intercept column (e.g. cbind(1, X)) if desired.

partition_vars

Data frame or matrix (n \times p). Variables considered for splitting. May contain both numeric and categorical (factor/character) columns when passed as a data frame. If NULL (default), z is used (all numeric).

cat_vars

Integer vector of column indices in partition_vars that should be treated as categorical. Only needed when partition_vars is a matrix; ignored when it is a data frame (factor/character columns are auto-detected). Default NULL.

trm

Numeric. Trimming parameter: minimum fraction of the current node's observations that must remain in each child segment after a split (default 0.15).

max_depth

Integer. Maximum depth of the tree (default 10).

min_obs

Integer or NULL. Minimum number of observations in a segment. If NULL (default), set to max(q + 1, 5).

prune

Logical. If TRUE (default), apply cost-complexity pruning after growing the full tree to remove spurious splits. If FALSE, return the greedily grown tree without pruning.

verbose

Logical. If TRUE, print progress messages (default FALSE).

Details

Each node in the tree is a list with type = "leaf" or type = "internal".

A leaf node contains: n, indices, coefficients, ssr, bic.

An internal node contains: split_var, split_var_name, split_type ("numeric" or "categorical"), split_val (for numeric) or split_left_levels (for categorical), bic_nosplit, bic_split, left, right, n.

The BIC criterion used is:

\mathrm{BIC} = n \log(\mathrm{SSR}/n) + k \log(n),

where k = q for no split and k = 2q for a single split.

Value

An object of class "ltree", a list containing:

tree

The recursive tree structure (see Details).

n

Total number of observations.

q

Number of regressors.

p

Number of partition variables.

pv_names

Names of the partition variables.

z_names

Names of the regressors.

is_cat

Logical vector indicating which partition variables are categorical.

trm

Trimming parameter used.

max_depth

Maximum depth used.

min_obs

Minimum observations per segment used.

call

The matched call.

S3 Methods

print(x, ...)

Prints a summary of the fitted tree, including the number of leaves, tree depth, and the split structure.

predict(object, newz, new_partition_vars = NULL, ...)

Returns predicted values for new data. newz is a numeric matrix of regressors and new_partition_vars is an optional data frame of partition variables (defaults to newz).

plot(x, data = x$partition_vars, cex = 0.85, main = "", ...)

Draws a tree diagram of the fitted segmented linear regression tree. Internal nodes are shown as beige rectangles, leaf nodes as green ovals. data defaults to the partition variables stored in the fitted object, so plot(res) works out of the box. Right-side levels of categorical splits are labelled automatically.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Quinlan, J.R. (1992). Learning with continuous classes. In: Proceedings of the Australian Joint Conference on Artificial Intelligence, World Scientific, pp 343–348.

Examples

data(ltree1)
fit <- ltree(ltree1$y[1:120],
             ltree1[1:120, c("x1", "x2", "x3", "x4")],
             trm = 0.1, max_depth = 2, prune = TRUE)
print(fit)


Linear Model Tree Data

Description

A dataset containing one realization from the piecewise linear design used to illustrate the generalized regression tree (linear model tree).

Usage

ltree1

Format

A data frame with 1500 rows and 5 variables:

y

Response variable.

x1

Continuous regressor.

x2

Continuous regressor.

x3

Continuous regressor.

x4

Categorical regressor.

Details

The data are generated from a segmented linear regression function with true splits at X_1 = 10, X_2 = 10, X_2 = 15, and X_4 \in \{a,b\} versus \{c\}.

Source

Generated from the design in Zheng and Chen (2019) and included for illustration purposes.

References

Quinlan, J.R. (1992). Learning with continuous classes. In: Proceedings of the Australian Joint Conference on Artificial Intelligence, World Scientific, pp 343–348.

Zheng, X. and Chen, S. X. (2019). Partitioning structure learning for segmented linear regression trees. Advances in Neural Information Processing Systems (NeurIPS 2019).

Examples

data(ltree1)
fit <- ltree(ltree1$y, ltree1[, c("x1", "x2", "x3", "x4")],
             trm = 0.1, max_depth = 10, prune = TRUE)
print(fit)


Smooth Surface Regression Tree Example Data

Description

A dataset containing one fixed sample for the smooth-surface generalized regression tree illustration.

Usage

ltree2

Format

A data frame with 1000 rows and 3 variables:

y

Response variable with Gaussian noise.

x1

Continuous regressor.

x2

Continuous regressor.

Details

The underlying regression surface is

m(X) = \max\{e^{-10X_1^2}, e^{-50X_2^2}, 1.25e^{-5(X_1^2 + X_2^2)}\}.

Source

Generated from the design in Zheng and Chen (2019) and included for illustration purposes.

References

Quinlan, J.R. (1992). Learning with continuous classes. In: Proceedings of the Australian Joint Conference on Artificial Intelligence, World Scientific, pp 343–348.

Zheng, X. and Chen, S. X. (2019). Partitioning structure learning for segmented linear regression trees. Advances in Neural Information Processing Systems (NeurIPS 2019).

Examples

data(ltree2)
fit <- ltree(ltree2$y,
             cbind(1, ltree2$x1, ltree2$x2),
             partition_vars = ltree2[, c("x1", "x2")],
             trm = 0.1, max_depth = 10, min_obs = 10, prune = TRUE)
print(fit)


Main Procedure for Restricted Structural Change Analysis

Description

Function for restricted structural change models that performs estimation, hypothesis testing, and critical value simulation.

Usage

mainp(m, q, z, y, trm, robust, prewhit, hetvar, S, s, 
  R, r, doestim, dotest, docv, Tstar, rep, bigt,
  forma, formb, Verbose)

Arguments

m

An integer of number of breaks.

q

An integer of number of regressors.

z

A numeric matrix (T \times q) of regressor.

y

A numeric vector (T \times 1) of dependent variable.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust=1).

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance across segments.

S

Numeric matrix defining the linear reparameterization for Form A: \delta = S\theta + s, where \delta stacks the q coefficients for each of the m+1 regimes (so \delta \in \mathbb{R}^{(m+1)q}). Must have full column rank. If there are no restrictions, set S = diag((m+1) * q).

s

Numeric vector of constants in \delta = S\theta + s, of length (m+1)q. If there are no restrictions, set s = rep(0, (m+1) * q).

R

Numeric matrix defining linear restrictions for Form B, R\delta = r, where \delta \in \mathbb{R}^{(m+1)q} stacks the q coefficients for each of the m+1 regimes. Each row of R represents one linear restriction. Must have full row rank. Do not use this form if there are no restrictions; use Form A instead.

r

Numeric vector of restriction constants in R\delta = r, with length equal to nrow(R).

doestim

An integer (0 or 1). If 1, perform estimation.

dotest

An integer (0 or 1). If 1, perform sup-F test.

docv

An integer (0 or 1). If 1, simulate critical values.

Tstar

An integer of sample size for critical value simulation (default: 500).

rep

An integer of number of Monte Carlo replications (default: 2000).

bigt

An integer of sample size (if NULL, derived from length of y).

forma

An integer (0 or 1). If 1, use Form A restrictions.

formb

An integer (0 or 1). If 1, use Form B restrictions.

Verbose

Logical. If TRUE, print detailed output (default FALSE).

Details

The function supports two forms of linear restrictions on the break-model coefficient vector \delta \in \mathbb{R}^{(m+1)q}:

Both forms can be used simultaneously (forma = 1 and formb = 1), in which case both sets of results are computed and the last one overwrites shared list entries (estimation, test_statistic, critical_values). If both forms are used simultaneously, consider storing results separately.

For testing and critical value simulation, the implied no-break null restrictions on the common coefficient vector \beta are derived automatically via build_null_from_S() (Form A) or build_null_from_R() (Form B).

Value

A list (returned invisibly) with some or all of the following components, depending on the values of doestim, dotest, docv, forma, and formb:

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
R <- matrix(c(1, 0, -1, 0,
              0, 1,  0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
out <- mainp(m = m, q = q, z = z, y = y, trm = trm,
             robust = 0, prewhit = 0, hetvar = 1,
             R = R, r = r,
             doestim = 1, dotest = 0, docv = 0,
             bigt = length(y), forma = 0, formb = 1, Verbose = FALSE)
out$estimation$breaks


Map Bootstrap Break Dates to Original Time Scale

Description

Maps break dates from bootstrap sample back to original time indices. This is the key function: if break point is at position k in bootstrap sample (which has time indices sorted as orig_time_map), then the break date in original time scale is orig_time_map[k].

Usage

map_boot_break_dates_to_original(T_boot, orig_time_map, bigt, h)

Map Break Dates to Bootstrap Sample

Description

Maps break dates from original sample to bootstrap sample indices.

Usage

map_break_dates_to_boot_sample(T_orig, orig_time_map, bigt, h)

Bootstrap restart optimization

Description

Applies bootstrap-based restart and re-optimization after an initial run of mainp. The procedure can be applied taking the break estimates from mainp as starting values. It generates bootstrap samples, re-estimates the break dates, and plugs the new estimates back into the original sample as starting values for re-optimization. This process is repeated to reduce the chance of convergence to a spurious local optimum.

Usage

mbrbp(m, q, z, y, trm, B, T_init, robust, prewhit, hetvar,
  S, s, R, r, doestim, dotest, docv, cvs,
  Tstar, rep, bigt, forma, formb, verbose, resi)

Arguments

m

Integer. Number of breaks.

q

Integer. Number of regressors.

z

Numeric matrix (T \times q). Regressors.

y

Numeric vector of length T. Dependent variable.

trm

Numeric. Trimming parameter.

B

Integer. Number of bootstrap replications.

T_init

Integer vector. Initial break dates (starting values for optimization).

robust

Integer (0 or 1). If 1, use HAC standard errors.

prewhit

Integer (0 or 1). If 1, apply AR(1) prewhitening (only when robust = 1).

hetvar

Integer (0 or 1). If 1, allow heteroskedastic variance across segments.

S

Numeric matrix. Restrictions for Form A (delta = S * theta + s).

s

Numeric vector. Restrictions for Form A.

R

Numeric matrix. Restrictions for Form B (R * delta = r).

r

Numeric vector. Restrictions for Form B.

doestim

Integer (0 or 1). If 1, perform estimation given (re-optimized) break dates.

dotest

Integer (0 or 1). If 1, compute the Sup-F test statistic.

docv

Integer (0 or 1). If 1, simulate critical values.

cvs

Optional. If provided, skip simulation and use these critical values directly.

Tstar

Integer. Sample size for critical value simulation (default: 500).

rep

Integer. Number of Monte Carlo replications (default: 2000).

bigt

Integer. Sample size; if NULL, set to length(y).

forma

Integer (0 or 1). If 1, use Form A restrictions.

formb

Integer (0 or 1). If 1, use Form B restrictions.

verbose

Logical. If TRUE, print progress/output.

resi

Logical. If TRUE, use residual bootstrap restarting (brbp_residual) instead of the default observation-resampling bootstrap (brbp). Residual bootstrap preserves the time ordering of the data. Default is FALSE.

Value

(Invisibly) a list with some or all of the following components, depending on the values of doestim, dotest, docv, forma, and formb:

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373–399.

Wood, S. N. (2001). Minimizing model fitting objectives that contain spurious local minima by bootstrap restarting. Biometrics, 57(1), 240–244.

Examples


data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
R <- matrix(c(1, 0, -1, 0,
              0, 1,  0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
init <- mainp(m = m, q = q, z = z, y = y, trm = trm,
              robust = 0, prewhit = 0, hetvar = 1,
              R = R, r = r,
              doestim = 1, dotest = 0, docv = 0,
              bigt = length(y), forma = 0, formb = 1, Verbose = FALSE)
out <- mbrbp(m = m, q = q, z = z, y = y, trm = trm, B = 3,
             T_init = init$estimation$breaks,
             robust = 0, prewhit = 0, hetvar = 1,
             R = R, r = r,
             doestim = 1, dotest = 0, docv = 0,
             bigt = length(y), forma = 0, formb = 1, verbose = FALSE)
out$estimation$breaks



Simple OLS Regression

Description

Performs ordinary least squares regression. Corresponds to the GAUSS procedure olsqr.

Usage

olsqr(y, x)

Arguments

y

Dependent variable (n x 1)

x

Regressor matrix (n x k)

Value

OLS coefficient estimates (k x 1)


OLS Regression with Residuals and Fitted Values

Description

Performs OLS regression and returns coefficients, residuals, and fitted values. Corresponds to the GAUSS procedure olsqr2. Uses pseudoinverse if matrix is singular (like GAUSS invpd).

Usage

olsqr2(y, x)

Arguments

y

Dependent variable (n x 1)

x

Regressor matrix (n x k)

Value

List with:

b

Coefficient estimates (k x 1)

e

Residuals (n x 1)

fit

Fitted values (n x 1)


Optimal One-Break Partition (Unrestricted)

Description

Obtains an optimal one-break partition for a segment that starts at date start and ends at date last. Corresponds to GAUSS procedure parti.

Usage

parti(start, b1, b2, last, bigvec, bigt)

Arguments

start

Beginning of the segment considered

b1

First possible break date

b2

Last possible break date

last

End of segment considered

bigvec

Vector containing SSR for all possible segments

bigt

Total sample size

Value

List with:

ssrmin

Minimized SSR

dx

Break date


Optimal One-Break Partition (Restricted)

Description

Obtains an optimal one-break partition for a segment under given coefficients. Called only when number of breaks is one. Corresponds to GAUSS procedure parti2.

Usage

parti2(start, b1, b2, last, bigvec2, bigt)

Arguments

start

Beginning of the segment considered

b1

First possible break date

b2

Last possible break date

last

End of segment considered

bigvec2

Vector containing SSR for all segments (size 2*bigt for m=1)

bigt

Total sample size

Value

List with:

ssrmin

Minimized SSR

dx

Break date


Restricted Structural Change Sup-F Test (Form A)

Description

Constructs the supremum F-test for structural change under Form A restrictions.

Usage

pftest(S, S0, y, z, m, q, bigt, trm, robust, prewhit, hetvar, s, s0,
  Verbose)

Arguments

S

Numeric matrix defining the linear reparameterization for Form A: \delta = S\theta + s, where \delta stacks the q coefficients for each of the m+1 regimes (so \delta \in \mathbb{R}^{(m+1)q}). Must have full column rank. If there are no restrictions, set S = diag((m+1) * q).

S0

Numeric matrix of restrictions under the null hypothesis. This should be generated by first running null_model <- build_null_from_S(S, s, m, q, tol = 1e-10) and then setting S0 <- null_model$S0.

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

m

An integer of number of breaks under alternative.

q

An integer of number of regressors.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening.

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance.

s

Numeric vector of constants in \delta = S\theta + s, of length (m+1)q. If there are no restrictions, set s = rep(0, (m+1) * q).

s0

Numeric vector of restriction constants under the null hypothesis. Obtain via s0 <- null_model$s0.

Verbose

Logical. If TRUE, print detailed output (default FALSE).

Value

The F test statistic (returned invisibly).

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
S <- matrix(c(1, 0,
              0, 1,
              1, 0,
              0, 1), nrow = 4, byrow = TRUE)
s <- rep(0, 4)
null_model <- build_null_from_S(S, s, m, q)
pftest(S, null_model$S0, y, z, m, q, length(y), trm,
       0, 0, 1, s, null_model$s0, FALSE)


Restricted Structural Change Sup-F Test (Form B)

Description

Constructs the supremum F-test for structural change under Form B restrictions.

Usage

pftest2(R, R0, y, z, m, q, bigt, trm, robust, prewhit, hetvar, r, r0,
  Verbose)

Arguments

R

Numeric matrix defining linear restrictions for Form B, R\delta = r, where \delta \in \mathbb{R}^{(m+1)q} stacks the q coefficients for each of the m+1 regimes. Each row of R represents one linear restriction. Must have full row rank. Do not use this form if there are no restrictions; use Form A instead.

R0

Numeric matrix of restrictions under the null hypothesis, written in Form B as R_0 \delta = r_0. This should be generated by first running null_model <- build_null_from_R(R, r, m, q, tol = 1e-10) and then setting R0 <- null_model$R0. Do not use this form when there are no restrictions; use pftest instead.

y

A numeric vector (T \times 1) of dependent variable.

z

A numeric matrix (T \times q) of regressor.

m

An integer of number of breaks under alternative.

q

An integer of number of regressors.

bigt

An integer of sample size.

trm

A numeric value of trimming parameter.

robust

An integer (0 or 1). If 1, use HAC standard errors.

prewhit

An integer (0 or 1). If 1, apply AR(1) prewhitening.

hetvar

An integer (0 or 1). If 1, allow heteroskedastic variance.

r

Numeric vector of restriction constants in R\delta = r, with length equal to nrow(R).

r0

Numeric vector of restriction constants under the null hypothesis. Obtain via r0 <- null_model$r0.

Verbose

Logical. If TRUE, print detailed output.

Value

The F test statistic (returned invisibly).

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples

data(example)
y <- example$y
z <- matrix(1, length(y), 1)
m <- 3
q <- 1
trm <- 0.10
R <- matrix(c(1, 0, -1, 0,
              0, 1,  0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
null_model <- build_null_from_R(R, r, m, q)
pftest2(R, null_model$R0, y, z, m, q, length(y), trm,
        0, 0, 1, r, null_model$r0, FALSE)


Compute F-statistic given break dates

Description

Compute F-statistic given break dates

Usage

pftest_fb(
  y,
  z,
  m,
  q,
  bigt,
  trm,
  S,
  s,
  S0,
  T_init,
  robust = 1,
  prewhit = 0,
  hetvar = 1,
  Verbose = FALSE
)

Arguments

y

A numeric vector of dependent variable

z

A numeric matrix of regressors

m

Number of breaks

q

Number of regressors

bigt

Sample size

trm

Trimming parameter

S

Form A restriction matrix

s

Form A restriction vector

S0

Form A null hypothesis restriction

T_init

Initial break dates for brbp_residual

robust

Use robust variance (0 or 1)

prewhit

Use prewhitening (0 or 1)

hetvar

Allow heteroskedastic variance (0 or 1)

Verbose

Logical. If TRUE, print detailed output (default FALSE).

Value

F-test statistic value


Pseudo-Inverse

Description

Computes the pseudo-inverse (Moore-Penrose inverse) of a matrix. Corresponds to GAUSS function pinv.

Usage

pinv(A)

Arguments

A

Matrix

Value

Pseudo-inverse matrix


Diagonal Matrix of Segment Proportions

Description

Constructs a diagonal matrix with (T_i - T_(i-1))/T on the diagonal. Corresponds to GAUSS procedure plambda.

Usage

plambda(b, m, bigt)

Arguments

b

Break dates vector (m x 1)

m

Number of breaks

bigt

Sample size

Value

Diagonal matrix (m+1 x m+1)


Diagonal Matrix of Segment-Specific Residual Variances

Description

Computes a diagonal matrix with the variance of residuals for each segment. Corresponds to GAUSS procedure psigmq.

Usage

psigmq(res, b, q, m, nt)

Arguments

res

Residual vector (T x 1)

b

Break dates vector (m x 1)

q

Number of regressors

m

Number of breaks

nt

Sample size

Value

Diagonal matrix (m+1 x m+1)


Variance-Covariance Matrix of Delta

Description

Computes the variance-covariance matrix of the coefficient estimates. Corresponds to GAUSS procedure pvdel.

Usage

pvdel(y, z, i, q, bigt, b, coeff, prewhit, robust, hetvar)

Arguments

y

Dependent variable (T x 1)

z

Regressor matrix (T x q)

i

Number of breaks (same as m)

q

Number of regressors

bigt

Sample size

b

Break dates (m x 1)

coeff

Coefficient estimates ((m+1)*q x 1)

prewhit

Integer; if 1 apply AR(1) prewhitening (only if robust=1)

robust

Integer; if 0 use standard errors, if 1 use HAC

hetvar

Integer; if 1 allow heteroskedastic variance across segments

Value

Variance-covariance matrix ((m+1)*q x (m+1)*q)


Create diagonal partition of z matrix

Description

Constructs the diagonal block matrix Z_bar for m breaks. Corresponds to the GAUSS procedure pzbar.

Usage

pzbar(zz, m, bb)

Arguments

zz

Matrix of regressors (T x q)

m

Number of breaks

bb

Vector of break dates (m x 1)

Value

Diagonal block matrix Z_bar (T x (m+1)*q)


Qu's Algorithm Wrapper

Description

Wrapper function for Qu's algorithm (est or est2) with initial break dates.

Usage

qu_algorithm(y, z, q, m, bigt, trm, T_init, S, s, R, r)

Simulate Critical Values of Sup-F Test (Form A)

Description

Simulates critical values for the restricted structural change sup-F test using Monte Carlo methods with Form A restrictions.

Usage

rcv(Tstar, rep, q, m, S, s, S0, s0, trm, Verbose)

Arguments

Tstar

An integer of sample size for simulation (default: 500).

rep

An integer of number of Monte Carlo replications (default: 2000).

q

An integer of number of regressors in a single regime.

m

An integer of number of breaks under the alternative.

S

Numeric matrix defining the linear reparameterization for Form A: \delta = S\theta + s, where \delta stacks the q coefficients for each of the m+1 regimes (so \delta \in \mathbb{R}^{(m+1)q}). Must have full column rank. If there are no restrictions, set S = diag((m+1) * q).

s

Numeric vector of constants in \delta = S\theta + s, of length (m+1)q. If there are no restrictions, set s = rep(0, (m+1) * q).

S0

Numeric matrix of restrictions under the null hypothesis. This should be generated by first running null_model <- build_null_from_S(S, s, m, q, tol = 1e-10) and then setting S0 <- null_model$S0.

s0

Numeric vector of restriction constants under the null hypothesis. Obtain via s0 <- null_model$s0.

trm

A numeric value of trimming parameter.

Verbose

Logical. If TRUE, print progress messages.

Value

A numeric vector of length 4 containing critical values at 90%, 95%, 97.5%, and 99% quantiles.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples


m <- 3
q <- 1
trm <- 0.10
S <- matrix(c(1, 0,
              0, 1,
              1, 0,
              0, 1), nrow = 4, byrow = TRUE)
s <- rep(0, 4)
null_model <- build_null_from_S(S, s, m, q)
rcv(Tstar = 40, rep = 5, q = q, m = m,
    S = S, s = s, S0 = null_model$S0, s0 = null_model$s0,
    trm = trm, Verbose = FALSE)



Simulate Critical Values of Sup-F Test (Form B)

Description

Simulates critical values for the restricted structural change sup-F test using Monte Carlo methods with Form B restrictions.

Usage

rcv2(Tstar, rep, q, m, R, r, R0, r0, trm, Verbose)

Arguments

Tstar

An integer of sample size for simulation (recommended: 500).

rep

An integer of number of Monte Carlo replications (recommended: 2000).

q

An integer of number of regressors in a single regime.

m

An integer of number of breaks under the alternative.

R

Numeric matrix defining linear restrictions for Form B, R\delta = r, where \delta \in \mathbb{R}^{(m+1)q} stacks the q coefficients for each of the m+1 regimes. Each row of R represents one linear restriction. Must have full row rank. Do not use this form if there are no restrictions; use Form A instead.

r

Numeric vector of restriction constants in R\delta = r, with length equal to nrow(R).

R0

Numeric matrix of restrictions under the null hypothesis, written in Form B as R_0 \delta = r_0, generated by first running null_model <- build_null_from_R(R, r, m, q, tol = 1e-10) and then setting R0 <- null_model$R0. Do not use this form when there are no restrictions; use pftest instead.

r0

Numeric vector of restriction constants under the null hypothesis. Obtain via r0 <- null_model$r0.

trm

A numeric value of trimming parameter.

Verbose

Logical. If TRUE, print progress messages.

Value

A numeric vector of length 4 containing critical values at 90%, 95%, 97.5%, and 99% quantiles.

References

Perron, P., and Qu, Z. (2006). Estimating restricted structural change models. Journal of Econometrics, 134(2), 373-399.

Examples


m <- 3
q <- 1
trm <- 0.10
R <- matrix(c(1, 0, -1, 0,
              0, 1,  0, -1), nrow = 2, byrow = TRUE)
r <- c(0, 0)
null_model <- build_null_from_R(R, r, m, q)
rcv2(Tstar = 40, rep = 5, q = q, m = m,
     R = R, r = r, R0 = null_model$R0, r0 = null_model$r0,
     trm = trm, Verbose = FALSE)



Simulate Critical Values of Sup-F Test (Form B) - Parallel Version

Description

Simulates critical values using parallel processing for faster computation.

Usage

rcv2_parallel(Tstar, rep, q, m, R, r, R0, r0, trm, n_cores = NULL)

Arguments

Tstar

An integer of sample size for simulation (recommended: 1000).

rep

An integer of number of Monte Carlo replications (recommended: 1000).

q

An integer of number of regressors in a single regime.

m

An integer of number of breaks under the alternative.

R

Numeric matrix defining linear restrictions for Form B, R\delta = r, where \delta \in \mathbb{R}^{(m+1)q} stacks the q coefficients for each of the m+1 regimes. Each row of R represents one linear restriction. Must have full row rank. Do not use this form if there are no restrictions; use Form A instead.

r

Numeric vector of restriction constants in R\delta = r, with length equal to nrow(R).

R0

Numeric matrix of restrictions under the null hypothesis, written in Form B as R_0 \delta = r_0. This should be generated by first running null_model <- build_null_from_R(R, r, m, q, tol = 1e-10) and then setting R0 <- null_model$R0. Do not use this form when there are no restrictions; use pftest instead.

r0

Numeric vector of restriction constants under the null hypothesis. Obtain via r0 <- null_model$r0.

trm

A numeric value of trimming parameter.

n_cores

An integer of number of CPU cores to use (default: parallel::detectCores() - 1).

Value

A numeric vector of length 4 containing critical values at 90%, 95%, 97.5%, and 99% quantiles.


Simulate Critical Values of Sup-F Test (Form A) - Parallel Version

Description

Simulates critical values using parallel processing for faster computation.

Usage

rcv_parallel(Tstar, rep, q, m, S, s, S0, s0, trm, n_cores = NULL)

Arguments

Tstar

An integer of sample size for simulation (recommended: 1000).

rep

An integer of number of Monte Carlo replications (recommended: 1000).

q

An integer of number of regressors in a single regime.

m

An integer of number of breaks under the alternative.

S

Numeric matrix defining the linear reparameterization for Form A: \delta = S\theta + s, where \delta stacks the q coefficients for each of the m+1 regimes (so \delta \in \mathbb{R}^{(m+1)q}). Must have full column rank. If there are no restrictions, set S = diag((m+1) * q).

s

Numeric vector of constants in \delta = S\theta + s, of length (m+1)q. If there are no restrictions, set s = rep(0, (m+1) * q).

S0

Numeric matrix of restrictions under the null hypothesis. This should be generated by first running null_model <- build_null_from_S(S, s, m, q, tol = 1e-10) and then setting S0 <- null_model$S0.

s0

Numeric vector of restriction constants under the null hypothesis. Obtain via s0 <- null_model$s0.

trm

A numeric value of trimming parameter.

n_cores

An integer of number of CPU cores to use (default: parallel::detectCores() - 1).

Value

A numeric vector of length 4 containing critical values at 90%, 95%, 97.5%, and 99% quantiles.


Recursive Sum of Squared Residuals

Description

Computes recursive residuals from a data set starting at date "start" and ending at date "last".

Usage

ssr(start, y, z, h, last)

Arguments

start

Starting entry of the sample (1-indexed)

y

Dependent variable (T x 1)

z

Regressor matrix (T x q)

h

Minimal length of a segment

last

Ending date of the last segment

Value

Vector of SSR values (last x 1). First h-1 elements have no meaning.


SSR for All Possible Segments

Description

Creates a matrix storing the SSR for all possible segments under estimated coefficients. Corresponds to GAUSS procedure ssr2.

Usage

ssr2(y, z, b, q, m)

Arguments

y

Dependent variable (T x 1)

z

Regressor matrix (T x q)

b

Estimated coefficients ((m+1)*q x 1)

q

Number of regressors

m

Number of breaks

Value

Vector of SSR values (T*(m+1) x 1)


Utility Functions for Restricted Structural Change Models

Description

Utility Functions for Restricted Structural Change Models