- using R version 4.3.3 (2024-02-29)
- using platform: x86_64-pc-linux-gnu (64-bit)
- R was compiled by
gcc-13 (Debian 13.2.0-13) 13.2.0
GNU Fortran (Debian 13.2.0-13) 13.2.0
- running under: Debian GNU/Linux trixie/sid
- using session charset: UTF-8
- checking for file ‘DeclareDesign/DESCRIPTION’ ... OK
- this is package ‘DeclareDesign’ version ‘1.0.8’
- package encoding: UTF-8
- checking package namespace information ... OK
- checking package dependencies ... NOTE
Package suggested but not available for checking: ‘margins’
- checking if this is a source package ... OK
- checking if there is a namespace ... OK
- checking for executable files ... OK
- checking for hidden files and directories ... OK
- checking for portable file names ... OK
- checking for sufficient/correct file permissions ... OK
- checking whether package ‘DeclareDesign’ can be installed ... OK
See the install log for details.
- checking package directory ... OK
- checking for future file timestamps ... OK
- checking DESCRIPTION meta-information ... OK
- checking top-level files ... OK
- checking for left-over files ... OK
- checking index information ... OK
- checking package subdirectories ... OK
- checking R files for non-ASCII characters ... OK
- checking R files for syntax errors ... OK
- checking whether the package can be loaded ... [3s/4s] OK
- checking whether the package can be loaded with stated dependencies ... [3s/3s] OK
- checking whether the package can be unloaded cleanly ... [3s/4s] OK
- checking whether the namespace can be loaded with stated dependencies ... [3s/4s] OK
- checking whether the namespace can be unloaded cleanly ... [3s/4s] OK
- checking loading without being on the library search path ... [1s/1s] OK
- checking use of S3 registration ... OK
- checking dependencies in R code ... OK
- checking S3 generic/method consistency ... OK
- checking replacement functions ... OK
- checking foreign function calls ... OK
- checking R code for possible problems ... [28s/34s] OK
- checking Rd files ... [1s/1s] OK
- checking Rd metadata ... OK
- checking Rd line widths ... OK
- checking Rd cross-references ... OK
- checking for missing documentation entries ... OK
- checking for code/documentation mismatches ... OK
- checking Rd \usage sections ... OK
- checking Rd contents ... OK
- checking for unstated dependencies in examples ... OK
- checking examples ... [10s/11s] ERROR
Running examples in ‘DeclareDesign-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: declare_estimator
> ### Title: Declare estimator
> ### Aliases: declare_estimator declare_estimators label_estimator
> ### method_handler
>
> ### ** Examples
>
>
> # Setup for examples
> design <-
+ declare_model(
+ N = 500,
+ gender = rbinom(N, 1, 0.5),
+ U = rnorm(N, sd = 0.25),
+ potential_outcomes(Y ~ rbinom(
+ N, 1, prob = pnorm(0.2 * Z + 0.2 * gender + 0.1 * Z * gender + U)
+ ))
+ ) +
+ declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
+ declare_sampling(S = complete_rs(N = N, n = 200)) +
+ declare_assignment(Z = complete_ra(N = N, m = 100)) +
+ declare_measurement(Y = reveal_outcomes(Y ~ Z))
>
> run_design(design)
inquiry estimand
1 ATE 0.138
>
> # default estimator is lm_robust with tidy summary
> design_0 <-
+ design +
+ declare_estimator(Y ~ Z, inquiry = "ATE")
>
> run_design(design_0)
inquiry estimand estimator term estimate std.error statistic p.value
1 ATE 0.082 estimator Z 0.01 0.07025926 0.14233 0.8869641
conf.low conf.high df outcome
1 -0.1285525 0.1485525 198 Y
>
> # Linear regression using lm_robust and tidy summary
> design_1 <-
+ design +
+ declare_estimator(
+ formula = Y ~ Z,
+ .method = lm_robust,
+ .summary = tidy,
+ term = "Z",
+ inquiry = "ATE",
+ label = "lm_no_controls"
+ )
>
> run_design(design_1)
inquiry estimand term estimator estimate std.error statistic p.value
1 ATE 0.106 Z lm_no_controls 0.01 0.06842381 0.146148 0.8839533
conf.low conf.high df outcome
1 -0.124933 0.144933 198 Y
>
> # Use glance summary function to view model fit statistics
> design_2 <-
+ design +
+ declare_estimator(.method = lm_robust,
+ formula = Y ~ Z,
+ .summary = glance)
>
> run_design(design_2)
inquiry estimand estimator r.squared adj.r.squared statistic p.value
1 ATE 0.062 estimator 0.00490049 -0.0001252651 0.9750754 0.3246228
df.residual nobs se_type
1 198 200 HC2
>
> # Use declare_estimator to implement custom answer strategies
> my_estimator <- function(data) {
+ data.frame(estimate = mean(data$Y))
+ }
>
> design_3 <-
+ design +
+ declare_inquiry(Y_bar = mean(Y)) +
+ declare_estimator(handler = label_estimator(my_estimator),
+ label = "mean",
+ inquiry = "Y_bar")
>
> run_design(design_3)
inquiry estimand estimator estimate
1 Y_bar 0.570 mean 0.57
2 ATE 0.136 <NA> NA
>
> # Use `term` to select particular coefficients
> design_4 <-
+ design +
+ declare_inquiry(difference_in_cates = mean(Y_Z_1[gender == 1] - Y_Z_0[gender == 1]) -
+ mean(Y_Z_1[gender == 0] - Y_Z_0[gender == 0])) +
+ declare_estimator(Y ~ Z * gender,
+ term = "Z:gender",
+ inquiry = "difference_in_cates",
+ .method = lm_robust)
>
> run_design(design_4)
inquiry estimand term estimator estimate std.error
1 difference_in_cates 0.1443609 Z:gender estimator 0.1966622 0.1381796
2 ATE 0.1180000 <NA> <NA> NA NA
statistic p.value conf.low conf.high df outcome
1 1.423236 0.1562576 -0.07584754 0.469172 196 Y
2 NA NA NA NA NA <NA>
>
> # Use glm from base R
> design_5 <-
+ design +
+ declare_estimator(Y ~ Z + gender,
+ family = "gaussian",
+ inquiry = "ATE",
+ .method = glm)
>
> run_design(design_5)
inquiry estimand estimator term estimate std.error statistic p.value
1 ATE 0.074 estimator Z 0.07 0.07 1 0.3185372
conf.low conf.high
1 -0.06719748 0.2071975
>
> # If we use logit, we'll need to estimate the average marginal effect with
> # margins::margins. We wrap this up in function we'll pass to model_summary
>
> library(margins) # for margins
Error in library(margins) : there is no package called ‘margins’
Execution halted
- checking for unstated dependencies in ‘tests’ ... OK
- checking tests ... [128s/139s] OK
Running ‘testthat.R’ [127s/139s]
- checking PDF version of manual ... [7s/8s] OK
- checking HTML version of manual ... [2s/3s] OK
- checking for non-standard things in the check directory ... OK
- DONE
Status: 1 ERROR, 1 NOTE