Insert, delete and replace steps in an (already declared) design object.

insert_step(design, new_step, before = NULL, after = NULL)

delete_step(design, step)

replace_step(design, step, new_step)

Arguments

design

a design object, usually created by declare_design, fill_out, or the design library.

new_step

the new step - either a function or a partial call

before

the step before which to add steps

after

same

step

the step to be deleted or replaced

Value

A new design object. See declare_design for details.

Details

see modify_design for details.

Examples

my_population <- declare_population(N = 100, noise = rnorm(N)) my_potential_outcomes <- declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) my_assignment <- declare_assignment(m = 50) my_assignment_2 <- declare_assignment(m = 25) design <- declare_design(my_population, my_potential_outcomes, my_assignment) design
#> #> Design Summary #> #> Step 1 (population): declare_population(N = 100, noise = rnorm(N)) ------------- #> #> N = 100 #> #> Added variable: ID #> N_missing N_unique class #> 0 100 character #> #> Added variable: noise #> min median mean max sd N_missing N_unique #> -2.77 0.1 0.02 2.69 1.03 0 100 #> #> Step 2 (potential outcomes): declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) #> #> Added variable: Y_Z_0 #> min median mean max sd N_missing N_unique #> -2.77 0.1 0.02 2.69 1.03 0 100 #> #> Added variable: Y_Z_1 #> min median mean max sd N_missing N_unique #> -4 1.7 1.83 7.47 2.33 0 100 #> #> Step 3 (assignment): declare_assignment(m = 50) -------------------------------- #> #> Added variable: Z #> 0 1 #> 50 50 #> 0.50 0.50 #> #> Added variable: Z_cond_prob #> 0.5 #> 100 #> 1.00 #>
insert_step(design, dplyr::mutate(income = noise^2), after = my_assignment)
#> #> Design Summary #> #> Step 1 (population): declare_population(N = 100, noise = rnorm(N)) ------------- #> #> N = 100 #> #> Added variable: ID #> N_missing N_unique class #> 0 100 character #> #> Added variable: noise #> min median mean max sd N_missing N_unique #> -2.76 0.09 0.07 3.45 1.13 0 100 #> #> Step 2 (potential outcomes): declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) #> #> Added variable: Y_Z_0 #> min median mean max sd N_missing N_unique #> -2.76 0.09 0.07 3.45 1.13 0 100 #> #> Added variable: Y_Z_1 #> min median mean max sd N_missing N_unique #> -1.61 2.11 2.01 6.69 1.93 0 100 #> #> Step 3 (assignment): declare_assignment(m = 50) -------------------------------- #> #> Added variable: Z #> 0 1 #> 50 50 #> 0.50 0.50 #> #> Added variable: Z_cond_prob #> 0.5 #> 100 #> 1.00 #> #> Step 4 (wrapped): ~dplyr::mutate(income = noise^2) ----------------------------- #> #> Added variable: income #> min median mean max sd N_missing N_unique #> 0 0.77 1.26 11.92 1.82 0 100 #>
insert_step(design, dplyr::mutate(income = noise^2), before = my_assignment)
#> #> Design Summary #> #> Step 1 (population): declare_population(N = 100, noise = rnorm(N)) ------------- #> #> N = 100 #> #> Added variable: ID #> N_missing N_unique class #> 0 100 character #> #> Added variable: noise #> min median mean max sd N_missing N_unique #> -2.8 0.07 -0.03 1.84 0.91 0 100 #> #> Step 2 (potential outcomes): declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) #> #> Added variable: Y_Z_0 #> min median mean max sd N_missing N_unique #> -2.8 0.07 -0.03 1.84 0.91 0 100 #> #> Added variable: Y_Z_1 #> min median mean max sd N_missing N_unique #> -3.84 2.13 2.08 8.32 2.35 0 100 #> #> Step 3 (wrapped): ~dplyr::mutate(income = noise^2) ----------------------------- #> #> Added variable: income #> min median mean max sd N_missing N_unique #> 0 0.46 0.83 7.86 1.2 0 100 #> #> Step 4 (assignment): declare_assignment(m = 50) -------------------------------- #> #> Added variable: Z #> 0 1 #> 50 50 #> 0.50 0.50 #> #> Added variable: Z_cond_prob #> 0.5 #> 100 #> 1.00 #>
delete_step(design, my_assignment)
#> #> Design Summary #> #> Step 1 (population): declare_population(N = 100, noise = rnorm(N)) ------------- #> #> N = 100 #> #> Added variable: ID #> N_missing N_unique class #> 0 100 character #> #> Added variable: noise #> min median mean max sd N_missing N_unique #> -2.49 -0.01 -0.09 2.2 0.92 0 100 #> #> Step 2 (potential outcomes): declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) #> #> Added variable: Y_Z_0 #> min median mean max sd N_missing N_unique #> -2.49 -0.01 -0.09 2.2 0.92 0 100 #> #> Added variable: Y_Z_1 #> min median mean max sd N_missing N_unique #> -3.73 1.96 2.07 7.18 2.24 0 100 #>
replace_step(design, my_assignment, dplyr::mutate(words="HIARYLAH"))
#> #> Design Summary #> #> Step 1 (population): declare_population(N = 100, noise = rnorm(N)) ------------- #> #> N = 100 #> #> Added variable: ID #> N_missing N_unique class #> 0 100 character #> #> Added variable: noise #> min median mean max sd N_missing N_unique #> -3.11 -0.25 -0.13 2.3 1.07 0 100 #> #> Step 2 (potential outcomes): declare_potential_outcomes(Y_Z_0 = noise, Y_Z_1 = noise + rnorm(N, mean = 2, sd = 2)) #> #> Added variable: Y_Z_0 #> min median mean max sd N_missing N_unique #> -3.11 -0.25 -0.13 2.3 1.07 0 100 #> #> Added variable: Y_Z_1 #> min median mean max sd N_missing N_unique #> -5.34 1.81 1.82 7.13 2.06 0 100 #> #> Step 3 (wrapped): ~dplyr::mutate(words = "HIARYLAH") --------------------------- #> #> Added variable: words #> HIARYLAH #> 100 #> 1.00 #>