Created
September 13, 2022 23:01
-
-
Save alexpghayes/b3792cb594d7a05989a08ffb55d14818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(fastRG) | |
library(estimatr) | |
library(tidyverse) | |
set.seed(27) | |
get_one_estimate <- function() { | |
k <- 5 | |
n <- 1000 | |
B <- matrix(stats::runif(k * k), nrow = k, ncol = k) | |
theta <- round(stats::rlnorm(n, 2)) | |
pi <- c(1, 2, 4, 1, 1) | |
m <- dcsbm( | |
theta = theta, | |
B = B, | |
pi = pi, | |
expected_degree = 50 | |
) | |
A <- sample_sparse(m) | |
trt <- rbinom(n, size = 1, prob = 0.5) | |
perc_trted_neighbors <- drop(A %*% trt / rowSums(A)) | |
perc_trted_neighbors[is.na(perc_trted_neighbors)] <- 0 # isolated nodes | |
y <- trt + cos(perc_trted_neighbors) + rnorm(n) | |
fit <- lm_robust(y ~ trt) | |
tidy(fit) %>% | |
filter(term == "trt") | |
} | |
ests <- purrr::map_dfr(1:50, \(x) get_one_estimate()) | |
ests %>% | |
mutate( | |
sim = row_number() | |
) %>% | |
ggplot(aes(x = sim, ymin = conf.low, y = estimate, ymax = conf.high)) + | |
geom_pointrange() + | |
geom_hline(yintercept = 1, color = "steelblue") + | |
theme_minimal() + | |
labs( | |
title = "50 confidence intervals from the bonkers t-test", | |
caption = "Y(w[i], W[-i]) linear in trt and non-linear in portion of treated neighbors", | |
y = "Value (true direct effect is 1)", | |
x = "Simulation index" | |
) | |
Author
alexpghayes
commented
Sep 14, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment