prepare_cd_input() is deprecated and is not used by cd_test(). Transforming
residuals before a dependence test can change the tested hypothesis. Pass the
original residual matrix to cd_test() and use its documented missing-data
policy instead.
For compatibility, this function still performs:
Dropping time periods with fewer than
min_per_timefinite observations.Optional row-wise standardization to unit variance over available times.
Optional demeaning across units at each time (changes the tested residuals).
Usage
prepare_cd_input(
E,
standardize = c("row", "none"),
demean_time = FALSE,
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.
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
NAifstandardize="none").- col_means
Numeric vector of time means subtracted when
demean_time=TRUE.
Details
This helper is retained temporarily for compatibility. Row scaling changes
the weighted covariance underlying CDw, while cross-sectional time demeaning
can mechanically induce dependence. Neither transformation is applied by
cd_test().
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)
#> Warning: 'get_residuals()' is deprecated; use residuals() for csdm fits or pass a residual matrix directly to cd_test().
prep <- prepare_cd_input(E, standardize = "row", demean_time = TRUE, min_per_time = 3)
#> Warning: 'prepare_cd_input()' is deprecated and is not used by cd_test(); pass original residuals to cd_test() instead.
dim(prep$Z)
#> [1] 10 38