Compare two designs
Usage
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_inquiries(
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, setcontext = 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_model(N = 100, u = rnorm(N), potential_outcomes(Y ~ Z + u)) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_sampling(S = complete_rs(N, n = 75)) +
declare_assignment(Z = complete_ra(N, m = 50)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
design2 <- declare_model(N = 200, U = rnorm(N),
potential_outcomes(Y ~ 0.5*Z + U)) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_sampling(S = complete_rs(N, n = 100)) +
declare_assignment(Z = complete_ra(N, m = 25)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, .method = lm_robust, inquiry = "ATE")
compare_designs(design1, design2)
#> Loading required namespace: diffobj
#> Research design comparison
#>
#>
#>
#> # Compare design code -----------------------------------------------------------
#>
#> < str(design1) > str(design2)
#> @@ 1,2 @@ @@ 1,2 @@
#> < Named chr [1:6] "declare_model(N = 1 > Named chr [1:6] "declare_model(N = 2
#> : 00, u = rnorm(N), potential_outcomes( : 00, U = rnorm(N), potential_outcomes(
#> : Y ~ Z + u))" ... : Y ~ 0.5 * Z + U))" ...
#> - attr(*, "names")= chr [1:6] "model - attr(*, "names")= chr [1:6] "model
#> " "ATE" "sampling" "assignment" ... " "ATE" "sampling" "assignment" ...
#>
#>
#> # Compare draw_data(design) -----------------------------------------------------
#>
#> < str(design1) > str(design2)
#> @@ 1,8 @@ @@ 1,8 @@
#> < 'data.frame': 75 obs. of 7 variabl > 'data.frame': 100 obs. of 7 variab
#> : es: : les:
#> < $ ID : chr "001" "002" "003" "004 > $ ID : chr "001" "002" "006" "007
#> : " ... : " ...
#> < $ u : num -0.294 -0.563 0.378 -0 > $ U : num -0.294 -0.563 0.404 -2
#> : .143 0.404 ... : .819 1.401 ...
#> < $ Y_Z_0: num -0.294 -0.563 0.378 -0 > $ Y_Z_0: num -0.294 -0.563 0.404 -2
#> : .143 0.404 ... : .819 1.401 ...
#> < $ Y_Z_1: num 0.706 0.437 1.378 0.85 > $ Y_Z_1: num 0.2057 -0.0632 0.9043
#> : 7 1.404 ... : -2.319 1.9014 ...
#> $ S : num 1 1 1 1 1 1 1 1 1 1 .. $ S : num 1 1 1 1 1 1 1 1 1 1 ..
#> . .
#> < $ Z : int 1 1 0 0 1 1 1 0 0 0 .. > $ Z : int 1 0 0 0 0 1 0 1 0 0 ..
#> : . : .
#> < $ Y : num 0.706 0.437 0.378 -0.1 > $ Y : num 0.206 -0.563 0.404 -2.
#> : 43 1.404 ... : 819 1.401 ...
#>
#>
#> # Compare draw_estimands(design) ------------------------------------------------
#>
#> < design1 > design2
#> @@ 1,2 @@ @@ 1,2 @@
#> inquiry estimand inquiry estimand
#> < 1 ATE 1 > 1 ATE 0.5
#>
#>
#> # Compare draw_estimates(design) ------------------------------------------------
#>
#> < design1
#> > design2
#> @@ 1,4 / 1,4 @@
#> estimator term estimate std.error statistic p.value conf.low
#> < 1 estimator Z 1.149296 0.2347213 4.896428 5.679152e-06 0.6814971
#> > 1 estimator Z 0.770971 0.216545 3.560327 0.0005733527 0.3412444
#> conf.high df outcome inquiry
#> < 1 1.617095 73 Y ATE
#> > 1 1.200698 98 Y ATE
compare_design_code(design1, design2)
#> < str(design1) > str(design2)
#> @@ 1,2 @@ @@ 1,2 @@
#> < Named chr [1:6] "declare_model(N = 1 > Named chr [1:6] "declare_model(N = 2
#> : 00, u = rnorm(N), potential_outcomes( : 00, U = rnorm(N), potential_outcomes(
#> : Y ~ Z + u))" ... : Y ~ 0.5 * Z + U))" ...
#> - attr(*, "names")= chr [1:6] "model - attr(*, "names")= chr [1:6] "model
#> " "ATE" "sampling" "assignment" ... " "ATE" "sampling" "assignment" ...
compare_design_summaries(design1, design2)
#> < design1 > design2
#> @@ 1,97 @@ @@ 1,99 @@
#>
#> Research design declaration summary Research design declaration summary
#>
#> < Step 1 (model): declare_model(N = 100 > Step 1 (model): declare_model(N = 200
#> : , u = rnorm(N), potential_outcomes(Y : , U = rnorm(N), potential_outcomes(Y
#> : ~ Z + u)) : ~ 0.5 * Z + U))
#>
#> < 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
#>
#> 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 2 (inquiry): declare_inquiry(ATE Step 2 (inquiry): declare_inquiry(ATE
#> = mean(Y_Z_1 - Y_Z_0)) ------------- = mean(Y_Z_1 - Y_Z_0)) -------------
#> ------ ------
#>
#> A single draw of the inquiry: A single draw of the inquiry:
#> inquiry estimand inquiry estimand
#> < ATE 1 > ATE 0.5
#>
#> < Step 3 (sampling): declare_sampling(S > Step 3 (sampling): declare_sampling(S
#> : = complete_rs(N, n = 75)) ---------- : = complete_rs(N, n = 100)) ---------
#> : ------ : ------
#>
#> < N = 75 (25 subtracted) > N = 100 (100 subtracted)
#>
#> Added variable: S Added variable: S
#> 1 1
#> < 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_missin min median mean max sd N_missing
#> g N_unique N_unique
#> < -3.04 0.14 -0.03 2.5 1.06 > -2.82 -0.04 0.02 2.5 0.93 0
#> : 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_missin min median mean max sd N_missing
#> g N_unique N_unique
#> < -3.04 0.14 -0.03 2.5 1.06 > -2.82 -0.04 0.02 2.5 0.93 0
#> : 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 min median mean max sd N_missing
#> N_unique N_unique
#> < -2.04 1.14 0.97 3.5 1.06 0 > -2.32 0.46 0.52 3 0.93 0
#> : 75 : 100
#>
#> < Step 4 (assignment): declare_assignme > Step 4 (assignment): declare_assignme
#> : nt(Z = complete_ra(N, m = 50)) ------ : nt(Z = complete_ra(N, m = 25)) ------
#> : ------ : ------
#>
#> Added variable: Z Added variable: Z
#> 0 1 0 1
#> < 25 50 > 75 25
#> < 0.33 0.67 > 0.75 0.25
#>
#> Step 5 (measurement): declare_measure Step 5 (measurement): declare_measure
#> ment(Y = reveal_outcomes(Y ~ Z)) ---- ment(Y = 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.67 0.64 3.5 1.07 0 > -2.82 0.17 0.15 3 0.98 0
#> : 75 : 100
#>
#> < Step 6 (estimator): declare_estimator > Step 6 (estimator): declare_estimator
#> : (Y ~ Z, inquiry = "ATE") ------------ : (Y ~ Z, .method = lm_robust, inquiry
#> : ------ : = "ATE")
#>
#> Formula: Y ~ Z Formula: Y ~ Z
#> ~ >
#> ~ > Method: lm_robust
#>
#> A single draw of the estimator: A single draw of the estimator:
#> < estimator term estimate std.error st > estimator term estimate std.error st
#> : atistic p.value conf.low conf.hi : atistic p.value conf.low conf.h
#> : gh df : igh
#> < estimator Z 0.545746 0.2263475 2 > estimator Z 0.770971 0.216545 3
#> : .411097 0.01842188 0.09463598 0.9968 : .560327 0.0005733527 0.3412444 1.200
#> : 56 73 : 698
#> < outcome inquiry > df outcome inquiry
#> < Y ATE > 98 Y ATE
#>
compare_design_data(design1, design2)
#> < str(design1) > str(design2)
#> @@ 1,8 @@ @@ 1,8 @@
#> < 'data.frame': 75 obs. of 7 variabl > 'data.frame': 100 obs. of 7 variab
#> : es: : les:
#> < $ ID : chr "001" "002" "003" "004 > $ ID : chr "001" "002" "006" "007
#> : " ... : " ...
#> < $ u : num -0.6 1.004 -1.2372 -1. > $ U : num -0.294 -0.563 0.404 -2
#> : 1521 0.0362 ... : .819 1.401 ...
#> < $ Y_Z_0: num -0.6 1.004 -1.2372 -1. > $ Y_Z_0: num -0.294 -0.563 0.404 -2
#> : 1521 0.0362 ... : .819 1.401 ...
#> < $ Y_Z_1: num 0.4 2.004 -0.237 -0.15 > $ Y_Z_1: num 0.2057 -0.0632 0.9043
#> : 2 1.036 ... : -2.319 1.9014 ...
#> $ S : num 1 1 1 1 1 1 1 1 1 1 .. $ S : num 1 1 1 1 1 1 1 1 1 1 ..
#> . .
#> < $ Z : int 1 1 0 0 1 1 1 1 1 1 .. > $ Z : int 1 0 0 0 0 1 0 1 0 0 ..
#> : . : .
#> < $ Y : num 0.4 2 -1.24 -1.15 1.04 > $ Y : num 0.206 -0.563 0.404 -2.
#> : ... : 819 1.401 ...
compare_design_estimates(design1, design2)
#> < design1
#> > design2
#> @@ 1,4 / 1,4 @@
#> estimator term estimate std.error statistic p.value conf.low
#> < 1 estimator Z 1.149296 0.2347213 4.896428 5.679152e-06 0.6814971
#> > 1 estimator Z 0.770971 0.216545 3.560327 0.0005733527 0.3412444
#> conf.high df outcome inquiry
#> < 1 1.617095 73 Y ATE
#> > 1 1.200698 98 Y ATE
compare_design_inquiries(design1, design2)
#> < design1 > design2
#> @@ 1,2 @@ @@ 1,2 @@
#> inquiry estimand inquiry estimand
#> < 1 ATE 1 > 1 ATE 0.5