Title: Cross-Sectional Dependence Models
Version: 1.0.0
Depends: R (≥ 4.0.0)
Imports: MASS
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown, kableExtra, xtsum, spelling
Description: Provides estimators and utilities for large panel-data models with cross-sectional dependence, including mean group (MG), common correlated effects (CCE) and dynamic CCE (DCCE) estimators, and cross-sectionally augmented ARDL (CS-ARDL) specifications, plus related inference and diagnostics.
License: GPL-3
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Config/testthat/edition: 3
VignetteBuilder: knitr
Language: en-US
NeedsCompilation: no
Packaged: 2026-02-17 20:26:55 UTC; Joaoc
Author: Joao Claudio Macosso [aut, cre]
Maintainer: Joao Claudio Macosso <joaoclaudiomacosso@gmail.com>
Repository: CRAN
Date/Publication: 2026-02-20 10:10:02 UTC

Penn World Tables panel (93 countries, 1960–2007)

Description

A panel of 93 countries (unit id) observed annually over 1960–2007 (time/year), with the log-transformed variables used in xtdcce2-style examples.

Usage

PWT_60_07

Format

A data frame with 4464 rows and 6 variables:

id

Unit identifier (country id).

year

Time identifier (year, 1960–2007).

log_rgdpo

Log real GDP (output).

log_hc

Log human capital index.

log_ck

Log capital stock.

log_ngd

Log (net) government debt (or similar), used as a covariate/control.

Source

Penn World Table (PWT). This dataset is included as a small, convenient panel for examples and tests.


Cross-sectional dependence (CD) tests for panel residuals

Description

Computes Pesaran CD, CDw, CDw+, and CD* tests for cross-sectional dependence in panel residuals. The implementation supports residual matrices or fitted csdm_fit objects and provides consistent handling of unbalanced panels.

Usage

cd_test(object, ...)

## Default S3 method:
cd_test(
  object,
  type = c("CD", "CDw", "CDw+", "CDstar", "all"),
  n_pc = 4L,
  seed = NULL,
  min_overlap = 2L,
  na.action = c("drop.incomplete.times", "pairwise"),
  ...
)

## S3 method for class 'csdm_fit'
cd_test(
  object,
  type = c("CD", "CDw", "CDw+", "CDstar", "all"),
  n_pc = 4L,
  seed = NULL,
  min_overlap = 2L,
  na.action = c("drop.incomplete.times", "pairwise"),
  ...
)

## S3 method for class 'cd_test'
print(x, digits = 3, ...)

Arguments

object

A csdm_fit model object or a numeric matrix of residuals (N x T).

...

Additional arguments passed to methods.

type

Which test(s) to compute: one of "CD", "CDw", "CDw+", "CDstar", or "all" (default: "CD").

n_pc

Number of principal components for CD* (default 4).

seed

Integer seed for weight draws in CDw/CDw+ (default NULL = no seed set).

min_overlap

Minimum number of overlapping time periods required for a unit pair to be included in CD/CDw/CDw+ (default 2).

na.action

How to handle missing data: "drop.incomplete.times" (default) removes time periods with any missing observations to create a balanced panel for CD*; "pairwise" uses pairwise correlations for CD/CDw/CDw+ and warns for CD*.

x

An object of class cd_test.

digits

Number of digits to print (default 3).

Details

Notation

Let E be the residual matrix with N cross-sectional units and T time periods. For each unit pair (i,j), let T_{ij} be the number of overlapping time periods and \rho_{ij} the pairwise correlation.

Test statistics

CD (Pesaran, 2015)

CD = \sqrt{\frac{2}{N(N-1)}} \sum_{i<j} \sqrt{T_{ij}} \, \rho_{ij}

CDw (Juodis and Reese, 2021)

Random sign flips w_i \in \{-1,1\} are applied to residuals before computing correlations. The statistic is CD applied to the sign-flipped data.

CDw+ (Fan, Liao, and Yao, 2015)

Power enhancement adds a sparse thresholding term to CDw. The threshold is

c_N = \sqrt{\frac{2 \log(N)}{T}}

and the power term sums \sqrt{T_{ij}} |\rho_{ij}| for pairs exceeding the threshold.

CD* (Pesaran and Xie, 2021)

CD is computed on residuals after removing n_pc principal components from E. This provides a bias-corrected test under multifactor errors.

Missing data and balance

CD, CDw, CDw+

Always use pairwise-complete observations. Each pairwise correlation uses available overlaps.

CD*

Requires a balanced panel. By default, na.action = "drop.incomplete.times" removes any time period with missing observations. With na.action = "pairwise", CD* returns NA and a warning when missing values are present.

Value

An object of class cd_test with fields tests, type, N, T, na.action, and call. The tests list contains one or more test results, each with statistic and p.value.

References

Pesaran, M.H. (2015). "Testing weak cross-sectional dependence in large panels." Econometric Reviews, 34(6-10), 1089-1117.

Pesaran, M.H. (2021). "General diagnostic tests for cross-sectional dependence in panels." Empirical Economics, 60, 13-50.

Juodis, A., & Reese, S. (2021). "The incidental parameters problem in testing for remaining cross-sectional correlation." Journal of Business and Economic Statistics, 40(3), 1193-1203.

Fan, J., Liao, Y., & Yao, J. (2015). "Power Enhancement in High-Dimensional Cross-Sectional Tests." Econometric Reviews, 34(6-10), 742-779.

Pesaran, M.H., & Xie, Y. (2021). "A bias-corrected CD test for error cross-sectional dependence in panel models." Econometric Reviews, 41(6), 649-677.

Examples

# Simulate independent and dependent panels
set.seed(1)
E_indep <- matrix(rnorm(100), nrow = 10)
E_dep <- matrix(rnorm(10), nrow = 10, ncol = 10, byrow = TRUE)

# Compute all tests
cd_test(E_indep, type = "all")
cd_test(E_dep, type = "all")

# Specific test with parameters
cd_test(E_indep, type = "CDstar", n_pc = 2)

# From a fitted csdm model
data(PWT_60_07, package = "csdm")
df <- PWT_60_07
ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% ids & df$year >= 1970, ]
fit <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small,
  id = "id",
  time = "year",
  model = "cce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"))
)
cd_test(fit, type = "all")


Cluster-robust variance-covariance for OLS

Description

Computes one- or two-way cluster-robust vcov for an OLS design using the Liang-Zeger "meat" and Cameron-Gelbach-Miller inclusion-exclusion for two-way clustering.

Usage

cluster_vcov(X, u, cluster, df_correction = TRUE, type = c("oneway", "twoway"))

Arguments

X

Numeric design matrix (n x k) used in OLS.

u

Numeric residual vector (length n).

cluster

One of:

  • a vector (length n) of cluster ids for one-way clustering; or

  • a data.frame/list with two vectors (each length n) for two-way clustering.

df_correction

Logical; apply small-sample corrections. Default TRUE.

type

Character, one of "oneway" or "twoway".

Value

A k x k variance-covariance matrix.


Extract model coefficients from a fitted csdm model

Description

Returns estimated mean-group coefficients from a csdm_fit object. For model = "cs_ardl", the returned vector includes short-run mean-group coefficients, the adjustment coefficient (named lr_<y>), and long-run coefficients when available.

Usage

## S3 method for class 'csdm_fit'
coef(object, ...)

Arguments

object

A fitted object of class csdm_fit.

...

Currently unused.

Value

A named numeric vector of estimated coefficients.

See Also

summary.csdm_fit(), vcov.csdm_fit()


Cross-sectional averages by time (with optional leave-one-out)

Description

Computes cross-sectional averages (CSAs) of specified variables for each time period, optionally in a leave-one-out (LOO) fashion per observation. Supports unbalanced panels and observation weights.

Usage

cross_sectional_avg(
  data,
  id = NULL,
  time = NULL,
  vars,
  leave_out = FALSE,
  weights = NULL,
  suffix = "csa",
  return_mode = c("attach", "time"),
  na.rm = TRUE
)

Arguments

data

A data.frame or plm::pdata.frame.

id, time

Character scalar names of unit and time columns when data is a plain data.frame. If data is a pdata.frame, these are inferred from its index and can be omitted.

vars

Character vector of column names to average cross-sectionally.

leave_out

Logical; if TRUE, computes LOO means for each row: \bar{x}_{-i,t} = (\sum_{j \neq i} w_{jt} x_{jt}) / (\sum_{j \neq i} w_{jt}). If FALSE, computes standard time means: \bar{x}_{t} = (\sum_j w_{jt} x_{jt}) / (\sum_j w_{jt}).

weights

Optional. Either:

  • a numeric vector of length nrow(data), or

  • the name of a column in data with nonnegative weights.

If NULL, uses equal weights (1 for observed values).

suffix

Character suffix to append to CSA columns (default "csa").

return_mode

One of "attach" or "time".

  • "attach" returns the original data with CSA columns added.

  • "time" returns a unique-time table [time, csa_*].

na.rm

Logical; if TRUE, excludes NAs from sums and denominators. If FALSE, any NA in a time slice yields NA for that time's CSA for that variable.

Details

Efficiently computes, for each v in vars and time t,

\bar v_t = \frac{\sum_i w_{it}\, 1_{\{v_{it}\text{ finite}\}}\, v_{it}} {\sum_i w_{it}\, 1_{\{v_{it}\text{ finite}\}}}

For leave_out=TRUE, each row's CSA excludes its own contribution; if the denominator becomes \le 0 (e.g., only one finite observation at that time), the LOO mean is set to NA for that row/variable.

Value

A data.frame:


Panel Model Estimation with Cross Section Dependence

Description

Estimate panel data models that allow for cross-sectional dependence and heterogeneous slopes. The interface supports Mean Group (MG), Common Correlated Effects (CCE), Dynamic CCE (DCCE), and Cross-Sectionally Augmented ARDL (CS-ARDL) estimators with consistent handling of cross-sectional averages, dynamic structure, and robust inference.

Usage

csdm(
  formula,
  data,
  id,
  time,
  model = c("mg", "cce", "dcce", "cs_ardl", "cs_ecm", "cs_dl"),
  csa = csdm_csa(),
  lr = csdm_lr(),
  pooled = csdm_pooled(),
  trend = c("none", "unit", "pooled"),
  fullsample = FALSE,
  mgmissing = FALSE,
  vcov = csdm_vcov(),
  ...
)

Arguments

formula

Model formula of the form y ~ x1 + x2.

data

A data.frame (or plm::pdata.frame) containing the variables in formula.

id, time

Column names (strings) for the unit and time indexes. If data is a pdata.frame, these are taken from its index and the provided values are ignored.

model

Estimator to fit. One of "mg", "cce", "dcce", or "cs_ardl".

csa

Cross-sectional-average specification, created by csdm_csa().

lr

Long-run or dynamic specification, created by csdm_lr().

pooled

Pooled specification (reserved for future use), created by csdm_pooled().

trend

One of "none" or "unit" (adds a linear unit trend). "pooled" is reserved and not implemented.

fullsample

Logical; reserved for future extensions.

mgmissing

Logical; reserved for future extensions.

vcov

Variance-covariance specification, created by csdm_vcov().

...

Reserved for future extensions.

Details

Model equations

MG (Pesaran and Smith, 1995)

y_{it} = x_{it}^\top \beta_i + u_{it}

CCE (Pesaran, 2006)

y_{it} = x_{it}^\top \beta_i + \lambda_i^\top F_t + u_{it}

DCCE (Chudik and Pesaran, 2015)

\Delta y_{it} = \Delta x_{it}^\top \beta_i + \lambda_i^\top \Delta F_t + u_{it}

CS-ARDL (Chudik and Pesaran, 2015)

y_{it} = \phi_i y_{it-1} + x_{it}^\top \theta_i + \lambda_i^\top F_t + u_{it}

Estimation, identification, and assumptions

MG

Unit-by-unit estimation with heterogeneous slopes. The reported coefficients are cross-sectional averages of unit estimates. Requires sufficient time series per unit and weak serial dependence in errors.

CCE

Augments regressions with cross-sectional averages (CSA) to proxy unobserved common factors. Identification relies on large N and T, weak dependence in idiosyncratic errors after CSA, and weak exogeneity of regressors.

DCCE

Extends CCE to dynamic settings with lagged dependent variables and CSA lags. Identification relies on weak exogeneity, adequate time length for dynamic lags, and a stable factor structure.

CS-ARDL

Specifies dynamic distributed lags with CSA terms. Estimation follows ARDL-style dynamics in each unit and aggregates to panel averages. Assumes weak exogeneity and sufficient time length for lag structure.

Value

An object of class csdm_fit containing estimated coefficients, residuals, variance-covariance estimates, model metadata, and diagnostics. Use summary(), coef(), residuals(), vcov(), and cd_test() to access standard outputs.

References

Pesaran, M.H. and Smith, R. (1995). "Estimating long-run relationships from dynamic heterogeneous panels." Journal of Econometrics, 68(1), 79-113.

Pesaran, M.H. (2006). "Estimation and inference in large heterogeneous panels with multifactor error structure." Econometrica, 74(4), 967-1012.

Chudik, A. and Pesaran, M.H. (2015). "Common correlated effects estimation of heterogeneous dynamic panel data models with weakly exogenous regressors." Journal of Econometrics, 188(2), 393-420.

Chudik, A. and Pesaran, M.H. (2015). "Large panel data models with cross-sectional dependence: A survey." Annals of Economics and Finance, 16(1), 53-78.

Examples

library(csdm)
data(PWT_60_07, package = "csdm")
df <- PWT_60_07

# Keep examples fast but fully runnable
keep_ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% keep_ids & df$year >= 1970, ]

# Mean Group (MG)
mg <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small, id = "id", time = "year", model = "mg"
)
summary(mg)

# Common Correlated Effects (CCE)
cce <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small, id = "id", time = "year", model = "cce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"))
)
summary(cce)

# Dynamic CCE (DCCE)
dcce <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small, id = "id", time = "year", model = "dcce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"), lags = 3),
  lr = csdm_lr(type = "ardl", ylags = 1, xdlags = 0)
)
summary(dcce)

# CS-ARDL
cs_ardl <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small, id = "id", time = "year", model = "cs_ardl",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"), lags = 3),
  lr = csdm_lr(type = "ardl", ylags = 1, xdlags = 0)
)
summary(cs_ardl)

Specification: Cross-sectional averages (CSA)

Description

Specification: Cross-sectional averages (CSA)

Usage

csdm_csa(
  vars = "_all",
  lags = 0,
  scope = c("estimation", "global", "cluster"),
  cluster = NULL
)

Arguments

vars

Character. One of "_all", "_none", or a character vector of variable names.

lags

Integer. Either a scalar integer >= 0 applied to all CSA variables, or a named integer vector giving per-variable maximum lags.

scope

Character vector. One or more of c("estimation","global","cluster").

cluster

Reserved for future use.

Value

A spec object (list) used by csdm().

Examples

# Cross-sectional averages (CSA) configuration for DCCE
csa <- csdm_csa(
  vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"),
  lags = 3
)
csa

Specification: Long-run configuration

Description

Specification: Long-run configuration

Usage

csdm_lr(
  vars = NULL,
  type = c("none", "ecm", "ardl", "csdl"),
  ylags = 0,
  xdlags = 0,
  options = list()
)

Arguments

vars

Reserved for future use.

type

One of c("none","ecm","ardl","csdl").

ylags

Integer >= 0. Within-unit lags of the dependent variable to include when supported by the chosen model/type.

xdlags

Integer >= 0. Scalar distributed lags to apply to each RHS regressor when supported by the chosen model/type.

options

Reserved for future use.

Value

A spec object (list) used by csdm().

Examples

# Long-run / dynamic configuration (ARDL-style lags)
lr <- csdm_lr(type = "ardl", ylags = 1)
lr

# Minimal end-to-end DCCE example (kept small for speed)
data(PWT_60_07, package = "csdm")
df <- PWT_60_07
keep_ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% keep_ids & df$year >= 1970, ]
fit <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small,
  id = "id",
  time = "year",
  model = "dcce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"), lags = 3),
  lr = csdm_lr(type = "ardl", ylags = 1)
)
summary(fit)

Specification: Pooled constraints (stub)

Description

Specification: Pooled constraints (stub)

Usage

csdm_pooled(vars = NULL, constant = FALSE, trend = FALSE)

Arguments

vars

Reserved for future use.

constant

Logical; pooled constant.

trend

Logical; pooled trend.

Value

A spec object (list) used by csdm().


Specification: Variance-covariance for MG output (stub)

Description

Specification: Variance-covariance for MG output (stub)

Usage

csdm_vcov(type = c("mg", "np", "nw", "wpn", "ols"), ...)

Arguments

type

One of c("mg","np","nw","wpn","ols").

...

Reserved for future use.

Value

A spec object (list) used by csdm().


Extract residual matrices for panel diagnostics

Description

Unified accessor that returns an N x T residual matrix suitable for cross-sectional dependence diagnostics and post-estimation analysis.

Usage

get_residuals(object, type = c("auto", "cce", "pca", "pca_std"), strict = TRUE)

Arguments

object

A fitted model object supported by this package (e.g., class csdm_fit), or directly a numeric matrix of residuals shaped as N x T.

type

Character string selecting which residuals to return when available: one of "auto", "cce", "pca", or "pca_std".

  • "auto": prefer standardized PCA residuals if present, otherwise PCA residuals, otherwise CCE residuals, otherwise object if it is a matrix.

  • "cce": residuals from the CCE-augmented per-unit regressions.

  • "pca": residuals after removing estimated factors from \hat v_{it}.

  • "pca_std": "pca" residuals standardized by unit-specific scale (recommended for CD).

strict

Logical; if TRUE, error on unsupported objects. If FALSE, return NULL when residuals cannot be found.

Details

Residual types

cce

Residuals from the cross-sectionally augmented unit regressions.

pca

Residuals after principal-component factor removal.

pca_std

PCA residuals standardized by unit-specific scale.

auto

Priority rule: pca_std -> pca -> cce -> generic residual slots.

Assumptions and usage

The returned matrix is intended for diagnostics that operate on unit-time panels, including cd_test(). Missing values are preserved unless downstream routines explicitly filter or balance the panel.

Value

A numeric matrix of residuals with rows = units and columns = time, preserving rownames and colnames when available; or NULL if nothing suitable is found and strict = FALSE.

Examples

data(PWT_60_07, package = "csdm")
df <- PWT_60_07
ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% ids & df$year >= 1970, ]

fit <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small,
  id = "id",
  time = "year",
  model = "cce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"))
)

E <- get_residuals(fit, type = "auto")
dim(E)


Variance-covariance of Mean-Group (MG) averages

Description

Computes the covariance matrix of the MG estimator \bar{\beta} = N^{-1} \sum_i \hat\beta_i, using the cross-sectional covariance of unit-specific slopes and dividing by the effective sample sizes per coefficient (handles missing entries per unit).

Usage

pooled_vcov(beta_i, weights = NULL, pairwise = TRUE)

Arguments

beta_i

Numeric matrix of unit-specific coefficients (N x K); rows = units, columns = coefficients. May contain NAs.

weights

Optional numeric vector of length N with nonnegative weights summing to 1. If NULL, uses equal weights.

pairwise

Logical; use pairwise-complete covariances across units (default TRUE).

Details

For equal weights, diagonal entries coincide with \widehat{\mathrm{Var}}(\hat\beta_{ij}) / N_{\text{eff},j}. Off-diagonals are scaled analogously using pairwise effective N. If weights are provided, computes \mathrm{Var}(\sum_i w_i \hat\beta_i) using a weighted covariance.

Value

A K x K covariance matrix for the MG mean, with dimnames inherited from colnames(beta_i).


Predict method for csdm models

Description

Produces fitted values (index "xb") when available, or returns model residuals. Prediction on new data is not yet implemented.

Usage

## S3 method for class 'csdm_fit'
predict(object, newdata = NULL, type = c("xb", "residuals"), ...)

Arguments

object

A fitted object of class csdm_fit.

newdata

Optional new data (not yet supported).

type

One of "xb" for fitted values or "residuals".

...

Currently unused.

Value

A numeric matrix of fitted values or residuals, depending on type.

See Also

residuals.csdm_fit(), summary.csdm_fit()


Prepare residual matrices for CD and CD* diagnostics

Description

Cleans and transforms an N x T residual matrix for cross-sectional dependence testing. Operations include:

  1. Dropping time periods with fewer than min_per_time finite observations.

  2. Optional row-wise standardization to unit variance over available times.

  3. Optional demeaning across units at each time (recommended for CD).

Usage

prepare_cd_input(
  E,
  standardize = c("row", "none"),
  demean_time = TRUE,
  min_per_time = 2L
)

Arguments

E

A numeric matrix of residuals (N x T); rows are units, columns are time; may be unbalanced (contain NA).

standardize

One of "row", "none". If "row", scale each row by its observed standard deviation.

demean_time

Logical; if TRUE, subtract the cross-sectional mean at each time from available residuals in that column.

min_per_time

Integer; drop time columns with fewer than this many finite observations.

Details

Transformation steps

  1. Time periods with fewer than min_per_time finite observations are removed.

  2. If standardize = "row", each unit is scaled by its observed standard deviation.

  3. If demean_time = TRUE, each time slice is demeaned across available units.

Why this preprocessing matters

CD-type tests are sensitive to scale heterogeneity and sparse columns in unbalanced panels. This helper creates a better-conditioned input matrix while preserving as much usable information as possible.

Value

A list with:

Z

Processed residual matrix (N x T^*) after filtering/standardizing/demeaning.

kept_t

Integer indices of kept time columns (relative to the original E).

m_t

Integer vector of cross-sectional counts per kept time (number of finite rows).

row_sds

Numeric vector of row standard deviations used (invisibly NA if standardize="none").

col_means

Numeric vector of time means subtracted when demean_time=TRUE.

Examples

data(PWT_60_07, package = "csdm")
df <- PWT_60_07
ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% ids & df$year >= 1970, ]
fit <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small,
  id = "id",
  time = "year",
  model = "cce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"))
)
E <- get_residuals(fit)
prep <- prepare_cd_input(E, standardize = "row", demean_time = TRUE, min_per_time = 3)
dim(prep$Z)


Compact print method for fitted csdm models

Description

Prints a concise overview of a fitted csdm_fit object, including the model type, formula, panel dimensions, and a coefficient table with standard errors when available.

Usage

## S3 method for class 'csdm_fit'
print(x, digits = 4, ...)

Arguments

x

A fitted object of class csdm_fit.

digits

Number of printed digits.

...

Currently unused.

Value

Invisibly returns x.

See Also

summary.csdm_fit(), coef.csdm_fit(), residuals.csdm_fit()


Print method for csdm summary objects

Description

Formats and prints a summary.csdm_fit object. Output adapts to model type and includes coefficient tables, selected goodness-of-fit diagnostics, and compact model metadata.

Usage

## S3 method for class 'summary.csdm_fit'
print(x, digits = 4, ...)

Arguments

x

A summary.csdm_fit object.

digits

Number of digits to print.

...

Further arguments passed to methods.

Details

The printout includes classic Pesaran CD diagnostics from the summary object. For a full CD diagnostic panel (CD, CDw, CDw+, CD*), use cd_test() on the fitted model.

Value

Invisibly returns x.

See Also

summary.csdm_fit(), cd_test()


Extract residual matrix from a fitted csdm model

Description

Returns residuals as an N x T matrix (rows are units, columns are time). This method is designed for panel diagnostics and downstream tools such as cd_test().

Usage

## S3 method for class 'csdm_fit'
residuals(object, type = c("e", "u"), ...)

Arguments

object

A fitted object of class csdm_fit.

type

Residual type. Currently only "e" is implemented.

...

Currently unused.

Value

A numeric matrix of residuals with dimensions N x T.

See Also

get_residuals(), cd_test(), predict.csdm_fit()


Heteroskedasticity-robust (HC) sandwich variance-covariance for OLS

Description

Computes White/Huber HC0-HC3 sandwich vcov for an OLS design.

Usage

sandwich_vcov(X, u, type = c("HC0", "HC1", "HC2", "HC3"))

Arguments

X

Numeric design matrix (n x k) used in OLS.

u

Numeric residual vector (length n).

type

Character; one of "HC0", "HC1", "HC2", "HC3".

Value

A k x k variance-covariance matrix.


Summarize csdm model estimation results

Description

Computes post-estimation summaries for csdm_fit objects, including mean-group coefficient inference, model-level diagnostics, and model-specific summary tables (for example, short-run and long-run blocks for CS-ARDL).

Usage

## S3 method for class 'csdm_fit'
summary(object, digits = 4, ...)

Arguments

object

A fitted model object of class csdm_fit.

digits

Number of digits to print.

...

Further arguments passed to methods.

Details

Reported inference

For each coefficient \hat\beta_k, the summary reports standard errors, z-statistics, and two-sided normal-approximation p-values:

z_k = \frac{\hat\beta_k}{\operatorname{se}(\hat\beta_k)}, \qquad p_k = 2\{1-\Phi(|z_k|)\}.

Diagnostics

The printed summary shows the classic Pesaran CD diagnostic by default. Extended diagnostics (CDw, CDw+, CD*) are available through cd_test().

Value

An object of class summary.csdm_fit with core metadata (call/formula/model/N/T), coefficient tables, fit statistics, and model-specific components for printing and downstream inspection.

See Also

print.summary.csdm_fit(), cd_test(), coef.csdm_fit(), vcov.csdm_fit()

Examples

data(PWT_60_07, package = "csdm")
df <- PWT_60_07
ids <- unique(df$id)[1:10]
df_small <- df[df$id %in% ids & df$year >= 1970, ]
fit <- csdm(
  log_rgdpo ~ log_hc + log_ck + log_ngd,
  data = df_small,
  id = "id",
  time = "year",
  model = "cce",
  csa = csdm_csa(vars = c("log_rgdpo", "log_hc", "log_ck", "log_ngd"))
)
s <- summary(fit)
s

Extract coefficient covariance matrix from a fitted csdm model

Description

Extract coefficient covariance matrix from a fitted csdm model

Usage

## S3 method for class 'csdm_fit'
vcov(object, ...)

Arguments

object

A fitted object of class csdm_fit.

...

Currently unused.

Value

A numeric variance-covariance matrix aligned with coef(object) for models where this is available.

See Also

coef.csdm_fit(), summary.csdm_fit()