Insert, delete and replace steps in an (already declared) design object.
Usage
insert_step(design, new_step, before, after)
delete_step(design, step)
replace_step(design, step, new_step)
Arguments
- design
A design object, usually created using the + operator,
expand_design
, 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
The step after which to add steps.
- step
The quoted label of the step to be deleted or replaced.
Examples
my_model <-
declare_model(
N = 100,
U = rnorm(N),
Y_Z_0 = U,
Y_Z_1 = U + rnorm(N, mean = 2, sd = 2)
)
my_assignment <- declare_assignment(Z = complete_ra(N, m = 50))
my_assignment_2 <- declare_assignment(Z = complete_ra(N, m = 25))
design <- my_model + my_assignment
draw_data(design)
#> ID U Y_Z_0 Y_Z_1 Z
#> 1 001 -1.165441928 -1.165441928 1.376403824 1
#> 2 002 -1.352798718 -1.352798718 3.671323822 0
#> 3 003 -0.874779915 -0.874779915 -0.887107020 0
#> 4 004 0.090114038 0.090114038 4.607775778 1
#> 5 005 0.231475953 0.231475953 1.378260756 0
#> 6 006 1.610101120 1.610101120 5.208371296 0
#> 7 007 0.497654441 0.497654441 2.179134031 1
#> 8 008 0.252513921 0.252513921 -0.605699203 0
#> 9 009 -0.628742353 -0.628742353 1.613680893 0
#> 10 010 -3.566753200 -3.566753200 -2.829034648 1
#> 11 011 -0.071437630 -0.071437630 -3.382854108 1
#> 12 012 0.029053078 0.029053078 2.137556150 0
#> 13 013 -0.706154519 -0.706154519 2.751216861 1
#> 14 014 0.124242090 0.124242090 0.747296543 1
#> 15 015 1.017437248 1.017437248 2.718841130 1
#> 16 016 -0.816834611 -0.816834611 1.143622838 1
#> 17 017 1.949962240 1.949962240 2.213702299 0
#> 18 018 -1.643018745 -1.643018745 -3.041738852 1
#> 19 019 0.833064092 0.833064092 1.621314375 1
#> 20 020 -0.648753639 -0.648753639 0.005633707 0
#> 21 021 0.026895935 0.026895935 0.743233035 0
#> 22 022 -1.189950672 -1.189950672 -1.198519162 0
#> 23 023 -0.725130275 -0.725130275 4.685574672 0
#> 24 024 -1.048264374 -1.048264374 2.258689096 0
#> 25 025 0.783276559 0.783276559 5.398143783 1
#> 26 026 -1.008537713 -1.008537713 -0.117413019 1
#> 27 027 -0.381343920 -0.381343920 2.357952207 0
#> 28 028 0.007446301 0.007446301 2.977915112 0
#> 29 029 0.854762744 0.854762744 3.560863058 0
#> 30 030 0.299232101 0.299232101 2.274426330 1
#> 31 031 2.278110267 2.278110267 4.334577390 1
#> 32 032 1.104595719 1.104595719 5.513613354 1
#> 33 033 0.295484022 0.295484022 2.739387210 0
#> 34 034 -0.903536284 -0.903536284 0.595644013 1
#> 35 035 0.286406369 0.286406369 2.955422089 0
#> 36 036 -0.821061964 -0.821061964 0.445768646 0
#> 37 037 -0.185918278 -0.185918278 3.649008773 0
#> 38 038 -2.005070289 -2.005070289 -0.627512044 0
#> 39 039 -1.873116306 -1.873116306 1.510478159 0
#> 40 040 -0.957408965 -0.957408965 0.791894023 0
#> 41 041 -1.023965594 -1.023965594 1.759240352 1
#> 42 042 -1.847100445 -1.847100445 -0.539860355 0
#> 43 043 -0.524296436 -0.524296436 -1.104229595 1
#> 44 044 1.340435559 1.340435559 4.936045689 1
#> 45 045 -2.041927848 -2.041927848 0.650585043 1
#> 46 046 -1.419603271 -1.419603271 -0.343770064 0
#> 47 047 1.138787202 1.138787202 3.788686171 1
#> 48 048 -1.012946091 -1.012946091 1.426348189 0
#> 49 049 -0.454044867 -0.454044867 0.644863708 1
#> 50 050 -2.108431829 -2.108431829 -3.640504959 0
#> 51 051 -2.664127737 -2.664127737 -0.600936646 1
#> 52 052 1.309704429 1.309704429 1.941620789 0
#> 53 053 -0.711461258 -0.711461258 3.909001905 1
#> 54 054 -0.989722956 -0.989722956 4.522404379 1
#> 55 055 -0.142882350 -0.142882350 4.360266074 1
#> 56 056 0.645792436 0.645792436 5.061580946 1
#> 57 057 1.729133817 1.729133817 4.366582464 0
#> 58 058 -1.492035203 -1.492035203 1.918925178 0
#> 59 059 -0.210294395 -0.210294395 1.633541541 1
#> 60 060 1.182563229 1.182563229 3.465360995 0
#> 61 061 0.321746340 0.321746340 1.589802934 1
#> 62 062 0.478907698 0.478907698 -0.112553281 1
#> 63 063 -1.266856472 -1.266856472 0.822088713 0
#> 64 064 0.125321007 0.125321007 -1.626343231 1
#> 65 065 1.081100376 1.081100376 5.991091196 1
#> 66 066 0.166026780 0.166026780 2.910165491 1
#> 67 067 -0.535105598 -0.535105598 0.598310004 0
#> 68 068 -0.319754049 -0.319754049 4.997786769 1
#> 69 069 1.026193333 1.026193333 1.932861012 0
#> 70 070 -2.278651400 -2.278651400 -1.423062741 1
#> 71 071 0.223181656 0.223181656 -3.488454106 0
#> 72 072 0.044039039 0.044039039 1.961404826 0
#> 73 073 0.337100617 0.337100617 1.987383273 1
#> 74 074 0.504742343 0.504742343 3.958508919 0
#> 75 075 0.748684401 0.748684401 0.852595714 1
#> 76 076 -0.527500626 -0.527500626 3.658791601 0
#> 77 077 -0.100328635 -0.100328635 5.943506891 0
#> 78 078 0.615150196 0.615150196 1.912388697 1
#> 79 079 1.475780258 1.475780258 2.040145060 0
#> 80 080 0.226288882 0.226288882 3.171479110 1
#> 81 081 -1.676659565 -1.676659565 2.150929437 1
#> 82 082 -0.374691872 -0.374691872 1.284738084 1
#> 83 083 0.240988140 0.240988140 4.843838040 1
#> 84 084 -0.170600334 -0.170600334 2.191077190 0
#> 85 085 1.876180897 1.876180897 7.161110466 1
#> 86 086 0.773638654 0.773638654 5.182550727 0
#> 87 087 0.412796831 0.412796831 2.358731062 1
#> 88 088 -0.138855460 -0.138855460 5.412915422 1
#> 89 089 0.251308748 0.251308748 3.861379026 0
#> 90 090 0.545132758 0.545132758 4.066247302 1
#> 91 091 -0.814371866 -0.814371866 1.115217545 0
#> 92 092 -1.393524088 -1.393524088 -1.140973913 0
#> 93 093 1.324467120 1.324467120 4.183787260 0
#> 94 094 0.747653735 0.747653735 0.251787453 0
#> 95 095 -1.191725909 -1.191725909 1.958755117 0
#> 96 096 -0.769044366 -0.769044366 1.575445623 1
#> 97 097 0.120309394 0.120309394 0.391363581 1
#> 98 098 1.493732010 1.493732010 4.042487970 1
#> 99 099 -0.205267391 -0.205267391 0.868373731 0
#> 100 100 -1.310178500 -1.310178500 -1.916724198 0
design_modified <- replace_step(design, 2, my_assignment_2)
draw_data(design)
#> ID U Y_Z_0 Y_Z_1 Z
#> 1 001 -0.189893107 -0.189893107 5.34343076 0
#> 2 002 0.074885221 0.074885221 1.36882852 0
#> 3 003 -0.427555959 -0.427555959 3.45881000 0
#> 4 004 1.132831057 1.132831057 3.64119341 1
#> 5 005 0.861728244 0.861728244 4.45412490 0
#> 6 006 2.383438436 2.383438436 3.94208416 1
#> 7 007 -1.844768119 -1.844768119 2.26759827 1
#> 8 008 0.384144644 0.384144644 1.81094596 1
#> 9 009 2.029345127 2.029345127 4.21422009 1
#> 10 010 -0.035091608 -0.035091608 -0.77358678 1
#> 11 011 1.001548526 1.001548526 2.96667803 1
#> 12 012 0.936941594 0.936941594 4.38641748 0
#> 13 013 1.726541306 1.726541306 2.67039706 1
#> 14 014 -1.200479938 -1.200479938 -2.43868588 0
#> 15 015 -0.067355595 -0.067355595 2.69567986 0
#> 16 016 1.847741588 1.847741588 3.92502062 0
#> 17 017 1.159292475 1.159292475 5.17076462 0
#> 18 018 -1.243009661 -1.243009661 0.83122512 1
#> 19 019 1.296428446 1.296428446 0.80268984 1
#> 20 020 -1.623393778 -1.623393778 0.66679326 1
#> 21 021 -0.766036475 -0.766036475 -2.28261570 1
#> 22 022 -1.095682167 -1.095682167 2.39436671 0
#> 23 023 1.594788540 1.594788540 2.12456588 0
#> 24 024 0.169317594 0.169317594 2.08262324 0
#> 25 025 0.886280585 0.886280585 2.08783049 1
#> 26 026 0.564609955 0.564609955 3.68641437 0
#> 27 027 0.836591824 0.836591824 3.23114301 1
#> 28 028 0.574191638 0.574191638 2.16702303 0
#> 29 029 1.645554192 1.645554192 6.88777788 1
#> 30 030 1.635358903 1.635358903 1.03885267 1
#> 31 031 0.981700774 0.981700774 1.80564103 0
#> 32 032 -1.124199522 -1.124199522 1.02382870 1
#> 33 033 -0.641862586 -0.641862586 -0.53443240 0
#> 34 034 0.134635262 0.134635262 2.40274383 0
#> 35 035 0.748884343 0.748884343 1.21044324 1
#> 36 036 1.685588919 1.685588919 1.03105400 0
#> 37 037 -2.005854480 -2.005854480 -0.57150517 1
#> 38 038 0.161949035 0.161949035 3.99194560 0
#> 39 039 -0.306986153 -0.306986153 1.74393962 1
#> 40 040 -0.559624072 -0.559624072 -0.57637161 0
#> 41 041 -0.673120394 -0.673120394 -0.16175725 1
#> 42 042 0.705895485 0.705895485 2.04731684 0
#> 43 043 0.256464986 0.256464986 1.34669996 0
#> 44 044 0.033362783 0.033362783 1.35430724 1
#> 45 045 -0.236225639 -0.236225639 2.07459084 0
#> 46 046 0.516755836 0.516755836 8.06973117 0
#> 47 047 0.603969920 0.603969920 3.37724303 1
#> 48 048 0.871201887 0.871201887 2.87807934 0
#> 49 049 -1.796000140 -1.796000140 -1.02775159 0
#> 50 050 -1.188547977 -1.188547977 0.66182966 1
#> 51 051 0.521092913 0.521092913 6.27918516 1
#> 52 052 -1.130415412 -1.130415412 2.25357094 1
#> 53 053 0.153468211 0.153468211 1.78622013 0
#> 54 054 -0.571139294 -0.571139294 4.39250880 1
#> 55 055 1.225389454 1.225389454 0.99394257 0
#> 56 056 1.262085877 1.262085877 3.90116176 0
#> 57 057 -0.684075068 -0.684075068 0.05291745 0
#> 58 058 -1.021681746 -1.021681746 -1.13061062 0
#> 59 059 0.663967066 0.663967066 0.75806927 1
#> 60 060 1.462159420 1.462159420 0.95504389 1
#> 61 061 0.236452124 0.236452124 0.42453932 0
#> 62 062 -0.270264874 -0.270264874 -1.55084633 0
#> 63 063 -1.294057330 -1.294057330 -0.60771670 1
#> 64 064 1.267035351 1.267035351 -1.13092243 0
#> 65 065 0.343265132 0.343265132 1.05913756 0
#> 66 066 -1.890053422 -1.890053422 -2.06179735 0
#> 67 067 0.441403259 0.441403259 2.36337263 1
#> 68 068 -1.219032635 -1.219032635 1.99393492 1
#> 69 069 -1.253665941 -1.253665941 1.75650202 0
#> 70 070 -1.505280633 -1.505280633 2.31836557 1
#> 71 071 -0.185938404 -0.185938404 -2.09974898 0
#> 72 072 -0.627410294 -0.627410294 0.83789962 1
#> 73 073 1.388924453 1.388924453 0.39777635 0
#> 74 074 -0.285353322 -0.285353322 4.17793942 1
#> 75 075 -1.215436230 -1.215436230 1.09452556 1
#> 76 076 0.085648431 0.085648431 1.87073149 0
#> 77 077 1.339786955 1.339786955 1.58480573 0
#> 78 078 0.896434653 0.896434653 3.91072965 0
#> 79 079 -0.997826962 -0.997826962 3.50784109 0
#> 80 080 -0.680505962 -0.680505962 2.99211495 1
#> 81 081 -0.690610087 -0.690610087 1.12056640 1
#> 82 082 0.617221316 0.617221316 4.60811404 1
#> 83 083 -1.235647339 -1.235647339 0.52050980 0
#> 84 084 2.065491731 2.065491731 1.86081912 1
#> 85 085 -0.005737503 -0.005737503 2.34998076 1
#> 86 086 0.666144638 0.666144638 0.41894998 1
#> 87 087 1.687651770 1.687651770 1.38192324 0
#> 88 088 0.784519711 0.784519711 1.44207272 1
#> 89 089 0.436561477 0.436561477 -0.34296891 1
#> 90 090 -0.562915551 -0.562915551 0.90800078 0
#> 91 091 1.168115110 1.168115110 4.36497693 0
#> 92 092 0.548787508 0.548787508 5.98086226 1
#> 93 093 -1.141231198 -1.141231198 0.83860021 1
#> 94 094 0.633493920 0.633493920 3.56639124 0
#> 95 095 0.965582753 0.965582753 1.92187234 1
#> 96 096 -0.404741944 -0.404741944 0.64306956 1
#> 97 097 0.160130860 0.160130860 5.41353858 0
#> 98 098 0.328820551 0.328820551 2.81083070 0
#> 99 099 1.095861529 1.095861529 3.73096541 1
#> 100 100 -0.898939032 -0.898939032 0.84234851 1
if (FALSE) { # \dontrun{
design <-
declare_model(
N = 100,
U = rnorm(N),
potential_outcomes(Y ~ 0.20 * Z + U)
) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_assignment(Z = complete_ra(N, m = N/2)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
insert_step(design, declare_sampling(S = complete_rs(N, n = 50)),
after = 1)
# If you are using a design created by a designer, for example from
# the DesignLibrary package, you will not have access to the step
# objects. Instead, you can always use the label of the step.
design <- DesignLibrary::two_arm_designer()
# get the labels for the steps
names(design)
insert_step(design,
declare_sampling(S = complete_rs(N, n = 50)),
after = "potential_outcomes")
} # }
design <-
declare_model(
N = 100,
U = rnorm(N),
potential_outcomes(Y ~ 0.20 * Z + U)
) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_assignment(Z = complete_ra(N, m = N/2)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
delete_step(design, step = 5)
#>
#> Research design declaration summary
#>
#> Step 1 (model): declare_model(N = 100, U = rnorm(N), potential_outcomes(Y ~ 0.2 * Z + U))
#>
#> Step 2 (inquiry): declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) -------------------
#>
#> Step 3 (assignment): declare_assignment(Z = complete_ra(N, m = N/2)) -----------
#>
#> Step 4 (measurement): declare_measurement(Y = reveal_outcomes(Y ~ Z)) ----------
#>
#> Run of the design:
#>
#> inquiry estimand
#> ATE 0.2
#>
design <-
declare_model(
N = 100,
U = rnorm(N),
potential_outcomes(Y ~ 0.20 * Z + U)
) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_assignment(Z = complete_ra(N, m = N/2)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
replace_step(
design,
step = 3,
new_step = declare_assignment(Z = simple_ra(N, prob = 0.5)))
#>
#> Research design declaration summary
#>
#> Step 1 (model): declare_model(N = 100, U = rnorm(N), potential_outcomes(Y ~ 0.2 * Z + U))
#>
#> Step 2 (inquiry): declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) -------------------
#>
#> Step 3 (assignment): declare_assignment(Z = simple_ra(N, prob = 0.5)) ----------
#>
#> Step 4 (measurement): declare_measurement(Y = reveal_outcomes(Y ~ Z)) ----------
#>
#> Step 5 (estimator): declare_estimator(Y ~ Z, inquiry = "ATE") ------------------
#>
#> Run of the design:
#>
#> inquiry estimand estimator term estimate std.error statistic p.value conf.low
#> ATE 0.2 estimator Z 0.259 0.205 1.27 0.208 -0.147
#> conf.high df outcome
#> 0.665 98 Y
#>