Skip to content

Fix honest sample splitting - #46

Merged
fbargaglistoffi merged 7 commits into
fbargaglistoffi:masterfrom
charliewang123:master
Jun 14, 2026
Merged

Fix honest sample splitting#46
fbargaglistoffi merged 7 commits into
fbargaglistoffi:masterfrom
charliewang123:master

Conversation

@charliewang123

Copy link
Copy Markdown
Contributor
  • compute_effects_nct was receiving the full sample instead of the held-out estimation clusters, which violates the honesty guarantee
  • Now correctly subsets to estimation units and re-indexes Ne_list before passing to compute_effects_nct

Copilot AI review requested due to automatic review settings June 14, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the NetworkCausalTree estimation step to compute effects on the estimation (non-discovery) clusters only, and adjusts plot-related tests to use the newer function arguments/settings.

Changes:

  • Compute compute_effects_nct() inputs on est_units only (clusters not in the discovery set).
  • Update plot tests to pass K, effect_weights, and use method = "singular".
  • Increase simulated data size in plot tests.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 7 comments.

File Description
tests/testthat/test-plot_NCT.R Updates test inputs/arguments for NetworkCausalTree() and larger generated data.
R/NetworkCausalTree.R Changes effect estimation to run on the estimation subset rather than the full sample.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 29 to 35
fit <- NetworkCausalTree(
Y = d$Y, W = d$W, X = d$X, A = d$A, p = d$p,
method = "OF", depth = 1, minsize = 20,
ratio_disc = 0.5,
output = "detection"
K = d$K,
effect_weights = c(1,0,0,0),
method = "singular", depth = 1, minsize = 20,
ratio_disc = 0.5
)
Comment thread R/NetworkCausalTree.R
Comment on lines +171 to +178
N = length(est_units),
W = W[est_units],
G = G[est_units],
Y = Y[est_units],
X = X[est_units, , drop = FALSE],
p = p[est_units],
Ne = Ne[est_units],
Ne_list = Ne_list_est,
Comment thread R/NetworkCausalTree.R Outdated
Comment on lines +163 to +166
Ne_list_est <- lapply(est_units, function(id) {
neigh <- intersect(Ne_list[[id]], est_units)
match(neigh, est_units)
})
Comment thread R/NetworkCausalTree.R Outdated
Comment on lines +171 to +173
N = length(est_units),
W = W[est_units],
G = G[est_units],
Comment thread R/NetworkCausalTree.R Outdated
Comment on lines +177 to +178
Ne = Ne[est_units],
Ne_list = Ne_list_est,

set.seed(100)
d <- data_generator_direct_indirect(N = 100, k = 5, M = 2, p = rep(0.3,100), remove_isolates = TRUE)
d <- data_generator_direct_indirect(N = 500, k = 10, M = 2, p = rep(0.3, 500), remove_isolates = TRUE)

set.seed(100)
d <- data_generator_direct_indirect(N = 100, k = 5, M = 2, p = rep(0.3,100), remove_isolates = TRUE)
d <- data_generator_direct_indirect(N = 500, k = 10, M = 2, p = rep(0.3, 500), remove_isolates = TRUE)
@fbargaglistoffi

Copy link
Copy Markdown
Owner

Fixing honest estimation from JOSS reviewer’s request.

@fbargaglistoffi
fbargaglistoffi merged commit fd53735 into fbargaglistoffi:master Jun 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants