Declare an Estimator tidy_estimator takes an untidy estimation function, and returns a tidy handler which accepts standard labelling options.

declare_estimator(..., handler = estimator_handler, label = "my_estimator")

tidy_estimator(estimator_function)

model_handler(data, ..., model = estimatr::difference_in_means,
  coefficient_name = Z)

estimator_handler(data, ..., estimand = NULL, label)

Arguments

...

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

handler

the handler function

label

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

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.

data

a data.frame

model

A model function, e.g. lm or glm. By default, the model is the difference_in_means function from the estimatr package.

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

a declare_estimand step object, or a character label, or a list of either

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, conditions = 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 NaN NaN NaN 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 #> 1 my_estimator Z 0.25 2.021803e-17 0 0.25 0.25 #> estimand_label #> 1 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(data){ data.frame(est = with(data, mean(Y))) } my_estimator_custom <- declare_estimator(handler = tidy_estimator(my_estimator_function), estimand = my_estimand) my_estimator_custom(df)
#> estimator_label est estimand_label #> 1 my_estimator 0.125 ATE