Skip to contents

Abstract class for randomization-based inference.

Super class

Inference -> InferenceRand

Methods

+ inherited public methods from Inference


InferenceRand$set_custom_randomization_statistic_function()

Set a custom R randomization statistic.

Replaces the default treatment-effect estimate used in approximate_randomization_distribution_beta_hat_T() and compute_randomization_two_sided_pval() with a user-supplied R function. The function must return one scalar statistic for the current randomized outcome/assignment state. Pass NULL to clear the custom statistic. This cannot be used at the same time as set_custom_randomization_statistic_cpp().

Usage

InferenceRand$set_custom_randomization_statistic_function(
  custom_randomization_statistic_function
)

Arguments

custom_randomization_statistic_function

A function that returns one scalar value, or NULL to restore the class default statistic.


InferenceRand$set_custom_randomization_statistic_cpp()

Set a custom compiled C++ randomization statistic.

Replaces the default treatment-effect estimate used in approximate_randomization_distribution_beta_hat_T() and compute_randomization_two_sided_pval() with a scalar C++ statistic. A source string is recommended because each parallel worker can compile its own copy safely. A pre-compiled Rcpp function can be used in the main process, but external pointers may not survive serialization to workers. Pass NULL to clear the custom statistic. This cannot be used at the same time as set_custom_randomization_statistic_function().

Usage

InferenceRand$set_custom_randomization_statistic_cpp(fn)

Arguments

fn

Either a C++ source code string, a pre-compiled Rcpp function, an RcppXPtrUtils::cppXPtr() external pointer, or NULL. A source string or Rcpp function must return a scalar double and accept either (NumericVector y, IntegerVector w) or (NumericVector y, IntegerVector w, IntegerVector dead). An external pointer follows the package-wide user_compiled_fns.h calling convention shared with DesignFixedOptimal's custom_objective – Eigen types: double f(const Eigen::VectorXd& y, const Eigen::VectorXd& w), or the 3-argument form appending const Eigen::VectorXd& dead – and, like a pre-compiled Rcpp function, is valid in the main process only (external pointers do not survive serialization to parallel workers; use a source string for parallel paths).


InferenceRand$approximate_randomization_distribution_beta_hat_T()

Computes the randomization distribution of the treatment effect estimate under the sharp null.

Usage

InferenceRand$approximate_randomization_distribution_beta_hat_T(
  r = 501,
  delta = 0,
  transform_responses = "none",
  show_progress = TRUE,
  permutations = NULL,
  debug = FALSE,
  zero_one_logit_clamp = .Machine$double.eps
)

Arguments

r

Number of randomization vectors. Default 501.

delta

The null difference. Default 0.

transform_responses

Type of transformation. Default "none".

show_progress

Show progress bar. Default TRUE.

permutations

Pre-computed permutations. Default NULL.

debug

If TRUE, return a list with the distribution values and per-iteration diagnostics including error messages, warning messages, counts of each, and summary proportions for iterations with errors, warnings, and illegal (non-finite) values. Runs serially. Default FALSE.

zero_one_logit_clamp

The clamping amount for exact 0 and 1 values when logging

Returns

When debug = FALSE (default), a numeric vector of length r. When debug = TRUE, a list with: values, errors (list of character vectors, one per iteration), warnings (list of character vectors, one per iteration), num_errors, num_warnings, prop_iterations_with_errors, prop_iterations_with_warnings, and prop_illegal_values.


InferenceRand$supports_rand_pval_for_incidence()

Whether compute_rand_two_sided_pval() is actually usable on this instance right now – FALSE exactly when it would stop(): an incidence-response instance with no custom randomization statistic and a design not eligible for design-randomization-based incidence inference (see private$should_use_design_randomization_for_incidence()). TRUE for every other case, including every non-incidence response type. Public, self-contained (only reads already-set instance state, no side effects), so InferenceSuite can check this before attempting the sentinel instead of relying on the stop() being silently swallowed into a pval = NA "ok" row – the single source of truth for both this check and compute_rand_two_sided_pval()'s own guard, so the two can never drift apart (fix_inference_hierarchy.md's method-level-`stop()` TODO, 2026-08-21).

Usage

InferenceRand$supports_rand_pval_for_incidence()

Returns

A single logical.


InferenceRand$compute_rand_two_sided_pval()

Computes a randomization-based p-value.

Usage

InferenceRand$compute_rand_two_sided_pval(
  r = 501,
  delta = 0,
  transform_responses = "none",
  na.rm = TRUE,
  show_progress = TRUE,
  permutations = NULL,
  zero_one_logit_clamp = .Machine$double.eps
)

Arguments

r

Number of randomization vectors.

delta

Null difference.

transform_responses

Transformation.

na.rm

Remove NAs.

show_progress

Show progress.

permutations

Pre-computed permutations.

zero_one_logit_clamp

The clamping amount for exact 0 and 1 values when logging

Returns

Randomization p-value.


InferenceRand$clone()

The objects of this class are cloneable with this method.

Usage

InferenceRand$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.