Skip to content

Instantly share code, notes, and snippets.

@chelseaparlett
Last active August 9, 2020 17:32
Show Gist options
  • Save chelseaparlett/cd3609f921eaedbd4732dc191a9b0917 to your computer and use it in GitHub Desktop.
Save chelseaparlett/cd3609f921eaedbd4732dc191a9b0917 to your computer and use it in GitHub Desktop.
library(tidyverse)
library("viridis")
n <- 100
sd <- 10
cutoffz_r <- qnorm(0.975) * (sd/sqrt(n))
cutoffz_l <- -cutoffz_r
min_ES <- 0.28
min_raw <- min_ES*sd
p <- pnorm(cutoffz_r, min_raw, sd/sqrt(n))
power <- 1-p
curves <- seq(3,6, by = 0.25)
colors <- viridis(length(curves))
curvesproto <- lapply(1:length(curves), function(x) stat_function(fun = dnorm,
n = 101, args = list(mean = curves[x],
sd = sd/sqrt(n)), color = colors[x],
alpha = 0.5))
curvesproto2 <- lapply(1:length(curves), function(x) stat_function(fun = dnorm,
args = list(mean = curves[x], sd = sd/sqrt(n)),
xlim = c(cutoffz_r, min_raw),
geom = "area",
alpha = 0.2))
p1 <- ggplot(data = data.frame(x = c(-3, 10)), aes(x)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 0,
sd = sd/sqrt(n)),
size = 1,
color = "darkgrey") +
ylab("") +
scale_y_continuous(breaks = NULL) +
stat_function(fun = dnorm, n = 101,
args = list(mean = min_raw, sd = sd/sqrt(n)),
color = "black", size = 1) +
geom_vline(xintercept = cutoffz_r, lty = 3, size = 1) +
geom_vline(xintercept = min_raw, lty = 2, size = 1) +
stat_function(fun = dnorm,
args = list(mean = min_raw, sd = sd/sqrt(n)),
xlim = c(cutoffz_r,8),
geom = "area",
alpha = 0.2) +
stat_function(fun = dnorm,
args = list(mean = min_raw, sd = sd/sqrt(n)),
xlim = c(cutoffz_r, min_raw),
geom = "area",
alpha = 0.2) +
theme_minimal() + xlab("Raw Effect")
p1 + curvesproto + curvesproto2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment