declare_assignment: Declare Data Strategy: Assignment

Description Usage Arguments Value Examples

Description

Declare Data Strategy: Assignment

Usage

1
2
3

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.

legacy

Use the legacy randomizr functionality. This will be disabled in future; please use legacy = FALSE.

Value

A function that takes a data.frame as an argument and returns a data.frame with assignment columns appended.

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
27
28
29
30
31
32
33
34
35
# setting up a design stub
design <- declare_model(
  classrooms = add_level(10),
  individuals = add_level(20, female = rbinom(N, 1, 0.5))
) + NULL

# Declare assignment of m units to treatment
design + declare_assignment(Z = complete_ra(N = N, m = 100), legacy = FALSE)

# Declare assignment specifying varying block probabilities
design + 
  declare_assignment(Z = block_ra(blocks = female, 
                                  block_prob = c(1/3, 2/3)), legacy = FALSE)

# Declare assignment of clusters with probability 1/4
design + declare_assignment(
  Z = cluster_ra(prob = 1/4, clusters = classrooms), legacy = FALSE)
 
# Declare factorial assignment (Approach 1): 
#   Use complete random assignment to assign Z1 
#   then block on Z1 to assign Z2. 
design + 
   declare_assignment(Z1 = complete_ra(N = N, m = 100),
                      Z2 = block_ra(blocks = Z1), legacy = FALSE)
   
# Declare factorial assignment (Approach 2): 
#   Assign to four conditions and then split into Z1 and Z2 
design +  
  declare_assignment(Z = complete_ra(N = N, conditions = 1:4),
                     Z1 = as.numeric(Z %in% 2:3), 
                     Z2 = as.numeric(Z %in% 3:4), legacy = FALSE)
   
# Declare assignment using functions outside randomizr package:
design + 
  declare_assignment(Z = rbinom(n = N, size = 1, prob = 0.35), legacy = FALSE)

DeclareDesign documentation built on Feb. 15, 2021, 1:07 a.m.