Declare an Estimator

declare_estimator(..., estimator_function = estimatr::difference_in_means,
  estimand = NULL, label = my_estimator)

Arguments

...

Arguments to the estimand function. For example, you could specify the formula for your estimator, i.e., formula = Y ~ Z + age.

estimator_function

A function that takes a data.frame as an argument and returns a data.frame with the estimates, summary statistics (i.e., standard error, p-value, and confidence interval) and a label. By default, the estimator function is the difference_in_means function from the estimatr package.

estimand

An estimand object created using declare_estimand. Estimates from this estimator function will be associated with the estimand, for example for calculating the bias and coverage of the estimator.

label

An optional label to name the estimator, such as DIM.

Value

a function that accepts a data.frame as an argument and returns a data.frame containing the value of the estimator and associated statistics.

Examples

my_population <- declare_population(N = 100) my_potential_outcomes <- declare_potential_outcomes( formula = Y ~ .25 * Z, condition_names = c(0, 1)) my_estimand <- declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0)) my_assignment <- declare_assignment(m = 50) design <- declare_design( my_population, my_potential_outcomes, my_estimand, my_assignment, reveal_outcomes ) df <- draw_data(design) my_estimator_dim <- declare_estimator(Y ~ Z, estimand = my_estimand) my_estimator_dim(df)
#> estimator_label est se p ci_lower ci_upper df estimand_label #> 1 my_estimator 0.25 0 0 0.25 0.25 98 ATE
# Use the linear regression (lm) function # with robust standard errors from the estimatr package my_estimator_lm <- declare_estimator(Y ~ Z, estimator_function = estimatr::lm_robust, coefficient_name = "Z", estimand = my_estimand) my_estimator_lm(df)
#> estimator_label variable_names est se p ci_lower ci_upper estimand_label #> 2 my_estimator Z 0.25 0 0 0.25 0.25 ATE
# Use a custom estimator function my_estimator_function <- function(formula, data){ data.frame(est = with(data, mean(Y))) } my_estimator_custom <- declare_estimator(Y ~ Z, estimator_function = my_estimator_function, estimand = my_estimand) my_estimator_custom(df)
#> estimator_label est estimand_label #> 1 my_estimator 0.125 ATE