Skip to contents

Fits a linear probability model \(E[Y \mid w, x] = \beta_0 + \beta_T w + \beta_X^\top x\) via ordinary least squares for binary (incidence) responses \(Y \in \{0,1\}\), using the treatment indicator \(w\) and, optionally, all recorded covariates \(x\) as predictors. \(\hat\beta_T\) is reported directly as the risk-difference estimate: because \(Y\) is 0/1, the OLS fit coincides with a saturated/linear model for the conditional risk \(P(Y=1\mid w,x)\), so the coefficient on \(w\) is already on the risk-difference (probability) scale with no back-transformation needed. This is a misspecified working model for a binary response (heteroskedastic, errors not Gaussian: \(\mathrm{Var}(Y \mid w,x) = P(w,x)(1-P(w,x))\) varies by treatment arm and covariates, so a single pooled residual variance is the wrong variance model), so likelihood_tier = "none": standard errors and the Wald CI use the Huber-White (HC0) sandwich variance of \(\hat\beta_T\) – \((X'X)^{-1} X'\,\mathrm{diag}(e_i^2)\,X\, (X'X)^{-1}\), from the OLS residuals \(e_i\) – not the classical homoskedastic OLS variance and not a binomial likelihood, and no likelihood-ratio or parametric-bootstrap methods are exposed.

Small samples. With unequal allocation (prob_T = 0.2, about 10 treated subjects at n = 50), the HC0 Wald test rejected a true null 11% of the time at a nominal 5% level with covariate adjustment (intervals covered 89%) and 10.2% treatment-only. The excess is expected to shrink as n grows. With so few subjects in one arm, use a larger or more balanced sample, or a randomization or bootstrap test. Source: the first calibration campaign (2026-11-09-8c32d060; provisional, 1000 screening replicates per cell, Monte Carlo standard error about 0.007; measured at n = 50 only), https://github.com/kapelner/EDI/tree/calibration-results.

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.

ProcedureRegimeError orderEffective nRegularityBasisReferences
randfinite sampleexacteventsregulartheory[Fisher1935], [LehmannRomano2005]
waldasymptotic\(O(n_{eff}^{-1})\)eventsregularassumed default[Hall1992]
jackknifeasymptotic\(O(n_{eff}^{-1})\)eventsregularassumed default[ShaoTu1995]
bootstrapasymptotic\(O(n_{eff}^{-1})\)eventsregularassumed default[Hall1992]
bayes_bootasymptotic\(O(n_{eff}^{-1})\)eventsregularassumed default[Rubin1981], [Lo1987]
rand_bootstrapasymptotic\(O(n_{eff}^{-1})\)eventsregularassumed 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.

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.

[Hall1992] Hall, P. (1992). The Bootstrap and Edgeworth Expansion. Springer.

[ShaoTu1995] Shao, J., and Tu, D. (1995). The Jackknife and Bootstrap. 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 -> InferenceIncidRiskDiff

Methods

+ inherited public methods from Inference


InferenceIncidRiskDiff$compute_rand_two_sided_pval()

Randomization two-sided p-value for the risk difference. For incidence responses the default p-value comes from the randomization draws; the Zhang exact randomization test is used only when type = "Zhang" is passed explicitly (where applicable).

Usage

InferenceIncidRiskDiff$compute_rand_two_sided_pval(
  r = 501,
  delta = 0,
  transform_responses = "none",
  na.rm = TRUE,
  show_progress = TRUE,
  permutations = NULL,
  type = NULL,
  args_for_type = NULL,
  zero_one_logit_clamp = .Machine$double.eps,
  alternative = "two.sided"
)

Arguments

r

Number of randomization vectors.

delta

Null treatment effect value.

transform_responses

Response transformation to apply during the test. For survival responses the default "log" multiplies the recorded times of the units treated under each reference allocation by \(e^\delta\), event and censoring times alike, with censoring indicators unchanged – the rank-based AFT residual construction (Tsiatis 1990; Wei, Ying and Lin 1990; Jin, Lin, Wei and Ying 2003); see compute_rand_confidence_interval() for the assumptions.

na.rm

Whether to remove non-finite simulated statistics.

show_progress

Whether to show progress.

permutations

Optional pre-generated assignment draws.

type

NULL (default) or "Zhang", the only accepted value. NULL computes the p-value from the randomization draws. "Zhang" instead returns the Zhang exact combined test (see InferenceIncidExactZhang); it applies only to incidence responses on a Bernoulli or matching design. For any other response or design, a non-NULL type is an error; other strings (for example "Fisher" or "exact") are rejected.

args_for_type

NULL or a list keyed by type, used only with type = "Zhang": list(Zhang = list(combination_method = "Stouffer")), where combination_method is "Fisher" (default), "Stouffer" or "min_p".

zero_one_logit_clamp

The clamping amount for exact 0 and 1 values when logging

alternative

"two.sided" (default), "greater" or "less"; use "greater" for a non-negative, one-tailed-by-construction statistic. The observed allocation counts as one of the \(B\) finite draws: two-sided is \(\min(1, 2(1 + \min(b_{\ge}, b_{\le}))/(1 + B))\) (doubled smaller tail, smallest value \(2/(B + 1)\)); "greater" is \((1 + b_{\ge})/(1 + B)\) (smallest \(1/(B + 1)\)), where \(b_{\ge}\) and \(b_{\le}\) count the draws at least as large / as small as the observed statistic. This exact Monte Carlo p-value (Phipson and Smyth 2010) has size at most \(\alpha\) and is never 0; the realized allocation is never counted twice (a seeded design's replay of it is skipped, a full enumeration's copy removed); see InferenceRand$compute_rand_two_sided_pval().

Returns

A two-sided p-value (a single-tail p-value when alternative is not "two.sided").


InferenceIncidRiskDiff$new()

Initialize a risk-difference inference object.

Usage

InferenceIncidRiskDiff$new(
  des_obj,
  model_formula = NULL,
  verbose = FALSE,
  smart_cold_start_default = NULL
)

Arguments

des_obj

A completed Design object with an incidence response.

model_formula

Optional 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.

verbose

Whether to print progress messages.

smart_cold_start_default

Whether to use smart cold start values.


InferenceIncidRiskDiff$compute_estimate()

Fits the OLS linear-probability model and returns the risk-difference point estimate \(\hat\beta_T\), the coefficient on treatment. On a hardened design (private$harden), or when estimate_only = FALSE, delegates to fast_ols_with_var_cpp() via the shared model cache so the variance is available for later confidence-interval/p-value calls without refitting.

Usage

InferenceIncidRiskDiff$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip the variance/degrees-of-freedom computation and return only \(\hat\beta_T\) (cheaper for simulation/randomization callers that never request inference).


InferenceIncidRiskDiff$compute_asymp_confidence_interval()

Wald confidence interval for the risk difference, \(\hat\beta_T \pm z_{1-\alpha/2}\, \hat s(\hat\beta_T)\), using the Huber-White (HC0) sandwich standard error from the cached model fit (see the class-level documentation) and a normal-quantile multiplier – fast_ols_with_var_cpp() doesn't report residual degrees of freedom, so private$compute_z_or_t_ci_from_s_and_df() always falls back to its \(z\) branch here, never a \(t\) reference, regardless of \(n\). Interval bounds are not clamped to \([-1, 1]\); a linear-probability model can produce out-of-range endpoints near the boundary of the covariate space.

Usage

InferenceIncidRiskDiff$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

Two-sided miscoverage rate; the returned interval has nominal coverage \(1-\alpha\).


InferenceIncidRiskDiff$compute_asymp_two_sided_pval()

Two-sided Wald test of \(H_0: \beta_T = \delta\) vs. \(H_1: \beta_T \neq \delta\), via the Wald statistic \((\hat\beta_T - \delta) / \hat s(\hat\beta_T)\) (\(\hat s\) the Huber-White sandwich SE) referred to a standard normal distribution – same \(z\), not \(t\), reference as $compute_asymp_confidence_interval(), for the same reason (no residual degrees of freedom are ever cached for this class).

Usage

InferenceIncidRiskDiff$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

Null risk-difference value under \(H_0\) (default 0, no treatment effect).


InferenceIncidRiskDiff$compute_estimate_with_bootstrap_weights()

Refits the linear-probability model by weighted least squares under subject/block resampling weights (nonparametric-bootstrap replicate weights or Bayesian-bootstrap Dirichlet weights, both expanded to row weights via expand_subject_or_block_weights_to_row_weights()) and returns the re-estimated treatment coefficient. Full-rank draws use the native OLS kernel, with stats::lm.wfit() as the compatibility fallback. Rows with non-finite or non-positive weight are excluded; if too few positive-weight rows remain to identify the design, the replicate estimate is NA_real_.

Usage

InferenceIncidRiskDiff$compute_estimate_with_bootstrap_weights(
  subject_or_block_weights,
  estimate_only = FALSE
)

Arguments

subject_or_block_weights

Numeric weights, one per subject or per resampling block (matched pair/cluster), as produced by the bootstrap or Bayesian-bootstrap resampling machinery.

estimate_only

Accepted for interface compatibility; standard errors are never computed for a single bootstrap replicate regardless of this flag (only the point estimate is used to build the bootstrap distribution).


InferenceIncidRiskDiff$clone()

The objects of this class are cloneable with this method.

Usage

InferenceIncidRiskDiff$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

# \donttest{
seq_des = DesignSeqOneByOneBernoulli$new(n = 10, response_type = 'incidence')
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(rbinom(10, 1, 0.5))
inf = InferenceIncidRiskDiff$new(seq_des)
inf$compute_estimate()
#> [1] 0.2625382
# }