| 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 |
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 |
candidate_randomizations |
A numeric matrix of candidate randomizations. |
candidate_randomizations_array |
An optional 'JAX' array of candidate randomizations. If not provided, the function coerces |
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 |
conda_env |
A character string specifying the name of the conda environment to use
via |
conda_env_required |
A logical indicating whether the specified conda environment
must be strictly used. If |
Value
Returns an S3 object with slots:
-
p_valueA numeric value or vector representing the p-value of the test (or the expected p-value under the prior structure specified in the function inputs). -
FIA numeric vector representing the fiducial interval iffindFI=TRUE. -
tau_obsA numeric value or vector representing the estimated treatment effect(s). -
fastrr_envThe fastrerandomize environment.
References
Zhang, Y. and Zhao, Q., 2023. What is a randomization test?. Journal of the American Statistical Association, 118(544), pp.2928-2942.
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)