Skip to content

Instantly share code, notes, and snippets.

@acoppock
Created April 29, 2020 15:20
Show Gist options
  • Select an option

  • Save acoppock/d4793bca5a6c1f013c52245ba3f828bd to your computer and use it in GitHub Desktop.

Select an option

Save acoppock/d4793bca5a6c1f013c52245ba3f828bd to your computer and use it in GitHub Desktop.

Revisions

  1. acoppock created this gist Apr 29, 2020.
    21 changes: 21 additions & 0 deletions ATTandCACE.R
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    library(DeclareDesign)
    library(tidyverse)

    design <-
    declare_population(N = 50,
    type = sample(c("complier", "nevertaker"), N, replace = TRUE)) +
    declare_potential_outcomes(D ~ Z * (type == "complier")) +
    declare_potential_outcomes(Y ~ 5 * Z + rnorm(N)) +
    declare_assignment(prob = 0.5) +
    declare_estimand(CACE = mean(Y_Z_1 - Y_Z_0),
    subset = type == "complier") +
    declare_estimand(ATT = mean(Y_Z_1 - Y_Z_0),
    subset = D == 1)

    # Different in a single draw
    draw_estimands(design)

    # Same in expectation
    simulate_design(design, sims = 500) %>%
    group_by(estimand_label) %>%
    summarise(mean_estimand = mean(estimand))