randomization_test {fastrerandomize}R Documentation

Fast randomization test

Description

Fast randomization test

Usage

randomization_test(
  obsW = NULL,
  obsY = NULL,
  alpha = 0.05,
  candidate_randomizations = NULL,
  candidate_randomizations_array = NULL,
  n0_array = NULL,
  n1_array = NULL,
  findFI = FALSE,
  c_initial = 2,
  conda_env = "fastrerandomize_env",
  conda_env_required = TRUE
)

Arguments

obsW

A numeric vector where 0's correspond to control units and 1's to treated units.

obsY

An optional numeric vector of observed outcomes. If not provided, the function assumes a NULL value.

alpha

The significance level for the test. Default is 0.05.

candidate_randomizations

A numeric matrix of candidate randomizations.

candidate_randomizations_array

An optional 'JAX' array of candidate randomizations. If not provided, the function coerces candidate_randomizations into a 'JAX' array.

n0_array

An optional array specifying the number of control units.

n1_array

An optional array specifying the number of treated units.

findFI

A logical value indicating whether to find the fiducial interval. Default is FALSE.

c_initial

A numeric value representing the initial criterion for the fiducial interval search. Default is 2.

conda_env

A character string specifying the name of the conda environment to use via reticulate. Default is "fastrerandomize_env".

conda_env_required

A logical indicating whether the specified conda environment must be strictly used. If TRUE, an error is thrown if the environment is not found. Default is TRUE.

Value

Returns an S3 object with slots:

References

See Also

generate_randomizations for randomization generation function.

Examples

## Not run: 
# A small synthetic demonstration with 6 units, 3 treated and 3 controls:

# Generate pre-treatment covariates
X <- matrix(rnorm(24*2), ncol = 2)

# Generate candidate randomizations
RandomizationSet_MC <- generate_randomizations(
  n_units = nrow(X),
  n_treated = round(nrow(X)/2),
  X = X,
  randomization_accept_prob = 0.1,
  randomization_type = "monte_carlo",
  max_draws = 100000,
  batch_size = 1000
)

# Generate outcome
W <- RandomizationSet_MC$randomizations[1,]
obsY <- rnorm(nrow(X), mean = 2 * W)

# Perform randomization test
results_base <- randomization_test(
  obsW = W,
  obsY = obsY,
  candidate_randomizations = RandomizationSet_MC$randomizations
)
print(results_base)

# Perform randomization test with fiducial interval
result_fi <- randomization_test(
  obsW = W,
  obsY = obsY,
  candidate_randomizations = RandomizationSet_MC$randomizations,
  findFI = TRUE
)
print(result_fi)

## End(Not run)


[Package fastrerandomize version 0.3 Index]