Skip to contents

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_cores

Current 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_obj

A completed Design object whose entire n subjects are assigned and response y is recorded within.

verbose

Whether to print progress messages.

harden

Whether to apply robustness measures (default TRUE). When TRUE, 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. When FALSE, 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 to FALSE when you want to verify that the raw model converges without intervention.

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. An offset() term is refused with an error: offsets are not supported yet.

smart_cold_start_default

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

seed

Integer seed for reproducibility.


Inference$capabilities()

Returns the effective metadata-backed capabilities for this inference object.

Usage

Inference$capabilities()

Returns

A character vector of capability names.


Inference$supports()

Returns whether this inference object supports a metadata-backed capability.

Usage

Inference$supports(capability)

Arguments

capability

Capability name or names.

Returns

A logical vector aligned with capability.


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.

Usage

Inference$compute_exact_two_sided_pval_for_treatment_effect(...)

Arguments

...

Other arguments passed to the method.


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.

Usage

Inference$compute_exact_confidence_interval(...)

Arguments

...

Other arguments passed to the method.


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.

Usage

Inference$compute_asymp_two_sided_pval(delta = 0)

Arguments

delta

Null treatment effect.


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.

Usage

Inference$compute_asymp_confidence_interval(alpha = 0.05)

Arguments

alpha

Significance level.


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.

Usage

Inference$compute_estimate(estimate_only = FALSE)

Arguments

estimate_only

If TRUE, skip variance component calculations.

Returns

A numeric treatment estimate.


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"))

Arguments

type

Which stage to query: "any", "estimate", or "se".

Returns

A logical scalar.


Inference$get_nonestimable_reason()

Returns the reason recorded for the most recent explicit non-estimability.

Usage

Inference$get_nonestimable_reason()

Returns

A character scalar or NULL.


Inference$get_nonestimable_stage()

Returns the stage recorded for the most recent explicit non-estimability.

Usage

Inference$get_nonestimable_stage()

Returns

A character scalar or NULL.


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.

Usage

Inference$get_summary()

Returns

Invisibly, the printed summary as a numeric matrix.


Inference$duplicate()

Duplicate this inference object

Usage

Inference$duplicate(verbose = FALSE, make_fork_cluster = FALSE)

Arguments

verbose

A flag indicating whether messages should be displayed.

make_fork_cluster

Whether the duplicate should be allowed to create a fork cluster. Default FALSE.

Returns

A new Inference object with the same data


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.

Usage

Inference$get_response()

Returns

A numeric response vector.


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.

Usage

Inference$get_treatment()

Returns

A numeric or integer 0/1 treatment vector.


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.

Usage

Inference$get_covariates()

Returns

A numeric matrix of covariates or NULL.


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.

Usage

Inference$get_analysis_data()

Returns

A data frame suitable for user-defined model fitting.


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.

Usage

Inference$get_design_object()

Returns

The completed Design object.


Inference$get_response_type()

Return the response type for the backing design.

Usage

Inference$get_response_type()

Returns

A character scalar such as "continuous", "incidence", "proportion", "count", "survival", or "ordinal".


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().

Usage

Inference$get_procedure_validity(procedure = NULL)

Arguments

procedure

NULL (default) for every supported procedure, or procedure labels as used in the method column of run_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".

Usage

Inference$set_estimand(estimand)

Arguments

estimand

Ignored here; see the MarginalEstimand version.

Returns

Does not return; always signals an error.


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.

Usage

Inference$get_estimand()

Returns

A character scalar.


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

Usage

Inference$get_supported_estimands()

Returns

Does not return on classes without the component.


Inference$get_model_formula()

Return the model formula used for covariate adjustment.

Usage

Inference$get_model_formula()

Returns

A formula object or NULL.


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_alg

The optimizer name: "newton_raphson" or "lbfgs", plus "irls" when IRLS is allowed (see allow_irls). Unambiguous abbreviations (e.g. "newton") are accepted via match.arg; any other value is an error. NULL (the default) selects default.

allow_irls

Whether "irls" (Iteratively Reweighted Least Squares) is an accepted value. Defaults to the object's current setting, which the class constructor sets (TRUE only for classes with an IRLS fit, such as InferenceIncidLogRegr and InferenceIncidProbitRegr).

default

The optimizer used when optimization_alg is NULL. When missing or NULL it comes from the optimization dispatch policy for this class (see get_optimization_dispatch_policy and set_optimization_dispatch_policy): "newton_raphson" unless the policy names another optimizer for the class (for example "lbfgs" for InferenceSurvivalWeibullRegr).

Returns

Invisibly returns self.


Inference$get_optimization_alg()

Return the optimizer used by likelihood-based inference implementations.

Usage

Inference$get_optimization_alg()


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.

Usage

Inference$set_seed(seed)

Arguments

seed

Integer seed for reproducibility.


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.

Usage

Inference$clear_randomization_cache()

Returns

self, invisibly.


Inference$clone()

The objects of this class are cloneable with this method.

Usage

Inference$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.