
G-Computation Mean-Difference Inference for Proportion Responses
Source:R/inference_proportion_gcomp.R
InferencePropGCompMeanDiff.RdFits a fractional-logit working model, \(\mathrm{logit}\,E[Y_i \mid x_i] =
x_i^\top\hat\beta\) (via fast_logistic_regression_cpp, treating
the continuous-in-\((0,1)\) proportion as a quasi-binomial mean model —
the same mean-model idea as
InferencePropFractionalLogit),
for a proportion outcome using treatment and, optionally, all recorded
covariates, then estimates the marginal mean difference by G-computation:
standardizing predicted mean proportions under all-treated and all-control
assignments over the empirical covariate distribution (see
gcomp_fractional_logit_point_estimate_cpp for the exact
standardization formula). Inference uses a Huber-White sandwich-robust
covariance for the regression coefficients and the delta method
(analytic gradient of the standardized mean-difference functional with
respect to \(\hat\beta\), by default) to propagate that covariance onto
the mean-difference scale, \(\widehat{\mathrm{Var}}(\widehat{\mathrm{md}})
= \nabla^\top \widehat{\mathrm{Var}}(\hat\beta) \nabla\).
The implementation is optimized for resampling-based inference. It utilizes a fast C++ IRLS solver for the underlying fractional logit regression. During resampling draws, it bypasses the calculation of the sandwich covariance matrix and delta-method standard errors, providing a significant speedup when computing bootstrap or randomization distributions.
Variance fallback cascade. If the primary analytic-gradient/sandwich-covariance
variance is non-finite (e.g. near-boundary fitted probabilities), up to seven
progressively more conservative fallback strategies are tried in order (see
the variance_fallback_methods constructor argument for the full list
and their individual definitions): stabilized (PSD-projected) sandwich
covariance, model-based (Fisher information) covariance, finite-difference
gradients in place of the analytic delta-method gradient, and combinations
with progressively stronger probability clipping. The first strategy in the
ordered list that yields a finite, positive variance is used; an empty
variance_fallback_methods vector always returns NA variance
rather than erroring.
Small-sample behaviour
How fast the size (and coverage) error of each procedure is expected to vanish as the
effective sample size \(n_{eff}\) grows, from EDI's convergence-rate registry
(inference_convergence_expectation()). Exact procedures are valid at every
n by construction; the others are asymptotic, so a small-sample excess is expected, and
its constant is not given by an order. The table is the expectation for a balanced
complete-randomization design; it is not a measured size. Reference keys are explained
under References.
| Procedure | Regime | Error order | Effective n | Regularity | Basis | References |
rand | finite sample | exact | subjects | regular | theory | [Fisher1935], [LehmannRomano2005] |
jackknife | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [ShaoTu1995] |
bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992] |
bayes_boot | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Rubin1981], [Lo1987] |
rand_bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992], [Kallus2018] |
The point estimate's bias is of order \(O(n_{eff}^{-1})\) (assumed default: [CoxSnell1968]).
Rows with basis assumed default: the order shown is the procedure's rate in a regular parametric model, and the cited works establish it for that case only. EDI has not derived it for this class.
Design-specific differences from the table:
On any design with unequal allocation (
prob_Tnot 0.5), forjackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the size of the smaller arm.On
DesignFixedBlockedCluster,DesignFixedCluster, forjackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the number of clusters.
Blocking designs
On a blocking design
(DesignFixedBlocking and relatives)
the regression-type inference classes do not add block fixed effects
(or block-by-treatment interactions) automatically: the model uses only the
covariate matrix. Whether the blocks enter the regression therefore depends
on how they were supplied: not at all with m=; as dummies when the
blocking column is a factor/character (or few-level integer) covariate; as a
single linear term when it is numeric. Randomization, bootstrap and
jackknife inference are block-aware regardless; only the model-based
(asymptotic, likelihood) path ignores the blocks.
When the proportion treated is the same in every block, the pooled
treatment estimate of a linear model is unbiased and its model-based SE is
conservative (it is inflated by the block variation it fails to remove), at a
cost in power. If the proportion treated differs across blocks (for example
equal_block_sizes = FALSE with very small blocks and an extreme
prob_T, where per-block rounding changes the allocation, or a
user-supplied m), the pooled treated-vs-control comparison is
confounded by block (Simpson's paradox) and can be biased; then include the
blocking covariate(s) explicitly as factor covariates. For non-linear models
(GLM, ordinal, survival) omitting blocks changes the estimand to a
block-marginal effect. See DesignFixedBlocking.
References
[Fisher1935] Fisher, R. A. (1935). The Design of Experiments. Oliver and Boyd.
[LehmannRomano2005] Lehmann, E. L., and Romano, J. P. (2005). Testing Statistical Hypotheses (3rd ed.). Springer.
[ShaoTu1995] Shao, J., and Tu, D. (1995). The Jackknife and Bootstrap. Springer.
[Hall1992] Hall, P. (1992). The Bootstrap and Edgeworth Expansion. Springer.
[Rubin1981] Rubin, D. B. (1981). "The Bayesian Bootstrap." The Annals of Statistics, 9(1), 130-134.
[Lo1987] Lo, A. Y. (1987). "A Large Sample Study of the Bayesian Bootstrap." The Annals of Statistics, 15(1), 360-375.
[Kallus2018] Kallus, N. (2018). "Optimal a priori balance in the design of controlled experiments." Journal of the Royal Statistical Society: Series B, 80(1), 85-112. Section 5 ("Algorithms for inference"), Algorithm 4.
[CoxSnell1968] Cox, D. R., and Snell, E. J. (1968). "A General Definition of Residuals." Journal of the Royal Statistical Society: Series B, 30(2), 248-265 (discussion 265-275).
Super class
Inference -> InferencePropGCompMeanDiff
Methods
Public methods
InferencePropGCompMeanDiff$compute_estimate_with_bootstrap_weights()InferencePropGCompMeanDiff$compute_asymp_confidence_interval()InferencePropGCompMeanDiff$compute_wald_confidence_interval()InferencePropGCompMeanDiff$compute_bootstrap_two_sided_pval()InferencePropGCompMeanDiff$compute_bootstrap_confidence_interval()InferencePropGCompMeanDiff$approximate_bootstrap_distribution_beta_hat_T()
+ inherited public methods from Inference
Inference$capabilities()Inference$clear_randomization_cache()Inference$compute_exact_confidence_interval()Inference$compute_exact_two_sided_pval_for_treatment_effect()Inference$duplicate()Inference$get_analysis_data()Inference$get_covariates()Inference$get_design_object()Inference$get_estimand()Inference$get_model_formula()Inference$get_nonestimable_reason()Inference$get_nonestimable_stage()Inference$get_optimization_alg()Inference$get_procedure_validity()Inference$get_response()Inference$get_response_type()Inference$get_summary()Inference$get_supported_estimands()Inference$get_treatment()Inference$is_nonestimable()Inference$set_estimand()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
InferencePropGCompMeanDiff$new()
Uses the shared randomization two-sided p-value contract; see
InferenceRand.
Initialize the g-computation inference object.
Usage
InferencePropGCompMeanDiff$new(
des_obj,
model_formula = NULL,
verbose = FALSE,
prob_clip_eps = 1e-06,
prob_clip_strong_eps = 1e-04,
max_resample_attempts = 50L,
smart_cold_start_default = NULL,
harden = TRUE,
variance_fallback_methods = c("robust", "stabilized_robust", "model_based",
"stabilized_robust_fd", "model_based_fd", "stabilized_robust_strong_clip",
"model_based_strong_clip", "model_based_fd_strong_clip")
)Arguments
des_objA completed
DesignSeqOneByOneobject with a proportion response.model_formulaOptional formula for covariate adjustment. If
NULL(default), the formula from the design object is used and its pre-computed design matrix is reused. If a formula is provided, a new design matrix is constructed from the design's imputed covariates.verboseWhether to print progress messages.
prob_clip_epsPrimary probability clamp applied to fitted values during model-based variance computation. Predicted probabilities are clipped to
[prob_clip_eps, 1 - prob_clip_eps]before computing IWLS weights. Must be in[0, 0.5). Default1e-6.prob_clip_strong_epsStronger clamp used as a fallback when the primary variance strategy fails. Predicted probabilities and gradients are clipped to
[prob_clip_strong_eps, 1 - prob_clip_strong_eps]. Must be in[0, 0.5)and should be \(\ge\)prob_clip_eps. Default1e-4.max_resample_attemptsMaximum number of times a single bootstrap replicate may be redrawn when the drawn sample fails validity screening (e.g. near-perfect separation, too few observations per arm, excessive boundary mass). If all attempts fail the replicate is recorded as
NA, silently reducing the effectiveB. Can be overridden per-call inapproximate_bootstrap_distribution_beta_hat_T. Must be a positive integer. Default50L.smart_cold_start_defaultWhether to use smart cold start values.
hardenWhether to apply robustness measures.
variance_fallback_methodsOrdered character vector of variance strategies to attempt in sequence. Each name corresponds to a (gradient, covariance-matrix) pair; the first strategy that yields a finite, positive variance is used. Allowed values (in their default order) are:
"robust"Analytic delta-method gradient with the sandwich (HC) covariance.
"stabilized_robust"Same gradient; covariance projected to the nearest PSD matrix.
"model_based"Same gradient; Fisher-information (IWLS) covariance. Fitted probabilities are first clipped to
[prob_clip_eps, 1 - prob_clip_eps], then the binomial variance weight \(w_i = \hat\mu_i(1-\hat\mu_i)\) is further capped at0.25. The cap is the global maximum of \(p(1-p)\), attained at \(p = 0.5\); it prevents a near-boundary fitted probability that slips through the clip from inflating the information matrix, which is mathematically correct because no Bernoulli variance can exceed 0.25."stabilized_robust_fd"Finite-difference (central-difference) gradient; stabilized sandwich covariance. The step size for coefficient \(j\) is \(h_j = \varepsilon^{1/3}(|\hat\beta_j| + 1)\), where \(\varepsilon = \)
.Machine$double.eps. The cube-root of machine epsilon is the theoretically optimal step that balances truncation error (\(O(h^2)\) for central differences) against floating-point cancellation (\(O(\varepsilon / h)\)), giving a total error of \(O(\varepsilon^{2/3})\)."model_based_fd"Finite-difference gradient (same step rule as
"stabilized_robust_fd"); model-based covariance with the 0.25 weight cap."stabilized_robust_strong_clip"Strong-clipped analytic gradient; stabilized sandwich covariance.
"model_based_strong_clip"Strong-clipped analytic gradient; model-based covariance (strong-clipped) with the 0.25 weight cap.
"model_based_fd_strong_clip"Strong-clipped finite-difference gradient (same step rule); model-based covariance (strong-clipped) with the 0.25 weight cap.
Pass a shorter vector or a single string to restrict which strategies are tried. An empty vector always returns
NAvariance.
InferencePropGCompMeanDiff$get_standard_error()
Returns the standard error of the g-computation mean-difference
estimate (NA if it is unavailable).
InferencePropGCompMeanDiff$compute_estimate_with_bootstrap_weights()
Recomputes the g-computation mean-difference estimate under the supplied subject- or block-level bootstrap weights and caches it; used by the Bayesian-bootstrap and resampling paths.
Usage
InferencePropGCompMeanDiff$compute_estimate_with_bootstrap_weights(
subject_or_block_weights,
estimate_only = FALSE
)InferencePropGCompMeanDiff$compute_asymp_confidence_interval()
Computes a 1 - alpha confidence interval.
InferencePropGCompMeanDiff$compute_asymp_two_sided_pval()
Uses the shared asymptotic two-sided p-value contract; see
InferenceAsymp.
InferencePropGCompMeanDiff$compute_wald_two_sided_pval()
Computes a Wald two-sided p-value for the treatment effect.
InferencePropGCompMeanDiff$compute_wald_confidence_interval()
Computes a Wald confidence interval for the treatment effect.
InferencePropGCompMeanDiff$compute_bootstrap_two_sided_pval()
Computes a bootstrap two-sided p-value for the treatment effect.
Usage
InferencePropGCompMeanDiff$compute_bootstrap_two_sided_pval(
delta = 0,
B = 501,
type = "symmetric",
na.rm = FALSE,
boundary_tol = 0.02,
max_boundary_mass = 0.95,
sep_tol = 0.02,
min_group_n = 5L,
show_progress = TRUE,
min_number_usable_samples = 5L,
min_fraction_usable_samples = 0.95
)Arguments
deltaThe null mean difference. Defaults to 0.
BNumber of bootstrap samples.
typeBootstrap p-value type. See
InferenceNonParamBootstrap$compute_bootstrap_two_sided_pval.na.rmWhether to remove non-finite bootstrap replicates. Default
FALSE: any non-finite replicate makes the p-valueNA, with a once-per-object warning of classedi_bootstrap_nonfinite_na_warning.boundary_tolResample screening threshold for boundary mass near 0/1.
max_boundary_massReject a resample when at least this fraction is near the boundary.
sep_tolSeparation tolerance used to reject nearly perfectly separated resamples.
min_group_nMinimum number of observations required in each treatment arm.
show_progressWhether to show a progress bar.
min_number_usable_samplesMinimum number of finite bootstrap samples required.
min_fraction_usable_samplesMinimum fraction of the
Breplicates that must be finite (and pass the screening above) whenna.rm = TRUE. Default 0.95. SeeInferenceNonParamBootstrap$compute_bootstrap_two_sided_pval.
InferencePropGCompMeanDiff$compute_bootstrap_confidence_interval()
Generic (non-screening-modified) bootstrap two-sided p-value, aliased directly from `InferenceNonParamBootstrap` so `compute_bootstrap_two_sided_pval()` can dispatch to it without relying on `super$`, which does not resolve under flat component composition.
Computes a bootstrap confidence interval.
Usage
InferencePropGCompMeanDiff$compute_bootstrap_confidence_interval(
alpha = 0.05,
B = 501,
type = NULL,
na.rm = TRUE,
show_progress = TRUE,
boundary_tol = 0.02,
max_boundary_mass = 0.95,
sep_tol = 0.02,
min_group_n = 5L,
min_number_usable_samples = 5L
)Arguments
alphaThe confidence level 1 -
alpha.BNumber of bootstrap samples.
typeBootstrap CI type.
na.rmWhether to remove non-finite bootstrap replicates.
show_progressWhether to show bootstrap progress.
boundary_tolResample screening threshold for boundary mass near 0/1.
max_boundary_massReject a resample when at least this fraction is near the boundary.
sep_tolSeparation tolerance used to reject nearly perfectly separated resamples.
min_group_nMinimum number of observations required in each treatment arm.
min_number_usable_samplesMinimum number of finite bootstrap samples required.
InferencePropGCompMeanDiff$approximate_bootstrap_distribution_beta_hat_T()
Generic (non-screening-modified) bootstrap confidence interval; see `compute_bootstrap_two_sided_pval_generic`.
Abbreviated bootstrap sampler that reuses a bootstrap worker.
Usage
InferencePropGCompMeanDiff$approximate_bootstrap_distribution_beta_hat_T(
B = 501,
show_progress = TRUE,
max_resample_attempts = NULL,
boundary_tol = 0.02,
max_boundary_mass = 0.95,
sep_tol = 0.02,
min_group_n = 5L,
debug = FALSE
)Arguments
BThe number of bootstrap samples (default 501).
show_progressWhether to show a progress bar.
max_resample_attemptsMaximum redraw attempts per bootstrap replicate before the replicate is recorded as
NA.NULL(default) uses the value set at construction time.boundary_tolResample screening threshold for boundary mass near 0/1.
max_boundary_massReject a resample when at least this fraction is near the boundary.
sep_tolSeparation tolerance used to reject nearly perfectly separated resamples.
min_group_nMinimum number of observations required in each treatment arm.
debugIf TRUE, return per-replicate diagnostics (values, errors, warnings) instead of just the bootstrap values.
Examples
# \donttest{
seq_des = DesignSeqOneByOneBernoulli$new(n = 10, response_type = 'proportion')
for (i in 1:10) {
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
}
seq_des$add_all_subject_responses(runif(10))
inf = InferencePropGCompMeanDiff$new(seq_des)
inf$compute_estimate()
#> [1] 0.1160218
# }