Skip to content

Instantly share code, notes, and snippets.

@acoppock
Created May 7, 2019 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoppock/8e0cd2d597a72863be2ab851da208d09 to your computer and use it in GitHub Desktop.
Save acoppock/8e0cd2d597a72863be2ab851da208d09 to your computer and use it in GitHub Desktop.
library(DeclareDesign)
library(tidyverse)
library(ggridges)
design <-
declare_population(
N = 1000,
X1 = rbinom(N, 1, .5),
X2 = rbinom(N, 1, .5),
X3 = rbinom(N, 1, .5),
X4 = rbinom(N, 1, .5),
X5 = rbinom(N, 1, .5),
Y = rnorm(N)
) +
declare_estimator(Y ~ X1, model = lm_robust, term = "X1", label = "D") +
declare_estimator(Y ~ X1*X2, model = lm_robust, term = "X1:X2", label = "DiD") +
declare_estimator(Y ~ X1*X2*X3, model = lm_robust, term = "X1:X2:X3", label = "DiDiD") +
declare_estimator(Y ~ X1*X2*X3*X4, model = lm_robust, term = "X1:X2:X3:X4", label = "DiDiDiD") +
declare_estimator(Y ~ X1*X2*X3*X4*X5, model = lm_robust, term = "X1:X2:X3:X4:X5", label = "DiDiDiDiD")
simulations <- simulate_design(design)
ggplot(simulations, aes(x = estimate, y = estimator_label)) +
geom_density_ridges() +
theme_ridges() +
theme(axis.title = element_blank())
variance_df <-
simulations %>%
group_by(estimator_label) %>%
summarise(variance = var(estimate))
variance_df$variance[2:5]/ variance_df$variance[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment