An abstract R6 Class that estimates, tests and provides intervals for a
treatment effect in a completed design.
This class takes a completed Design object as an input where this object
contains data for a fully completed experiment (i.e. all treatment
assignments were allocated and all responses were collected).
Perfect predictors among the covariates
At construction (or, if too few responses are recorded yet, lazily at the first
fit) the object checks whether the response, on a scale suited to its type, is an
exact linear function of the treatment and the covariates: y (continuous),
log y over exact event times with every censored time's interval containing
the fitted time (survival), logit(y) over interior values (proportion),
y or log1p(y) (count), the 0/1 response (incidence) or the category
codes (ordinal). The check is a least-squares residual check (residual sum of
squares about 0 relative to the total), skipped when there are fewer than 5
residual degrees of freedom. An exact fit on the treatment alone is a real
treatment effect and is left alone. Otherwise the smallest set of covariate
columns whose removal breaks the exact fit is dropped from the covariates this
object uses (the treatment is never dropped; with several smallest sets, their
union is dropped), and one warning of class edi_perfect_predictor_warning
(fields dropped, scales) names them: in a randomized experiment this
almost always means leakage (the outcome, or a variable measured after treatment,
among the covariates). Every later estimate, interval, test and resampling
replicate uses the reduced covariates. Only linear relations on that scale are
caught. Separation (some combination of treatment and covariates splitting the
outcomes) can happen by chance, so it is never handled here: classes warn about it
but keep the covariates. Classes whose fit does not use the covariates skip the
check.
Active bindings
num_coresCurrent number of cores for this inference object. Defaults to the global budget unless overridden on the object.
Methods
Inference$new()
Initialize an estimation and test object after the design is completed.
Usage
Inference$new(
des_obj,
verbose = FALSE,
harden = TRUE,
model_formula = NULL,
smart_cold_start_default = NULL,
seed = NULL
)Arguments
des_objA completed
Designobject whose entire n subjects are assigned and response y is recorded within.verboseWhether to print progress messages.
hardenWhether to apply robustness measures (default
TRUE). WhenTRUE, the inference methods employ defensive strategies including QR-based rank reduction of the design matrix, progressive correlation-threshold dropping, and fallback fits (e.g.\ robust survival regression, treatment-only models) to avoid crashes on ill-conditioned data. WhenFALSE, the vanilla algorithm runs on the full design matrix as supplied; any rank deficiency or convergence failure will surface as an error rather than being silently worked around. Set toFALSEwhen you want to verify that the raw model converges without intervention.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. Anoffset()term is refused with an error: offsets are not supported yet.smart_cold_start_defaultWhether to use smart cold start values by default for likelihood-based models. Explicit starts always override this object-level policy.
NULL(default) consults the global cold-start dispatch policy.seedInteger seed for reproducibility.
Inference$capabilities()
Returns the effective metadata-backed capabilities for this inference object.
Inference$compute_exact_two_sided_pval_for_treatment_effect()
Computes an exact two-sided p-value. Subclasses that support exact inference override this; inference objects that do not support exact methods throw an error.
Inference$compute_exact_confidence_interval()
Computes an exact confidence interval. Subclasses that support exact inference override this; inference objects that do not support exact methods throw an error.
Inference$compute_asymp_two_sided_pval()
Computes an asymptotic two-sided p-value. Subclasses that support asymptotic inference override this; inference objects that do not support asymptotic methods throw an error.
Inference$compute_asymp_confidence_interval()
Computes an asymptotic confidence interval. Subclasses that support asymptotic inference override this; inference objects that do not support asymptotic methods throw an error.
Inference$compute_estimate()
Computes the treatment-effect estimate. Concrete subclasses implement the model-specific estimator, such as a fitted regression coefficient, maximum-likelihood parameter, estimating-equation solution, mean or risk contrast, survival contrast, or rank statistic. Interval, p-value, bootstrap, jackknife, and randomization methods use this method as the canonical point-estimate contract.
Inference$is_nonestimable()
Returns whether the most recent inference attempt explicitly marked the result as non-estimable.
Usage
Inference$is_nonestimable(type = c("any", "estimate", "se"))Inference$get_nonestimable_reason()
Returns the reason recorded for the most recent explicit non-estimability.
Inference$get_nonestimable_stage()
Returns the stage recorded for the most recent explicit non-estimability.
Inference$get_summary()
Prints a coefficient summary table (Estimate / Std. Error /
statistic / p-value) for the most recent fit and returns it invisibly. Works for
every inference class: model-based classes show the full coefficient table when
coefficient names and a covariance matrix are available, otherwise (including
classes without a fitted model, such as randomization-only classes) a one-row
treatment summary. Pieces that are unavailable (e.g. a Wald standard error) are
shown as NA; this method never errors because one is missing.
Inference$duplicate()
Duplicate this inference object
Inference$get_response()
Return the response vector used by inference extension classes.
This accessor is part of the supported extension contract for user-defined R6 inference classes. Prefer this method over direct access to private fields.
Inference$get_treatment()
Return the treatment-assignment vector used by inference extension classes.
This accessor is part of the supported extension contract for user-defined R6 inference classes. Treatment is encoded as 0/1.
Inference$get_covariates()
Return the processed covariate matrix used by inference extension classes.
This accessor returns the design object's model-matrix covariates, after
the package's missingness handling and encoding, minus any columns
dropped by the perfect-predictor check (so it can have fewer columns
than the design object's own matrix). It may be NULL if no
covariates are available.
Inference$get_analysis_data()
Return a data frame with response, treatment, censoring status, and covariates.
This accessor is the preferred data interface for user-defined R6
inference classes. It avoids reliance on private implementation fields.
The returned data frame always contains y, w, and
dead; covariate columns are appended when available.
Inference$get_design_object()
Return the completed design object backing this inference object.
This accessor is part of the supported extension contract. Extension
classes should use this method instead of private$des_obj.
Inference$get_procedure_validity()
Look up what EDI's validity registry says about the inference
procedures this object supports by default (or a chosen subset): the
regime ("asymptotic" or "finite_sample"), the expected
order of the size error, the effective-sample-size rule together with
its realised value for this object's data, the regularity of the
problem, and the basis and reference of each claim. Nothing is fitted.
The same lookup without data is
get_inference_procedure_validity().
Arguments
procedureNULL(default) for every supported procedure, or procedure labels as used in themethodcolumn ofrun_all_inference()results (e.g."wald").
Returns
A list with expectation (a data frame, one row per
procedure, see get_inference_procedure_validity()),
measured (NULL: no measured calibration values are
shipped yet) and measured_note.
Inference$set_estimand()
Change the target estimand. Only classes that compose the
MarginalEstimand component
(capability "marginal_estimand") can do this; they replace this
method with their own. On every other class it stops with an error of
class "edi_estimand_not_supported".
Arguments
estimandIgnored here; see the
MarginalEstimandversion.
Inference$get_estimand()
The current target estimand. On classes without the
MarginalEstimand component
this is always "conditional": the class reports only its
default treatment effect.
Inference$get_supported_estimands()
The estimands this object can be switched to with
set_estimand(). Classes without the
MarginalEstimand component
cannot switch, so this stops with an error of class
"edi_estimand_not_supported".
Inference$set_optimization_alg()
Set the optimizer used by likelihood-based inference implementations. Changing the optimizer clears the object's cached results.
Usage
Inference$set_optimization_alg(
optimization_alg = NULL,
allow_irls = private$optimization_alg_allow_irls,
default = private$optimization_alg_default
)Arguments
optimization_algThe optimizer name:
"newton_raphson"or"lbfgs", plus"irls"when IRLS is allowed (seeallow_irls). Unambiguous abbreviations (e.g."newton") are accepted viamatch.arg; any other value is an error.NULL(the default) selectsdefault.allow_irlsWhether
"irls"(Iteratively Reweighted Least Squares) is an accepted value. Defaults to the object's current setting, which the class constructor sets (TRUEonly for classes with an IRLS fit, such asInferenceIncidLogRegrandInferenceIncidProbitRegr).defaultThe optimizer used when
optimization_algisNULL. When missing orNULLit comes from the optimization dispatch policy for this class (seeget_optimization_dispatch_policyandset_optimization_dispatch_policy):"newton_raphson"unless the policy names another optimizer for the class (for example"lbfgs"forInferenceSurvivalWeibullRegr).
Inference$get_optimization_alg()
Return the optimizer used by likelihood-based inference implementations.
Inference$set_seed()
Set the seed for reproducibility. The seed governs the
parallel resampling workers and the randomization-test draws
(compute_rand_two_sided_pval(), compute_rand_confidence_interval()):
the randomization permutations are drawn from this seed (falling back to the
design's own seed when none is set here), inside a save/restore of the
caller's global .Random.seed, and the seed is part of the design-level
permutation-cache key. Without any seed the draws come from the global RNG
stream at the first call and are then cached on the design.
Inference$clear_randomization_cache()
Drop the design-level cache of randomization permutations (shared by every inference object built on this design), so the next randomization p-value / confidence interval redraws its permutations.
