Skip to content

Instantly share code, notes, and snippets.

@dgrtwo
Created March 11, 2017 18:51
Show Gist options
  • Save dgrtwo/061f70cc65e55abba98df81c9c3f60f6 to your computer and use it in GitHub Desktop.
Save dgrtwo/061f70cc65e55abba98df81c9c3f60f6 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(broom)
library(scales)
theme_set(theme_minimal())
crossing(n = round(10 ^ seq(1, 7, .1)),
delta = 10 ^ seq(-1, -3, -1),
sig.level = .05,
sd = .3) %>%
invoke(power.t.test, ., type = "one.sample") %>%
tidy() %>%
ggplot(aes(n, power, color = percent(delta))) +
geom_line() +
geom_hline(lty = 2, yintercept = .9) +
scale_x_log10(labels = comma_format()) +
scale_y_continuous(labels = percent_format()) +
labs(x = "Number of observations (log scale)",
y = "Power of one-sample t-test",
color = "Effect size",
title = "Power of one-sample t-test depending on sample size",
subtitle = "Standard deviation = .3; dashed line shows power = 90%")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment