
Simple Mean-Difference Inference for Continuous Responses
Source:R/inference_all_average_diff.R
InferenceAllSimpleAverageDiff.RdFits the simplest possible treatment-effect estimator for a continuous
response: the unadjusted difference in sample means between the treated and
control arms, \(\hat\beta_T = \bar y_T - \bar y_C\), with no covariate
adjustment. Inference is by Welch's unequal-variance t-test: standard
error \(\sqrt{s_T^2/n_T + s_C^2/n_C}\) (per-arm sample variances, not
pooled) with Satterthwaite-Welch degrees of freedom — see
$compute_asymp_confidence_interval() for the exact formula. This class
has no likelihood tier (likelihood_tier = "none") and provides
asymptotic Wald, randomization, and bootstrap (including Bayesian bootstrap)
confidence intervals and p-values. Warm starts are disabled for this class,
since the simple mean difference is a closed-form estimator (no iterative fit
to warm-start).
Initialize a simple mean-difference inference object.
Computes a \(1-\alpha\) level confidence interval for the
simple (unadjusted) mean-difference treatment effect
\(\hat\beta_T = \bar y_T - \bar y_C\), using Welch's
unequal-variance formula: standard error
\(\widehat{\mathrm{SE}}(\hat\beta_T) = \sqrt{s_T^2/n_T + s_C^2/n_C}\)
(sample variances \(s_T^2\), \(s_C^2\) computed separately per arm,
not pooled) with Satterthwaite-Welch degrees of freedom
\(\mathrm{df} = (s_T^2/n_T + s_C^2/n_C)^2 \big/ \left(\frac{(s_T^2/n_T)^2}{n_T-1}
+ \frac{(s_C^2/n_C)^2}{n_C-1}\right)\); the interval is
\(\hat\beta_T \pm t_{\mathrm{df}, 1-\alpha/2}\,\widehat{\mathrm{SE}}(\hat\beta_T)\).
Requires at least 2 observations per arm; otherwise the standard error
and interval are NA. See
InferenceAsymp for the shared
asymptotic confidence-interval contract this delegates to.
Computes a two-sided Welch's t-test p-value testing
\(H_0: \beta_T = \code{delta}\), from the same Welch
unequal-variance standard error and Satterthwaite-Welch degrees of
freedom used by $compute_asymp_confidence_interval() — see that
method's documentation for the full formula. See
InferenceAsymp for the shared
asymptotic two-sided p-value contract this delegates to.
Computes the simple (unadjusted) mean-difference point
estimate \(\hat\beta_T = \bar y_T - \bar y_C\), the difference in
sample means between the treated and control arms. NA if
either arm has zero observations. See
InferenceMLEorKMSummaryTable
for the shared estimate-contract this participates in.
Recomputes the simple mean-difference estimate under
subject/block bootstrap weights (used by the Bayesian bootstrap and
related weighted-resampling machinery — see
InferenceNonParamBootstrap).
The weighted point estimate is \(\hat\beta_T = \bar y_T^w - \bar
y_C^w\), weighted arm means \(\bar y_T^w = \sum_i r_i y_i \mathbb{1}[w_i=1]
/ \sum_i r_i \mathbb{1}[w_i=1]\) (and analogously for control), where
\(r_i\) are the expanded row weights. Unless estimate_only =
TRUE, the standard error treats the bootstrap weights as frequency
weights. Within each arm, with total weight \(W = \sum r_i\) and
weighted residual sum of squares \(Q = \sum r_i(y_i - \bar y_w)^2\),
the variance contribution is \(Q / [W(W - 1)]\); the
Satterthwaite-Welch degrees of freedom likewise use \(W - 1\).
This reduces exactly to the ordinary Welch formula for unit weights.
Rows with non-finite or non-positive weight, or a
non-finite response, are dropped before computing; if no rows survive,
returns NA with all cached variance components set to NA.
Value
The difference in sample means (treated minus control) as a single
number, or NA_real_ if either arm has no observations.
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] |
wald | asymptotic | \(O(n_{eff}^{-1})\) | subjects | regular | assumed default | [Hall1992] |
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 is unbiased under randomization (theory: [Neyman1923], [ImbensRubin2015]).
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), forwald,jackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the size of the smaller arm.On
DesignFixedBinaryMatch,DesignFixedBlocking,DesignFixedGreedy,DesignFixedGreedyDOptimal,DesignFixedMatchingGreedyPairSwitching,DesignFixedOptimal,DesignFixedOptimalBlocks,DesignFixedRerandomization,DesignSeqOneByOneKK14,DesignSeqOneByOneKK21,DesignSeqOneByOneKK21stepwise,DesignSeqOneByOnePocockSimon,DesignSeqOneByOneSPBR, forwald: the error order is \(O(1)\) (design mismatch; [BaiRomanoShaikh2021], [BugniCanayShaikh2018], [MaHuZhang2015], [LiDingRubin2018]).On
DesignFixedBlockedCluster,DesignFixedCluster, forwald,jackknife,bootstrap,bayes_boot,rand_bootstrap: the effective n is the number of clusters.
References
Welch, B. L. (1947). "The Generalization of 'Student's' Problem when Several Different Population Variances are Involved." Biometrika, 34(1-2), 28-35, doi:10.1093/biomet/34.1-2.28 , for the unequal-variance t-test and its Satterthwaite-Welch degrees-of-freedom approximation used here.
[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.
[BaiRomanoShaikh2021] Bai, Y., Romano, J. P., and Shaikh, A. M. (2021; in print 2022). "Inference in Experiments with Matched Pairs." Journal of the American Statistical Association, 117(540), 1726-1737.
[BugniCanayShaikh2018] Bugni, F. A., Canay, I. A., and Shaikh, A. M. (2018). "Inference under Covariate-Adaptive Randomization." Journal of the American Statistical Association, 113(524), 1784-1796.
[MaHuZhang2015] Ma, W., Hu, F., and Zhang, L. (2015). "Testing Hypotheses of Covariate-Adaptive Randomized Clinical Trials." Journal of the American Statistical Association, 110(510), 669-680.
[LiDingRubin2018] Li, X., Ding, P., and Rubin, D. B. (2018). "Asymptotic Theory of Rerandomization in Treatment-Control Experiments." Proceedings of the National Academy of Sciences, 115(37), 9157-9162.
[Neyman1923] Neyman, J. (1923, transl. 1990). "On the Application of Probability Theory to Agricultural Experiments." Statistical Science, 5(4), 465-472.
[ImbensRubin2015] Imbens, G. W., and Rubin, D. B. (2015). Causal Inference for Statistics, Social, and Biomedical Sciences. Cambridge University Press.
Super class
Inference -> InferenceAllSimpleAverageDiff
Methods
Public 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$is_nonestimable()Inference$set_estimand()Inference$set_optimization_alg()Inference$set_seed()Inference$supports()
InferenceAllSimpleAverageDiff$compute_rand_two_sided_pval()
Uses the randomization-CI layer's two-sided p-value contract
(InferenceRandCI's version, not InferenceRand's): for
incidence responses it does not refuse outright; the default p-value
comes from the randomization draws, and the Zhang exact randomization
test is used only when type = "Zhang" is passed explicitly
(where applicable), matching this class's pre-migration old-ladder
behavior of not refusing (see
InferenceIncidRiskDiff's identical rationale). Previously bound
to InferenceRand's version instead, which silently regressed
Zhang dispatch after migration – see
inference_all_abstract_rand_ci.R's
compute_rand_two_sided_pval for why it's now safe to splice
this in outside the old inheritance chain.
Usage
InferenceAllSimpleAverageDiff$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
rNumber of randomization vectors.
deltaNull treatment effect value.
deltaNull treatment effect value.
transform_responsesResponse 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); seecompute_rand_confidence_interval()for the assumptions.na.rmWhether to remove non-finite simulated statistics.
show_progressWhether to show progress.
permutationsOptional pre-generated assignment draws.
typeNULL(default) or"Zhang", the only accepted value.NULLcomputes the p-value from the randomization draws."Zhang"instead returns the Zhang exact combined test (seeInferenceIncidExactZhang); it applies only to incidence responses on a Bernoulli or matching design. For any other response or design, a non-NULLtypeis an error; other strings (for example"Fisher"or"exact") are rejected.args_for_typeNULLor a list keyed bytype, used only withtype = "Zhang":list(Zhang = list(combination_method = "Stouffer")), wherecombination_methodis"Fisher"(default),"Stouffer"or"min_p".zero_one_logit_clampThe 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); seeInferenceRand$compute_rand_two_sided_pval().
InferenceAllSimpleAverageDiff$new()
Usage
InferenceAllSimpleAverageDiff$new(
des_obj,
model_formula = NULL,
verbose = FALSE,
max_resample_attempts = 50L,
smart_cold_start_default = NULL
)Arguments
des_objA DesignSeqOneByOne object whose entire n subjects are assigned and response y is recorded within.
model_formulaOptional covariate formula. It is accepted for interface consistency but does not change the estimate or standard error, which use only the responses and treatment assignments (no covariate adjustment). If
NULL(default), the formula from the design object is used.verboseWhether to print progress messages. Default
FALSE.max_resample_attemptsMaximum number of times a single bootstrap replicate may be redrawn when the drawn sample fails validity screening. If all attempts fail the replicate is recorded as
NA, silently reducing the effectiveB. Must be a positive integer. Default50L.smart_cold_start_defaultWhether to use smart cold start values.
InferenceAllSimpleAverageDiff$compute_estimate_with_bootstrap_weights()
Examples
seq_des = DesignSeqOneByOneBernoulli$new(n = 6, response_type = "continuous")
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[1, 2 : 10])
#> [1] 1
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[2, 2 : 10])
#> [1] 0
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[3, 2 : 10])
#> [1] 0
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[4, 2 : 10])
#> [1] 0
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[5, 2 : 10])
#> [1] 1
seq_des$add_one_subject_to_experiment_and_assign(MASS::biopsy[6, 2 : 10])
#> [1] 1
seq_des$add_all_subject_responses(c(4.71, 1.23, 4.78, 6.11, 5.95, 8.43))
seq_des_inf = InferenceAllSimpleAverageDiff$new(seq_des)
seq_des_inf$compute_estimate()
#> [1] 2.323333
seq_des_inf$compute_asymp_confidence_interval()
#> 2.5% 97.5%
#> -2.892650 7.539317
seq_des_inf$compute_asymp_two_sided_pval()
#> [1] 0.2760874