
Logistic Regression Inference for Incidence Responses
Source:R/inference_incidence_logit.R
InferenceIncidLogRegr.RdFits a logistic regression model for binary (incidence) responses:
\(\mathrm{logit}(P(Y_i = 1)) = \beta_0 + \beta_T W_i + X_i^\top \gamma\),
where \(W_i\) is the treatment indicator and \(X_i\) are optional
recorded covariates, by maximum likelihood
(fast_logistic_regression_cpp/
fast_logistic_regression_weighted_cpp). \(\hat\beta_T\) is
a log-odds-ratio: \(\exp(\hat\beta_T)\) is the estimated treatment odds
ratio. likelihood_tier = "full": Wald, score, gradient, and
likelihood-ratio tests are all available (via the shared
StandardModelCache model-caching contract), plus
parametric-likelihood-bootstrap calibration of the likelihood-ratio test.
A fit whose coefficients exceed
max_abs_reasonable_coef in magnitude (a proxy for near-perfect
separation) is cached as nonestimable rather than returned. Validity
requires the usual logistic-regression assumptions: correctly specified
linear predictor on the logit scale, independence across subjects
conditional on covariates, and no perfect/quasi-complete separation.
Estimand. Composes
MarginalEstimand
(set_estimand()/get_estimand()/get_supported_estimands()).
Under the default estimand = "conditional", \(\hat\beta_T\) is the
log-odds-ratio above. Under estimand = "marginal_mean_diff", the
reported quantity is instead the g-computation marginal risk difference
\(\frac{1}{n}\sum_i \{\mathrm{plogis}(\hat\beta_0 + \hat\beta_T + X_i^\top
\hat\gamma) - \mathrm{plogis}(\hat\beta_0 + X_i^\top \hat\gamma)\}\) — every
subject's covariates plugged in once under treatment and once under
control, averaged over the empirical covariate distribution. Under
estimand = "marginal_ratio", the log of the corresponding marginal
risk ratio: the estimate, its confidence intervals and delta are all on
the log scale (delta = 0 is no effect). This is the same standardized
risk ratio that
InferenceIncidGCompRiskRatio
computes from the same logistic working model, but that class reports it on
the ratio scale (its estimate is exp() of this one, its intervals are
back-transformed and its delta = 1 is no effect) and its Wald standard
error uses the sandwich rather than the model covariance. Because there is no latent submodel for this family (unlike
e.g. InferencePropZeroOneInflatedBetaRegr's
zero/one-inflation mixture), the marginal mean function is exactly the
model's own fitted mean; no separate standardization step beyond the
g-computation average is needed. Standard errors under a marginal estimand
use the delta method against the model's coefficient covariance (degrees
of freedom Inf); testing_type is restricted to "wald"
whenever the estimand is non-conditional (set_testing_type() errors
otherwise). The underlying model fit is identical regardless of estimand —
switching estimand is a pure post-fit transform, never a refit.
Separation. When fitted probabilities are numerically 0 or 1 (the
data look (quasi-)completely separated) the maximum-likelihood estimate does
not exist: the reported estimate is where the fitter stopped and its Wald
standard error, p-value and confidence interval are not meaningful. The class
raises one warning of class edi_logistic_separation_warning per object
(silent inside resampling), as glm() does; the returned values are
unchanged. Prefer a likelihood-ratio test (set_testing_type("lik_ratio")),
a randomization test, an exact incidence method, or fewer covariates.
Subsampling and m-out-of-n
(v1.0.6-TODO-230.) At the default size \(b = m = \lfloor n^{0.7} \rfloor\) a draw can be
degenerate: a treatment arm with no events or only events, or a (quasi-)separated fit (a fitted probability numerically 0 or 1). Its log odds ratio then sits where the fitter stopped (about \(\pm 20\)),
not in the sampling law the pivot estimates, so the draw is NaN in
approximate_subsampling_distribution_beta_hat_T() and
approximate_m_out_of_n_bootstrap_distribution_beta_hat_T() (also with debug = TRUE)
and is not used. If fewer than min_fraction_usable_samples (default 0.8, user-settable since
v1.0.6-TODO-269) of the B draws are usable (degenerate and failed draws both count against
it), the subsampling / m-out-of-n p-value or interval is NA with reason
"subsampling_too_few_usable_draws_fraction" or "m_out_of_n_too_few_usable_draws_fraction"
and one edi_procedure_na_warning. The p-value is symmetric: the share of usable pivot draws
\(\sqrt{b}(\hat\theta^* - \hat\theta)\) (subsampling also divides by \(\sqrt{1 - b/n}\)) at
least as large in absolute value as \(\sqrt{n}(\hat\theta - \delta)\), floored at \(1/B\), rather
than the equal-tailed \(2\min\{\cdot\}\), because at small \(b\) the law of a log ratio is skewed
toward the observed effect and the equal-tailed rule doubles the heavy tail. The interval is the basic
(equal-tailed) one. Null size at \(n = 80\) (200 data sets, B = 199, nominal 0.05, before and
after): Wald 0.060; subsampling 0.000, m-out-of-n 0.000 before and after; the intervals that were NA from the extreme-interval cap (25% and 54% of data sets) are now finite. These tests stay conservative because at \(b = 21\) the spread of the subsample log odds ratio is about 1.5 times what the \(\sqrt{b}\) scaling assumes. The ordinary bootstrap is the better resampling method for this estimand.
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 | events | regular | theory | [Fisher1935], [LehmannRomano2005] |
wald | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [Hall1992] |
jackknife | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [ShaoTu1995] |
score | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [BarndorffNielsenCox1994] |
lik_ratio | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [BarndorffNielsenCox1994] |
gradient | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [Terrell2002], [Lemonte2016] |
lik_ratio_bartlett_approx | asymptotic | \(O(n_{eff}^{-2})\) | events | regular | assumed default | [Lawley1956], [BarndorffNielsenHall1988] |
lik_ratio_bartlett_exact | asymptotic | \(O(n_{eff}^{-2})\) | events | regular | assumed default | [Lawley1956], [BarndorffNielsenHall1988] |
param_boot | asymptotic | \(O(n_{eff}^{-2})\) | events | regular | assumed default | [Beran1988], [DiCiccioMartinStern2001], [Hall1992] |
param_boot_direct | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [Hall1992] |
bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [Hall1992] |
bayes_boot | asymptotic | \(O(n_{eff}^{-1})\) | events | regular | assumed default | [Rubin1981], [Lo1987] |
rand_bootstrap | asymptotic | \(O(n_{eff}^{-1})\) | events | 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.
The procedure list is by declared capability; an object can still report a procedure
(for example a Bartlett correction) as unavailable through get_supported_testing_types().
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
McCullagh, P., and Nelder, J. A. (1989). Generalized Linear Models (2nd ed.). Chapman and Hall/CRC, for the logistic regression model and its maximum-likelihood theory.
[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.
[BarndorffNielsenCox1994] Barndorff-Nielsen, O. E., and Cox, D. R. (1994). Inference and Asymptotics. Chapman and Hall.
[Terrell2002] Terrell, G. R. (2002). "The gradient statistic." Computing Science and Statistics, 34, 206-215.
[Lemonte2016] Lemonte, A. J. (2016). The Gradient Test: Another Likelihood-Based Test. Academic Press.
[Lawley1956] Lawley, D. N. (1956). "A General Method for Approximating to the Distribution of Likelihood Ratio Criteria." Biometrika, 43(3-4), 295-303.
[BarndorffNielsenHall1988] Barndorff-Nielsen, O. E., and Hall, P. (1988). "On the Level-Error after Bartlett Adjustment of the Likelihood Ratio Statistic." Biometrika, 75(2), 374-378.
[Beran1988] Beran, R. (1988). "Prepivoting Test Statistics: A Bootstrap View of Asymptotic Refinements." Journal of the American Statistical Association, 83(403), 687-697.
[DiCiccioMartinStern2001] DiCiccio, T. J., Martin, M. A., and Stern, S. E. (2001). "Simple and Accurate One-Sided Inference from Signed Roots of Likelihood Ratios." Canadian Journal of Statistics, 29(1), 67-76.
[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).
See also
Comparable Python API: statsmodels GLM. See also: Logistic regression (Wikipedia).
Super class
Inference -> InferenceIncidLogRegr
Methods
+ 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$initialize()Inference$is_nonestimable()Inference$set_estimand()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
InferenceIncidLogRegr$compute_estimate()
Fits the logistic regression model by maximum
likelihood. Under the default estimand = "conditional",
returns \(\hat\beta_T\), the treatment log-odds-ratio. Under
estimand = "marginal_mean_diff"/"marginal_ratio"
(set via set_estimand()), returns the g-computation
marginal risk difference/log-risk-ratio instead — see the
Estimand paragraph of the class description for the formula. The
underlying model fit is identical either way (a pure post-fit
transform of the same cached fit, no refit).
InferenceIncidLogRegr$compute_asymp_confidence_interval()
Wald confidence interval, dispatched by
testing_type for the conditional estimand (score/gradient/
likelihood-ratio/Bartlett available); under a marginal estimand
testing_type is always "wald" (the only value
set_estimand() permits there), so this always resolves to
the delta-method interval. Calls self$compute_estimate()
first (not private$shared() directly) so the
estimand-aware cache is always current regardless of call order.
InferenceIncidLogRegr$compute_asymp_two_sided_pval()
Wald two-sided p-value, dispatched by
testing_type exactly as
compute_asymp_confidence_interval(); see that method's
description for the marginal-estimand always-Wald note.
Examples
seq_des = DesignSeqOneByOneBernoulli$new(n = 60, response_type = 'incidence')
for (i in 1:60) {
seq_des$add_one_subject_to_experiment_and_assign(data.frame(x1 = rnorm(1)))
}
seq_des$add_all_subject_responses(rbinom(60, 1, 0.4))
# \donttest{
inf = InferenceIncidLogRegr$new(seq_des)
inf$compute_estimate()
#> [1] -0.7175273
# }
# \donttest{
inf$set_seed(1)
inf$compute_lik_ratio_bootstrap_two_sided_pval(delta = 0, B = 9, show_progress = FALSE)
#> [1] 0.4
# }