Description Usage Arguments Value Examples
View source: R/block_randomization.R
this function peforms block randomization of 2 treatments.
1 2 3 4 5 6 | block_randomization(
df,
blocking_vars,
frac,
treatment_names = c("control", "treatment")
)
|
df |
input data.frame. should include the variables
in |
blocking_vars |
string vector denoting the names of
variables in |
frac |
a numeric between 0 and 1. the fraction of observations assigned to the 2nd treatment group |
treatment_names |
names of the treatment groups. default is "control" for the first group and "treatment" for the second. |
a vector of treatment assignments
1 2 3 4 5 6 7 8 9 10 11 | library(utilityFunctions)
df <- data.frame(var1 = c(rep("A", 99), rep("B", 201), rep("C", 44), rep("D", 56)),
var2 = c(rep("E", 25), rep("F", 100), rep("G", 100), rep("H", 100), rep("I", 75)),
var3 = rep("J", 400))
blocking_vars <- c("var1", "var2")
df$treatment <- block_randomization(df, blocking_vars, frac = 0.8,
treatment_names = c("treat 1", "treat 2"))
# In the below example, not all blockings can attain an exact fraction of 0.8
tapply(df$treatment, paste0(df$var1, df$var2), function(x) mean(x == "treat 2"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.