This function can be used to randomize the treatment assignment for randomized experiments. In addition to the complete randomization, it implements randomized-block and matched-pair designs.
randomize(
data,
group = c("Treat", "Control"),
ratio = NULL,
indx = NULL,
block = NULL,
n.block = NULL,
match = NULL,
complete = TRUE
)
A data frame containing the observations to which the treatments are randomly assigned.
A numerical or character vector indicating the treatment/control groups. The length of the vector equals the total number of such groups. The default specifies two groups called “Treat” and “Control”.
An optional numerical vector which specifies the proportion of the treatment/control groups within the sample. The length of the vector should equal the number of groups. The default is the equal allocation.
An optional variable name in the data frame to be used as the names of the observations. If not specified, the row names of the data frame will be used so long as they are available. If the row names are not available, the integer sequence starting from 1 will be used.
An optional variable name in the data frame or a formula to be
used as the blocking variables for randomized-block designs. If a variable
name is specified, then the unique values of that variable will form blocks
unless n.block
is specified (see below). If a formula is specified,
it will be evaluated using data
and then blocking will be based on
the mahalanobis
distance of the resulting model matrix. In this case,
users may want to specify n.block
to avoid creating blocks that have
too few observations.
An optional scalar specifying the number of blocks to be
created for randomized block designs. If unspecified, the unique values of
the blocking variable will define blocks. If specified, the blocks of
roughly equal size will be created based on the quantile
of the
blocking variable.
An optional variable name in the data frame or a formula to be
used as the matching variables for matched-pair designs. This input is
applicable only to the case where there are two groups. Pairs of
observations will be formed based on the similar values of the matching
variable. If a formula is specified, the mahalanobis
distance of the
resulting model matrix will be used.
logical. If it equals TRUE
(default), then complete
randomization will be performed (within each block if randomized block
designs are used). Otherwise, simple randomization will be implemented. For
matched-pair designs, complete
has to equal TRUE
.
A list of class randomize
which contains the following items:
the matched call.
The vector of randomized treatments.
The data frame that was used to conduct the randomization.
The blocking variable that was used to implement randomized-block designs.
The matching variable that was used to implement matched-pair designs.
The variable indicating which observations belong to which blocks in randomized-block designs.
The variable indicating which observations belong to which pairs in matched-pair designs.
Randomized-block designs refer to the complete randomization of the treatment within the pre-specified blocks which contain multiple observations. Matched-pair designs refer to the randomization of the binary treatment variable within the pre-specified pair of observations.