Fix honest sample splitting - #46
Merged
Merged
Conversation
charliewang123
commented
Jun 14, 2026
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
Contributor
There was a problem hiding this comment.
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 onest_unitsonly (clusters not in the discovery set). - Update plot tests to pass
K,effect_weights, and usemethod = "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 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 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 on lines
+171
to
+173
| N = length(est_units), | ||
| W = W[est_units], | ||
| G = G[est_units], |
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) |
Owner
|
Fixing honest estimation from JOSS reviewer’s request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.