DeclareDesign (version 0.20.0)

declare_design: Declare a design

Description

Declare a design

Usage

# S3 method for dd
+(lhs, rhs)

# S3 method for design print(x, verbose = TRUE, ...)

# S3 method for design summary(object, verbose = TRUE, ...)

Arguments

lhs

A step in a research design, beginning with a function that draws the population. Steps are evaluated sequentially. With the exception of the first step, all steps must be functions that take a data.frame as an argument and return a data.frame. Typically, many steps are declared using the declare_ functions, i.e., declare_population, declare_population, declare_sampling, declare_potential_outcomes, declare_estimand, declare_assignment, and declare_estimator.

rhs

A second step in a research design

x

a design object, typically created using the + operator

verbose

an indicator for printing a long summary of the design, defaults to TRUE

...

optional arguments to be sent to summary function

object

a design object created using the + operator

Value

a list of two functions, the design_function and the data_function. The design_function runs the design once, i.e. draws the data and calculates any estimates and estimands defined in ..., returned separately as two data.frame's. The data_function runs the design once also, but only returns the final data.

Details

Users can supply three kinds of functions to create a design:

1. Data generating functions. These include population, assignment, and sampling functions.

2. Estimand functions.

3. Estimator functions.

The location of the estimand and estimator functions in the pipeline of functions determine *when* the values of the estimand and estimator are calculated. This allows users to, for example, differentiate between a population average treatment effect and a sample average treatment effect by placing the estimand function before or after sampling.

Design objects declared with the + operator can be investigated with a series of post-declaration commands, such as draw_data, draw_estimands, draw_estimates, and diagnose_design.

The print and summary methods for a design object return some helpful descriptions of the steps in your research design. If randomizr functions are used for any assignment or sampling steps, additional details about those steps are provided.

Examples

Run this code
# NOT RUN {
my_population <- declare_population(N = 500, noise = rnorm(N))

my_potential_outcomes <- declare_potential_outcomes(Y ~ Z + noise)

my_sampling <- declare_sampling(n = 250)

my_assignment <- declare_assignment(m = 25)

my_estimand <- declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0))

my_estimator <- declare_estimator(Y ~ Z, estimand = my_estimand)

my_mutate <- declare_step(dplyr::mutate, noise_sq = noise^2)

my_reveal <- declare_reveal()

design <- my_population + my_potential_outcomes + my_sampling +
         my_estimand + my_mutate +
         my_assignment + my_reveal + my_estimator

design

df <- draw_data(design)

estimates <- draw_estimates(design)
estimands <- draw_estimands(design)

# You can add steps to a design

design <- my_population + my_potential_outcomes
design + my_sampling

# Special Cases

# You may wish to have a design with only one step:

design <- my_population + NULL
design


# }
# NOT RUN {
diagnosis <- diagnose_design(design)

summary(diagnosis)
# }
# NOT RUN {

my_population <- declare_population(N = 500, noise = rnorm(N))

my_potential_outcomes <- declare_potential_outcomes(
  Y_Z_0 = noise, Y_Z_1 = noise +
  rnorm(N, mean = 2, sd = 2))

my_sampling <- declare_sampling(n = 250)

my_assignment <- declare_assignment(m = 25)

my_estimand <- declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0))

my_estimator <- declare_estimator(Y ~ Z, estimand = my_estimand)

my_mutate <- declare_step(dplyr::mutate, noise_sq = noise ^ 2)

my_reveal <- declare_reveal()

design <- my_population +
  my_potential_outcomes +
  my_sampling +
  my_estimand +
  my_mutate +
  my_assignment +
  my_reveal +
  my_estimator

summary(design)
# }

Run the code above in your browser using DataCamp Workspace