From be5a703848ba07b0944cf36c798c57aedd5e7cde Mon Sep 17 00:00:00 2001 From: charliewang123 Date: Tue, 13 Oct 2026 09:42:40 -0700 Subject: [PATCH 1/2] Update NetworkCausalTree.R --- R/NetworkCausalTree.R | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/R/NetworkCausalTree.R b/R/NetworkCausalTree.R index 1873259..6a4a65a 100644 --- a/R/NetworkCausalTree.R +++ b/R/NetworkCausalTree.R @@ -100,9 +100,22 @@ NetworkCausalTree <- function(X, Y, W, stop('You have to specify the Adjacency Matrix A.') } - # Ratio of clusters assigned to discovery set needs to be within boundaries - if (ratio_disc <= 0 | ratio_disc > 1) { - stop('The ratio of clusters to be assigned to the discovery set must be above 0 and below 1') + if (ratio_disc <= 0 || ratio_disc >= 1) { + stop("ratio_disc must be strictly between 0 and 1.") + } + + if (k < 2) { + stop("At least two clusters are required for honest sample splitting.") + } + + nclusters_disc <- round(k * ratio_disc) + + if (nclusters_disc < 1) { + stop("ratio_disc is too low; no clusters are assigned to the discovery sample. Please use a higher ratio_disc.") + } + + if (nclusters_disc >= k) { + stop("ratio_disc is too high; no clusters remain for the estimation sample. Please use a lower ratio_disc.") } # Compute network - specific information (the degree Ne, the number of treated friends Ne_treated, @@ -127,7 +140,6 @@ NetworkCausalTree <- function(X, Y, W, Ne = Ne) # Sample the clusters to be assigned to the discovery set - nclusters_disc = round(k * ratio_disc) clusters_disc <- sample(unique(K), size = nclusters_disc, replace = FALSE) # Generate the tree on the discovery set From 0e87218bbd726dfe7675681a5cc67396aabf3692 Mon Sep 17 00:00:00 2001 From: "Falco J. Bargagli-Stoffi" Date: Tue, 13 Oct 2026 14:41:47 -0700 Subject: [PATCH 2/2] Fix subsetting of A_est to preserve dimensions --- R/NetworkCausalTree.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/NetworkCausalTree.R b/R/NetworkCausalTree.R index 6a4a65a..8313a40 100644 --- a/R/NetworkCausalTree.R +++ b/R/NetworkCausalTree.R @@ -170,7 +170,7 @@ NetworkCausalTree <- function(X, Y, W, clusters_est <- setdiff(unique(K), clusters_disc) est_units <- which(K %in% clusters_est) - A_est <- A[est_units, est_units] + A_est <- A[est_units, est_units, drop = FALSE] Ne_est <- rowSums(A_est) Ne_treated_est <- as.vector(A_est %*% W[est_units]) G_est <- rep(1, length(est_units))