Declare an Estimator

declare_estimator(..., model = estimatr::difference_in_means,
  estimator_function = NULL, coefficient_name = Z, 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.

model

A model function, e.g. lm or glm. If model is specified, the estimator_function argument is ignored.By default, the model is the difference_in_means function from the estimatr package.

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.

coefficient_name

A character vector of coefficients that represent quantities of interest, i.e. Z. Only relevant when a model is chosen or for some estimator_function's such as difference_in_means and lm_robust.

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.

Custom Estimators

estimator_functions implementations should be tidy (accept and return a data.frame) model implementations should at the miminum provide S3 methods for summary and confint.

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 coefficient_name est se p ci_lower ci_upper estimand_label #> 1 my_estimator Z 0.25 0 0 0.25 0.25 ATE
# Use the linear regression (lm) function # with robust standard errors from the estimatr package my_estimator_lm <- declare_estimator(Y ~ Z, model = estimatr::lm_robust, coefficient_name = "Z", estimand = my_estimand) my_estimator_lm(df)
#> estimator_label coefficient_name est se p ci_lower ci_upper estimand_label #> 1 my_estimator Z 0.25 0 0 0.25 0.25 ATE
# Use R's built-in lm function via model estimator_lm <- declare_estimator(Y ~ Z, model = lm) # Run a probit regression using glm via model estimator_probit <- declare_estimator( Y ~ Z, model = glm, family = binomial(link = "probit"), coefficient_name = "Z" ) # 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