
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
A two-sided p-value.
The setting-appropriate (see description) numeric estimate of the treatment effect
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.
Super class
Inference -> InferenceAllSimpleAverageDiff
Methods
Public methods
+ inherited public methods from Inference
Inference$capabilities()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_model_formula()Inference$get_nonestimable_reason()Inference$get_nonestimable_stage()Inference$get_optimization_alg()Inference$get_response()Inference$get_response_type()Inference$get_treatment()Inference$is_nonestimable()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 this dispatches to the Zhang exact randomization
test where applicable rather than refusing outright, matching this
class's pre-migration old-ladder behavior (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
)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.
typeOptional incidence-specific exact randomization type.
args_for_typeOptional arguments keyed by
type.zero_one_logit_clampThe clamping amount for exact 0 and 1 values when logging
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 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. 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] 0
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.9825
seq_des_inf$compute_asymp_confidence_interval()
#> 2.5% 97.5%
#> -2.810951 8.775951
seq_des_inf$compute_asymp_two_sided_pval()
#> [1] 0.181089