declare_assignment: Declare Assignment Procedure

Description Usage Arguments Details Value Examples

Description

Declare Assignment Procedure

Usage

1
2
3
declare_assignment(..., handler = assignment_handler, label = NULL)

assignment_handler(data, ..., assignment_variable = "Z")

Arguments

...

arguments to be captured, and later passed to the handler

handler

a tidy-in, tidy-out function

label

a string describing the step

data

a data.frame

assignment_variable

name for assignment variable

Details

While declare_assignment can work with any assignment_function that takes data and returns data, most random assignment procedures can be easily implemented with randomizr. The arguments to conduct_ra can include N, block_var, clust_var, m, m_each, prob, prob_each, block_m, block_m_each = NULL, block_prob, block_prob_each, num_arms, and conditions. The arguments you need to specify are different for different designs. Check the help files for complete_ra, block_ra, cluster_ra, or block_and_cluster_ra for details on how to execute many common designs.

Custom assignment handlers should augment the data frame with an appropriate column for the assignments.

Value

a function that takes a data.frame as an argument and returns a data.frame with additional columns appended including an assignment variable and (optionally) probabilities of assignment.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
########################################################
# Default Handler
# Delegates to conduct_ra

my_assignment <- declare_assignment(m = 50)
my_assignment <- declare_assignment(block_prob = 1/3, blocks = female)
my_assignment <- declare_assignment(block_prob = 1/4, clusters = classrooms)

my_assignment <- declare_assignment(
  block_prob = 1/4,
  clusters = classrooms,
  assignment_variable = "X1"
)

########################################################
#' # Custom random assignment functions

my_assignment_function <- function(data) {
   data$Z <- ifelse(data$extra <= median(data$extra), 1, 0)
   data
}

my_assignment_custom <- declare_assignment(handler = my_assignment_function)

df <- my_assignment_custom(sleep)
table(df$Z, df$group)

graemeblair/DeclareDesign documentation built on May 8, 2018, 1:24 p.m.