Created
May 12, 2018 15:11
-
-
Save acoppock/f2983b71628ab810d825c286bb1e7360 to your computer and use it in GitHub Desktop.
Add Robust SEs to a ggplot
This file contains hidden or 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(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