Compare two designs

compare_designs(
  design1,
  design2,
  format = "ansi8",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

compare_design_code(
  design1,
  design2,
  format = "ansi256",
  mode = "sidebyside",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

compare_design_summaries(
  design1,
  design2,
  format = "ansi256",
  mode = "sidebyside",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

compare_design_data(
  design1,
  design2,
  format = "ansi256",
  mode = "sidebyside",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

compare_design_estimates(
  design1,
  design2,
  format = "ansi256",
  mode = "auto",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

compare_design_estimands(
  design1,
  design2,
  format = "ansi256",
  mode = "sidebyside",
  pager = "off",
  context = -1L,
  rmd = FALSE
)

Arguments

design1

A design object, typically created using the + operator

design2

A design object, typically created using the + operator

format

Format (in console or HTML) options from diffobj::diffChr

pager

Pager option from diffobj::diffChr

context

Context option from diffobj::diffChr which sets the number of lines around differences that are printed. By default, all lines of the two objects are shown. To show only the lines that are different, set context = 0; to get one line around differences for context, set to 1.

rmd

Set to TRUE use in Rmarkdown HTML output. NB: will not work with LaTeX, Word, or other .Rmd outputs.

mode

Mode options from diffobj::diffChr

Examples

design1 <- declare_population(N = 100, u = rnorm(N)) + declare_potential_outcomes(Y ~ Z + u) + declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0)) + declare_sampling(n = 75) + declare_assignment(m = 50) + reveal_outcomes(Y, Z) + declare_estimator(Y ~ Z, estimand = "ATE") design2 <- declare_population(N = 200, u = rnorm(N)) + declare_potential_outcomes(Y ~ 0.5*Z + u) + declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0)) + declare_sampling(n = 100) + declare_assignment(m = 25) + reveal_outcomes(Y, Z) + declare_estimator(Y ~ Z, model = lm_robust, estimand = "ATE") compare_designs(design1, design2)
#> Loading required namespace: diffobj
#> Research design comparison #> #> #> #> # Compare design code ----------------------------------------------------------- #> #> < design1 > design2 #> @@ 1,14 @@ @@ 1,14 @@ #> p #> opulation population #> < "declare_population(N = 100, u = r > "declare_popula #> : norm(N))" : tion(N = 200, u = rnorm(N))" #> potential #> _outcomes potential_outcomes #> < "declare_potential_outcomes(Y > "declare_potentia #> : ~ Z + u)" : l_outcomes(Y ~ 0.5 * Z + u)" #> #> ATE ATE #> "declare_estimand(ATE = mean(Y_Z_1 - "declare_estimand #> Y_Z_0))" (ATE = mean(Y_Z_1 - Y_Z_0))" #> #> sampling sampling #> < "declare_sampling > #> : (n = 75)" : "declare_sampling(n = 100)" #> a #> ssignment assignment #> < "declare_assignment > #> : (m = 50)" : "declare_assignment(m = 25)" #> #> reveal reveal #> "reveal_outcom #> es(Y, Z)" "reveal_outcomes(Y, Z)" #> #> estimator estimator #> < "declare_estimator(Y ~ Z, estimand = > "declare_estimator(Y ~ Z, model = lm_ #> : \"ATE\")" : robust, estimand = \"ATE\")" #> #> #> # Compare draw_data(design) ----------------------------------------------------- #> #> < str(design1) > str(design2) #> @@ 1,9 @@ @@ 1,9 @@ #> < 'data.frame': 75 obs. of 8 variabl > 'data.frame': 100 obs. of 8 variab #> : es: : les: #> < $ ID : chr "001" "002" > $ ID : chr "004" "005" #> : "004" "005" ... : "007" "008" ... #> < $ u : num -0.294 -0.5 > $ u : num -0.143 0.22 #> : 63 -0.143 0.224 0.404 ... : 4 -2.819 -1.315 1.696 ... #> < $ Y_Z_0 : num -0.294 -0.5 > $ Y_Z_0 : num -0.143 0.22 #> : 63 -0.143 0.224 0.404 ... : 4 -2.819 -1.315 1.696 ... #> < $ Y_Z_1 : num 0.706 0.437 > $ Y_Z_1 : num 0.357 0.724 #> : 0.857 1.224 1.404 ... : -2.319 -0.815 2.196 ... #> < $ S_inclusion_prob: num 0.75 0.75 0 > $ S_inclusion_prob: num 0.5 0.5 0.5 #> : .75 0.75 0.75 0.75 0.75 0.75 0.75 0.7 : 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ... #> : 5 ... ~ #> < $ Z : int 1 1 0 0 1 1 > $ Z : int 1 0 0 0 0 1 #> : 1 0 0 0 ... : 0 1 0 0 ... #> < $ Z_cond_prob : num 0.667 0.667 > $ Z_cond_prob : num 0.25 0.75 0 #> : 0.333 0.333 0.667 ... : .75 0.75 0.75 0.25 0.75 0.25 0.75 0.7 #> ~ : 5 ... #> < $ Y : num 0.706 0.437 > $ Y : num 0.357 0.224 #> : -0.143 0.224 1.404 ... : -2.819 -1.315 1.696 ... #> #> #> # Compare draw_estimands(design) ------------------------------------------------ #> #> < design1 > design2 #> @@ 1,2 @@ @@ 1,2 @@ #> estimand_label estimand estimand_label estimand #> < 1 ATE 1 > 1 ATE 0.5 #> #> #> # Compare draw_estimates(design) ------------------------------------------------ #> #> < design1 #> > design2 #> @@ 1,4 / 1,4 @@ #> estimator_label term estimate std.error statistic p.value conf.low #> < 1 estimator Z 1.023718 0.2279354 4.491265 4.265621e-05 0.5657591 #> > 1 estimator Z 0.6078596 0.2366002 2.569142 0.01170256 0.1383341 #> conf.high df outcome estimand_label #> < 1 1.481678 49.40125 Y ATE #> > 1 1.077385 98 Y ATE
compare_design_code(design1, design2)
#> < design1 > design2 #> @@ 1,14 @@ @@ 1,14 @@ #> p #> opulation population #> < "declare_population(N = 100, u = r > "declare_popula #> : norm(N))" : tion(N = 200, u = rnorm(N))" #> potential #> _outcomes potential_outcomes #> < "declare_potential_outcomes(Y > "declare_potentia #> : ~ Z + u)" : l_outcomes(Y ~ 0.5 * Z + u)" #> #> ATE ATE #> "declare_estimand(ATE = mean(Y_Z_1 - "declare_estimand #> Y_Z_0))" (ATE = mean(Y_Z_1 - Y_Z_0))" #> #> sampling sampling #> < "declare_sampling > #> : (n = 75)" : "declare_sampling(n = 100)" #> a #> ssignment assignment #> < "declare_assignment > #> : (m = 50)" : "declare_assignment(m = 25)" #> #> reveal reveal #> "reveal_outcom #> es(Y, Z)" "reveal_outcomes(Y, Z)" #> #> estimator estimator #> < "declare_estimator(Y ~ Z, estimand = > "declare_estimator(Y ~ Z, model = lm_ #> : \"ATE\")" : robust, estimand = \"ATE\")"
compare_design_summaries(design1, design2)
#> < design1 > design2 #> @@ 1,106 @@ @@ 1,108 @@ #> #> Design Summary Design Summary #> #> < Step 1 (population): declare_populati > Step 1 (population): declare_populati #> : on(N = 100, u = rnorm(N)) ----------- : on(N = 200, u = rnorm(N)) ----------- #> : ------ : ------ #> #> < N = 100 > N = 200 #> #> Added variable: ID Added variable: ID #> N_missing N_unique class N_missing N_unique class #> < 0 100 character > 0 200 character #> #> Added variable: u Added variable: u #> min median mean max sd N_missin min median mean max sd N_missing #> g N_unique N_unique #> < -3.04 0 -0.08 2.5 1.02 > -3.04 -0.02 0.02 2.5 0.98 0 #> : 0 100 : 200 #> #> < Step 2 (potential outcomes): declare_ > Step 2 (potential outcomes): declare_ #> : potential_outcomes(Y ~ Z + u) ------- : potential_outcomes(Y ~ 0.5 * Z + u) - #> : ------ : ------ #> #> < Formula: Y ~ Z + u > Formula: Y ~ 0.5 * Z + u #> #> Added variable: Y_Z_0 Added variable: Y_Z_0 #> min median mean max sd N_missin min median mean max sd N_missing #> g N_unique N_unique #> < -3.04 0 -0.08 2.5 1.02 > -3.04 -0.02 0.02 2.5 0.98 0 #> : 0 100 : 200 #> #> Added variable: Y_Z_1 Added variable: Y_Z_1 #> min median mean max sd N_missing min median mean max sd N_missing #> N_unique N_unique #> < -2.04 1 0.92 3.5 1.02 0 > -2.54 0.48 0.52 3 0.98 0 #> : 100 : 200 #> #> Step 3 (estimand): declare_estimand(A Step 3 (estimand): declare_estimand(A #> TE = mean(Y_Z_1 - Y_Z_0)) ----------- TE = mean(Y_Z_1 - Y_Z_0)) ----------- #> ------ ------ #> #> A single draw of the estimand: A single draw of the estimand: #> estimand_label estimand estimand_label estimand #> < ATE 1 > ATE 0.5 #> #> < Step 4 (sampling): declare_sampling(n > Step 4 (sampling): declare_sampling(n #> : = 75) ------------------------------ : = 100) ----------------------------- #> : ------ : ------ #> #> < N = 75 (25 subtracted) > N = 100 (100 subtracted) #> #> Added variable: S_inclusion_prob Added variable: S_inclusion_prob #> < 0.75 > 0.5 #> < 75 > 100 #> 1.00 1.00 #> #> Altered variable: ID Altered variable: ID #> Before: Before: #> N_missing N_unique class N_missing N_unique class #> < 0 100 character > 0 200 character #> #> After: After: #> N_missing N_unique class N_missing N_unique class #> < 0 75 character > 0 100 character #> #> Altered variable: u Altered variable: u #> Before: Before: #> min median mean max sd N_missin min median mean max sd N_missing #> g N_unique N_unique #> < -3.04 0 -0.08 2.5 1.02 > -3.04 -0.02 0.02 2.5 0.98 0 #> : 0 100 : 200 #> #> After: After: #> min median mean max sd N_missing min median mean max sd N_missing #> N_unique N_unique #> < -3.04 0.14 -0.04 2.5 1 0 > -3.04 0.12 0.01 2.5 0.98 0 #> : 75 : 100 #> #> Altered variable: Y_Z_0 Altered variable: Y_Z_0 #> Before: Before: #> min median mean max sd N_missin min median mean max sd N_missing #> g N_unique N_unique #> < -3.04 0 -0.08 2.5 1.02 > -3.04 -0.02 0.02 2.5 0.98 0 #> : 0 100 : 200 #> #> After: After: #> min median mean max sd N_missing min median mean max sd N_missing #> N_unique N_unique #> < -3.04 0.14 -0.04 2.5 1 0 > -3.04 0.12 0.01 2.5 0.98 0 #> : 75 : 100 #> #> Altered variable: Y_Z_1 Altered variable: Y_Z_1 #> Before: Before: #> min median mean max sd N_missing min median mean max sd N_missing #> N_unique N_unique #> < -2.04 1 0.92 3.5 1.02 0 > -2.54 0.48 0.52 3 0.98 0 #> : 100 : 200 #> #> After: After: #> min median mean max sd N_missing N min median mean max sd N_missing #> _unique N_unique #> < -2.04 1.14 0.96 3.5 1 0 > -2.54 0.62 0.51 3 0.98 0 #> : 75 : 100 #> #> < Step 5 (assignment): declare_assignme > Step 5 (assignment): declare_assignme #> : nt(m = 50) -------------------------- : nt(m = 25) -------------------------- #> : ------ : ------ #> #> Added variable: Z Added variable: Z #> 0 1 0 1 #> < 25 50 > 75 25 #> < 0.33 0.67 > 0.75 0.25 #> #> Added variable: Z_cond_prob Added variable: Z_cond_prob #> < 0.333333333333333 0.666666666666667 > 0.25 0.75 #> < 25 50 > 25 75 #> < 0.33 0.67 > 0.25 0.75 #> #> Step 6 (reveal): reveal_outcomes(Y, Z Step 6 (reveal): reveal_outcomes(Y, Z #> ) ----------------------------------- ) ----------------------------------- #> ------ ------ #> #> Added variable: Y Added variable: Y #> min median mean max sd N_missing min median mean max sd N_missing #> N_unique N_unique #> < -2.04 0.66 0.63 3.5 1.07 0 > -3.04 0.22 0.13 3 1.02 0 #> : 75 : 100 #> #> < Step 7 (estimator): declare_estimator > Step 7 (estimator): declare_estimator #> : (Y ~ Z, estimand = "ATE") ----------- : (Y ~ Z, model = lm_robust, estimand = #> : ------ : "ATE") #> #> Formula: Y ~ Z Formula: Y ~ Z #> ~ > #> ~ > Model: lm_robust #> #> A single draw of the estimator: A single draw of the estimator: #> estimator_label term estimate std.e estimator_label term estimate std.e #> rror statistic p.value conf.low rror statistic p.value conf.low #> < estimator Z 0.7892986 0.212 > estimator Z 0.6078596 0.236 #> : 3301 3.717319 0.0004051111 0.3657276 : 6002 2.569142 0.01170256 0.1383341 #> conf.high df outcome estimand_ conf.high df outcome estimand_label #> label ~ #> < 1.21287 69.14596 Y > 1.077385 98 Y ATE #> : ATE ~ #>
compare_design_data(design1, design2)
#> < str(design1) > str(design2) #> @@ 1,9 @@ @@ 1,9 @@ #> < 'data.frame': 75 obs. of 8 variabl > 'data.frame': 100 obs. of 8 variab #> : es: : les: #> < $ ID : chr "001" "002" > $ ID : chr "004" "005" #> : "003" "004" ... : "007" "008" ... #> < $ u : num -0.561 -0.6 > $ u : num -0.143 0.22 #> : 1.004 -1.237 0.19 ... : 4 -2.819 -1.315 1.696 ... #> < $ Y_Z_0 : num -0.561 -0.6 > $ Y_Z_0 : num -0.143 0.22 #> : 1.004 -1.237 0.19 ... : 4 -2.819 -1.315 1.696 ... #> < $ Y_Z_1 : num 0.439 0.4 2 > $ Y_Z_1 : num 0.357 0.724 #> : .004 -0.237 1.19 ... : -2.319 -0.815 2.196 ... #> < $ S_inclusion_prob: num 0.75 0.75 0 > $ S_inclusion_prob: num 0.5 0.5 0.5 #> : .75 0.75 0.75 0.75 0.75 0.75 0.75 0.7 : 0.5 0.5 0.5 0.5 0.5 0.5 0.5 ... #> : 5 ... ~ #> < $ Z : int 1 1 0 0 1 1 > $ Z : int 1 0 0 0 0 1 #> : 1 1 1 1 ... : 0 1 0 0 ... #> < $ Z_cond_prob : num 0.667 0.667 > $ Z_cond_prob : num 0.25 0.75 0 #> : 0.333 0.333 0.667 ... : .75 0.75 0.75 0.25 0.75 0.25 0.75 0.7 #> ~ : 5 ... #> < $ Y : num 0.439 0.4 1 > $ Y : num 0.357 0.224 #> : .004 -1.237 1.19 ... : -2.819 -1.315 1.696 ...
compare_design_estimates(design1, design2)
#> < design1 #> > design2 #> @@ 1,4 / 1,4 @@ #> estimator_label term estimate std.error statistic p.value conf.low #> < 1 estimator Z 1.023718 0.2279354 4.491265 4.265621e-05 0.5657591 #> > 1 estimator Z 0.6078596 0.2366002 2.569142 0.01170256 0.1383341 #> conf.high df outcome estimand_label #> < 1 1.481678 49.40125 Y ATE #> > 1 1.077385 98 Y ATE
compare_design_estimands(design1, design2)
#> < design1 > design2 #> @@ 1,2 @@ @@ 1,2 @@ #> estimand_label estimand estimand_label estimand #> < 1 ATE 1 > 1 ATE 0.5