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_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, 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_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, model = 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" "004" "005  >  $ ID   : chr  "001" "002" "003" "005
#> : " ...                                  : " ...                                
#> <  $ u    : num  0.622 0.957 -1.26 -0.7  >  $ U    : num  0.622 0.957 -1.233 -0.
#> : 09 -1.011 ...                          : 709 0.683 ...                        
#> <  $ Y_Z_0: num  0.622 0.957 -1.26 -0.7  >  $ Y_Z_0: num  0.622 0.957 -1.233 -0.
#> : 09 -1.011 ...                          : 709 0.683 ...                        
#> <  $ Y_Z_1: num  1.622 1.9575 -0.2598 0  >  $ Y_Z_1: num  1.122 1.457 -0.733 -0.
#> : .2909 -0.0109 ...                      : 209 1.183 ...                        
#>    $ 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 1 1 1 1 1 1 1 1 ..  >  $ Z    : int  0 0 1 0 0 0 0 0 0 0 ..
#> : .                                      : .                                    
#> <  $ Y    : num  1.622 1.9575 -0.2598 0  >  $ Y    : num  0.622 0.957 -0.733 -0.
#> : .2909 -0.0109 ...                      : 709 0.683 ...                        
#> 
#> 
#> # 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        
#> >   estimator term estimate std.error statistic    p.value   conf.low conf.high
#> < 1 estimator    Z 0.8951884 0.1889807  4.736931 1.040763e-05 0.5185505        
#> > 1 estimator    Z 0.550775 0.2439062  2.258143 0.02615435 0.06675111  1.034799
#> <   conf.high df outcome inquiry                                               
#> >   df outcome inquiry                                                         
#> < 1  1.271826 73       Y     ATE                                               
#> > 1 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 @@                             
#>                                                                                 
#>   Design Summary                           Design 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_missin
#>   g N_unique                               g N_unique                           
#> <  -1.86  -0.06 0.04 1.89 0.91           >  -2.11  -0.06 0.05 2.95 0.93         
#> : 0      100                             : 0      200                           
#>                                                                                 
#>   Added variable: Y_Z_0                    Added variable: Y_Z_0                
#>      min median mean  max   sd N_missin       min median mean  max   sd N_missin
#>   g N_unique                               g N_unique                           
#> <  -1.86  -0.06 0.04 1.89 0.91           >  -2.11  -0.06 0.05 2.95 0.93         
#> : 0      100                             : 0      200                           
#>                                                                                 
#>   Added variable: Y_Z_1                    Added variable: Y_Z_1                
#>      min median mean  max   sd N_missin       min median mean  max   sd N_missin
#>   g N_unique                               g N_unique                           
#> <  -0.86   0.94 1.04 2.89 0.91           >  -1.61   0.44 0.55 3.45 0.93         
#> : 0      100                             : 0      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_missin
#>   g N_unique                               g N_unique                           
#> <  -1.86  -0.06 0.04 1.89 0.91           >  -2.11  -0.06 0.05 2.95 0.93         
#> : 0      100                             : 0      200                           
#>                                                                                 
#>     After:                                   After:                             
#>      min median mean  max   sd N_missin       min median  mean  max   sd N_missi
#>   g N_unique                               ng N_unique                          
#> <  -1.86  -0.06 0.03 1.89 0.93           >  -2.11  -0.21 -0.08 2.75 0.94        
#> : 0       75                             :  0      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_missin
#>   g N_unique                               g N_unique                           
#> <  -1.86  -0.06 0.04 1.89 0.91           >  -2.11  -0.06 0.05 2.95 0.93         
#> : 0      100                             : 0      200                           
#>                                                                                 
#>     After:                                   After:                             
#>      min median mean  max   sd N_missin       min median  mean  max   sd N_missi
#>   g N_unique                               ng N_unique                          
#> <  -1.86  -0.06 0.03 1.89 0.93           >  -2.11  -0.21 -0.08 2.75 0.94        
#> : 0       75                             :  0      100                          
#>                                                                                 
#>   Altered variable: Y_Z_1                  Altered variable: Y_Z_1              
#>     Before:                                  Before:                            
#>      min median mean  max   sd N_missin       min median mean  max   sd N_missin
#>   g N_unique                               g N_unique                           
#> <  -0.86   0.94 1.04 2.89 0.91           >  -1.61   0.44 0.55 3.45 0.93         
#> : 0      100                             : 0      200                           
#>                                                                                 
#>     After:                                   After:                             
#>      min median mean  max   sd N_missin       min median mean  max   sd N_missin
#>   g N_unique                               g N_unique                           
#> <  -0.86   0.94 1.03 2.89 0.93           >  -1.61   0.29 0.42 3.25 0.94         
#> : 0       75                             : 0      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_missin       min median mean  max   sd N_missin
#>   g N_unique                               g N_unique                           
#> <  -1.39   0.74 0.69 2.89 0.95           >  -1.86  -0.04 0.05 3.25 0.97         
#> : 0       75                             : 0      100                           
#>                                                                                 
#> < Step 6 (estimator): declare_estimator  > Step 6 (estimator): declare_estimator
#> : (Y ~ Z, inquiry = "ATE") ------------  : (Y ~ Z, model = lm_robust, inquiry = 
#> : ------                                 : "ATE")                               
#>                                                                                 
#>   Formula: Y ~ Z                           Formula: Y ~ Z                       
#> ~                                        >                                      
#> ~                                        > Model:  lm_robust                    
#>                                                                                 
#>   A single draw of the estimator:          A single draw of the estimator:      
#>    estimator term  estimate std.error s     estimator term estimate std.error st
#>   tatistic    p.value  conf.low conf.hi    atistic    p.value   conf.low conf.hi
#>   gh df                                    gh df                                
#> <  estimator    Z 0.6047391 0.2313945    >  estimator    Z 0.550775 0.2439062  2
#> : 2.613455 0.01087875 0.1435706  1.0659  : .258143 0.02615435 0.06675111  1.0347
#> : 08 73                                  : 99 98                                
#>    outcome inquiry                          outcome inquiry                     
#>          Y     ATE                                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" "003" "005
#> : " ...                                  : " ...                                
#> <  $ u    : num  0.4298 0.9584 -0.0161   >  $ U    : num  0.622 0.957 -1.233 -0.
#> : 1.93 0.9866 ...                        : 709 0.683 ...                        
#> <  $ Y_Z_0: num  0.4298 0.9584 -0.0161   >  $ Y_Z_0: num  0.622 0.957 -1.233 -0.
#> : 1.93 0.9866 ...                        : 709 0.683 ...                        
#> <  $ Y_Z_1: num  1.43 1.958 0.984 2.93   >  $ Y_Z_1: num  1.122 1.457 -0.733 -0.
#> : 1.987 ...                              : 209 1.183 ...                        
#>    $ 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 1 1 0 1 1 0 1 1 ..  >  $ Z    : int  0 0 1 0 0 0 0 0 0 0 ..
#> : .                                      : .                                    
#> <  $ Y    : num  1.43 1.958 0.984 2.93   >  $ Y    : num  0.622 0.957 -0.733 -0.
#> : 0.987 ...                              : 709 0.683 ...                        
 compare_design_estimates(design1, design2)
#> < design1                                                                      
#> > design2                                                                      
#> @@ 1,4 / 1,4 @@                                                                
#> <   estimator term  estimate std.error statistic      p.value  conf.low        
#> >   estimator term estimate std.error statistic    p.value   conf.low conf.high
#> < 1 estimator    Z 0.8951884 0.1889807  4.736931 1.040763e-05 0.5185505        
#> > 1 estimator    Z 0.550775 0.2439062  2.258143 0.02615435 0.06675111  1.034799
#> <   conf.high df outcome inquiry                                               
#> >   df outcome inquiry                                                         
#> < 1  1.271826 73       Y     ATE                                               
#> > 1 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