Last updated on 2025-12-28 01:48:36 CET.
| Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
|---|---|---|---|---|---|---|
| r-devel-linux-x86_64-debian-clang | 1.1.0 | 6.81 | 218.34 | 225.15 | OK | |
| r-devel-linux-x86_64-debian-gcc | 1.1.0 | 4.91 | 142.23 | 147.14 | OK | |
| r-devel-linux-x86_64-fedora-clang | 1.1.0 | 12.00 | 376.86 | 388.86 | OK | |
| r-devel-linux-x86_64-fedora-gcc | 1.1.0 | 12.00 | 393.06 | 405.06 | OK | |
| r-devel-windows-x86_64 | 1.1.0 | 11.00 | 194.00 | 205.00 | ERROR | |
| r-patched-linux-x86_64 | 1.1.0 | 7.82 | 204.81 | 212.63 | OK | |
| r-release-linux-x86_64 | 1.1.0 | 6.90 | 202.94 | 209.84 | OK | |
| r-release-macos-arm64 | 1.1.0 | OK | ||||
| r-release-macos-x86_64 | 1.1.0 | 8.00 | 200.00 | 208.00 | OK | |
| r-release-windows-x86_64 | 1.1.0 | 11.00 | 204.00 | 215.00 | OK | |
| r-oldrel-macos-arm64 | 1.1.0 | OK | ||||
| r-oldrel-macos-x86_64 | 1.1.0 | 8.00 | 199.00 | 207.00 | OK | |
| r-oldrel-windows-x86_64 | 1.1.0 | 15.00 | 289.00 | 304.00 | OK |
Version: 1.1.0
Check: examples
Result: ERROR
Running examples in 'DeclareDesign-Ex.R' failed
The error most likely occurred in:
> ### 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
>
> # Custom answer strategies
> # A custom estimator should take data as an argument and return a data.frame
> # with columns such as "estimate", "std.error", "p.value", "conf.low", "conf.high"
> my_estimator <- function(data) {
+ data.frame(estimate = mean(data$Y))
+ }
>
> # Add a custom estimator to the design, wrapping it in `label_estimator()`
> # in order to pass label and inquiry arguments
>
> 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>
>
> if(require("broom")) {
+
+ # Use glm from base R
+ design_5 <-
+ design +
+ declare_estimator(Y ~ Z + gender,
+ family = "gaussian",
+ inquiry = "ATE",
+ .method = glm)
+
+ run_design(design_5)
+
+ # If we use logit, we'll need to estimate the average marginal effect with
+ # marginaleffects::avg_slopes. We wrap this up in a function we'll pass to
+ # .summary.
+
+ if(require("marginaleffects")) {
+
+ library(marginaleffects) # for predictions
+ library(broom) # for tidy
+
+ tidy_avg_slopes <- function(x) {
+ tidy(avg_slopes(x))
+ }
+
+ design_6 <-
+ design +
+ declare_estimator(
+ Y ~ Z + gender,
+ .method = glm,
+ family = binomial("logit"),
+ .summary = tidy_avg_slopes,
+ term = "Z"
+ )
+
+ run_design(design_6)
+
+ # Multiple estimators for one inquiry
+
+ design_7 <-
+ design +
+ declare_estimator(Y ~ Z,
+ .method = lm_robust,
+ inquiry = "ATE",
+ label = "OLS") +
+ declare_estimator(
+ Y ~ Z + gender,
+ .method = glm,
+ family = binomial("logit"),
+ .summary = tidy_avg_slopes,
+ inquiry = "ATE",
+ term = "Z",
+ label = "logit"
+ )
+
+ run_design(design_7)
+
+ }
+
+ }
Loading required package: broom
Loading required package: marginaleffects
Error: Error in step 6 (estimator):
Error in `[.data.table`(out, , `:=`(tmp_idx, seq_len(.N)), by = tmp): attempt access index 11/11 in VECTOR_ELT
Execution halted
Flavor: r-devel-windows-x86_64
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.