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("pairwise", "drop.incomplete.times"),
...
)
# 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("pairwise", "drop.incomplete.times"),
...
)
# S3 method for class 'cd_test'
print(x, digits = 3, ...)Arguments
- object
A
csdm_fitmodel 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. Seeded calls restore the caller's RNG state; NULL uses the current RNG stream.
- 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"removes time periods with any missing observations to create a balanced panel for CD*;"pairwise"(default) uses pairwise correlations for CD; unbalanced CDw/CDw+ requests error and CD* warns.- x
An object of class
cd_test.- digits
Number of digits to print (default 3).
Value
An object of class cd_test with fields tests, type,
N, T, na.action, excluded_units,
excluded_times, kept_times, and call. The tests
list contains one or more test results, each with statistic and
p.value.
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, 2022)
Independent Rademacher weights \(w_i \in \{-1,1\}\) are applied by unit. For a balanced residual panel, the statistic is $$CD_W = \left(\frac{1}{NT}\sum_{i,t}w_i^2 e_{it}^2\right)^{-1} \sqrt{\frac{2}{TN(N-1)}} \sum_t\sum_{i<j}w_i e_{it}w_j e_{jt}.$$ The first factor is the inverse pooled residual variance. One set of random weights is drawn per call; use
seedfor reproducibility.- CDw+ (Juodis and Reese, 2022; Fan, Liao, and Yao, 2015)
The power-enhanced statistic is $$CD_{W+} = CD_W + \sum_{i<j}|\rho_{ij}| 1\left\{|\rho_{ij}| > 2\sqrt{\log(N)/T}\right\}.$$ Here \(\rho_{ij}\) is the ordinary residual correlation, without multiplication by \(\sqrt{T}\). The nonnegative screening term is asymptotically zero under the conditions of the null hypothesis.
- CD* (Pesaran and Xie, 2021)
CD is computed on residuals after removing
n_pcprincipal components from \(E\). This provides a bias-corrected test under multifactor errors.
CD* requires a nondegenerate bias-correction denominator. Near-zero denominators can produce severe size distortions, including proportional loading/error-scale designs after standardization. Numerical rank checks do not establish the validity of the asymptotic approximation.
Missing data and balance
Time periods containing no finite residual for any retained unit are outside
the effective residual sample and are always removed before balance is
assessed. Partially observed periods are handled according to na.action.
- CD
Uses pairwise-complete observations by default. Each pairwise correlation uses available overlaps.
- CDw, CDw+
Require a balanced sample; explicitly select complete times if desired.
- CD*
Requires a balanced panel. Explicitly setting
na.action = "drop.incomplete.times"removes any time period with missing observations. Withna.action = "pairwise", CD* returnsNAand a warning when missing values are present.
References
Pesaran MH (2015). “Testing weak cross-sectional dependence in large panels.” Econometric Reviews, 34(6-10), 1089–1117.
Pesaran MH (2021). “General diagnostic tests for cross-sectional dependence in panels.” Empirical Economics, 60(1), 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), 1191–1203.
Fan J, Liao Y, Yao J (2015). “Power Enhancement in High-Dimensional Cross-Section Tests.” Econometrica, 83(4), 1497–1541.
Pesaran MH, 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")
#> Cross-sectional dependence tests
#> N = 10, T = 10
#>
#> statistic p.value
#> CD -1.325 0.185
#> CDw -1.184 0.237
#> CDw+ -1.184 0.237
#> CDstar 0.081 0.935
cd_test(E_dep, type = "CD")
#> Cross-sectional dependence tests
#> N = 10, T = 10
#>
#> statistic p.value
#> CD 21.213 0.000
# Specific test with parameters
cd_test(E_indep, type = "CDstar", n_pc = 2)
#> Cross-sectional dependence tests
#> N = 10, T = 10
#>
#> statistic p.value
#> CDstar -0.303 0.762
# 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")
#> Cross-sectional dependence tests
#> N = 10, T = 38
#>
#> statistic p.value
#> CD -3.581 0.000
#> CDw 2.322 0.020
#> CDw+ 4.464 0.000
#> CDstar -3.153 0.002