Skip to content

Instantly share code, notes, and snippets.

@acoppock
Created May 12, 2018 15:11
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/f2983b71628ab810d825c286bb1e7360 to your computer and use it in GitHub Desktop.
Save acoppock/f2983b71628ab810d825c286bb1e7360 to your computer and use it in GitHub Desktop.
Add Robust SEs to a ggplot
library(fabricatr)
library(randomizr)
library(estimatr)
library(ggplot2)
dat <- fabricate(N = 200,
Z = complete_ra(N, conditions = c("Control", "Treatment")),
X = sample(c("A", "B"), size = N, replace = TRUE),
Y = (X == "A") + (Z == "Treatment") + rnorm(N, sd = 1 + (Z == "Treatment")))
ggplot(dat, aes(Z, Y, group = X, color = X)) +
geom_point(position = position_jitter(height = 0, width = 0.1), alpha = .1) +
stat_smooth(method = "lm_robust") +
theme_bw() +
ggtitle("Robust SEs on a ggplot is easy with estimatr::lm_robust()",
'Just do stat_smooth(method = "lm_robust")')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment