
A Fixed-Sample-Size Bernoulli (Independent-Coin-Flip) Randomized Design
Source:R/design_fixed_bernoulli.R
DesignFixedBernoulli.RdA fixed-sample-size DesignFixed in which each subject's
treatment assignment \(w_i\) is drawn independently as
\(w_i \stackrel{iid}{\sim} \mathrm{Bernoulli}(p)\), \(i = 1, \dots, n\), where
\(p\) is prob_T. This is the classical Bernoulli (independent-coin-flip)
randomized design: unlike
DesignFixediBCRD (complete randomization), which
fixes the number of treated subjects at exactly \(\mathrm{round}(np)\), a Bernoulli
design leaves the realized number of treated subjects
\(n_T = \sum_i w_i \sim \mathrm{Binomial}(n, p)\) random; the trade-off is
independence across subjects (useful for some asymptotic/martingale arguments) at the
cost of not guaranteeing exact balance, which can matter for small \(n\) or for
inference procedures (e.g. exact permutation tests over a fixed number of treated) that
assume a fixed \(n_T\).
Draw mechanism. draw_ws_raw(r) delegates to
generate_permutations_bernoulli_cpp(), which fills an \(n \times r\) matrix of
independent \(\mathrm{Bernoulli}(p)\) draws (one column per requested replicate,
via a Mersenne Twister RNG seeded once per call from R's RNG state), so
r replicate allocation vectors are generated with a single C++ call rather than
r separate calls into R's own random-number generation.
assign_w_to_all_subjects() draws a single such allocation
(r = 1) and applies it to all subjects at once.
No exchange/balance search. Because subjects are treated independently, there
is no optimization step analogous to
DesignFixedGreedyDOptimal: covariates, if supplied, do
not influence the assignment probabilities or realized allocation at all.
References
Neyman, J. (1923, transl. 1990). "On the Application of Probability Theory to Agricultural Experiments." Statistical Science, 5(4), 465-472, for the potential-outcomes framework under which Bernoulli and complete randomization are compared; see also randomized experiment for orientation on Bernoulli vs. complete (restricted) randomization.
Super classes
Design -> DesignFixed -> DesignFixedBernoulli
Methods
+ inherited public methods from DesignFixed
+ inherited public methods from Design
Design$add_one_subject_response()Design$any_censoring()Design$applicable_inference_class_names()Design$assert_all_responses_recorded()Design$assert_all_subjects_arrived()Design$assert_even_allocation()Design$assert_fixed_sample()Design$capabilities()Design$check_experiment_completed()Design$draw_ws_according_to_design()Design$duplicate()Design$get_X()Design$get_X_imp()Design$get_X_raw()Design$get_design_formula()Design$get_edi_version_created()Design$get_effective_dead()Design$get_effective_time()Design$get_missingness_method()Design$get_n()Design$get_ordinal_levels()Design$get_original_ordinal_levels()Design$get_prob_T()Design$get_response_type()Design$get_response_type_original()Design$get_t()Design$get_w()Design$get_y()Design$get_y_L()Design$get_y_R()Design$get_y_original()Design$has_general_censoring()Design$incompatible_inference_classes_due_to_design_structure()Design$is_a_cluster_capable()Design$is_a_kk_matching_capable()Design$is_blocking_design()Design$is_fixed_sample_size()Design$is_matching_design()Design$prepare_for_resampling_replay()Design$randomization_family()Design$supports()Design$supports_randomization_draw()Design$supports_resampling()Design$supports_resampling_replay()Design$transform_y()Design$unavailable_inference_classes_due_to_missing_packages()Design$warm_all_subject_data_cache()
DesignFixedBernoulli$is_a_bernoulli_capable()
Characterization: this design draws each subject's treatment assignment as an independent \(\mathrm{Bernoulli}(p)\) coin flip (see class documentation), so it is Bernoulli-capable by construction.
DesignFixedBernoulli$new()
Initialize a fixed Bernoulli (independent-coin-flip) experimental
design. Unlike DesignFixediBCRD, the
realized number of treated subjects is not fixed at n * prob_T; it is
random (\(\mathrm{Binomial}(n, prob\_T)\)) because each subject's assignment
is an independent coin flip (see class documentation).
Usage
DesignFixedBernoulli$new(
response_type,
prob_T = 0.5,
include_is_missing_as_a_new_feature = TRUE,
n = NULL,
verbose = FALSE,
missingness_method = "impute",
design_formula = ~.,
seed = NULL
)Arguments
response_type"continuous", "incidence", "proportion", "count", "survival", or "ordinal".
prob_TPer-subject probability \(p\) that a given subject is assigned to treatment; need not be
0.5(unlikeDesignFixedGreedyDOptimal).include_is_missing_as_a_new_featureFlag for missingness indicators.
nThe sample size.
verboseA flag for verbosity.
missingness_methodHow to handle missing values in covariates.
design_formulaA formula object.
seedInteger seed for reproducibility.
Examples
des = DesignFixedBernoulli$new(n = 10, response_type = 'continuous')
des$add_all_subjects_to_experiment(data.frame(x1 = rnorm(10)))
des$assign_w_to_all_subjects()