When covariates are regressed out on the full dataset before cross-validation, held-out test information leaks into the training pipeline. This can inflate or distort out-of-sample performance.
In cpmr, leakage-safe behavior means:
library(cpmr)
set.seed(123)
n <- 80
p <- 120
# Synthetic connectivity matrix (rows = subjects, cols = edges)
conmat <- matrix(rnorm(n * p), nrow = n, ncol = p)
# A synthetic covariate (for example age-like nuisance variable)
covariates <- matrix(rnorm(n), ncol = 1)
# Build behavior with both signal and covariate effects
edge_signal <- rowMeans(conmat[, 1:10, drop = FALSE])
behav <- 0.7 * edge_signal + 0.6 * covariates[, 1] + rnorm(n, sd = 0.5)
# Leakage-safe call: covariates are handled fold-wise inside CV
fit <- cpm(
conmat = conmat,
behav = behav,
covariates = covariates,
kfolds = 5
)
summary(fit)
#> CPM summary:
#> Performance (Pearson):
#> Positive: 0.279
#> Negative: -0.104
#> Combined: 0.259
#> Prop. edges (50% folds):
#> Positive: 1.67%
#> Negative: 0.00%confounds to
covariatescovariates is now the primary argument name.
The old name confounds is still accepted as a deprecated
alias for backward compatibility.
# Backward-compatible alias (deprecated)
fit_old <- cpm(conmat, behav, confounds = covariates, kfolds = 5)
#> Warning: `confounds` is deprecated; please use `covariates` instead.Do not pass both in the same call.
Use this checklist when building CPM workflows: