Skip to content

Instantly share code, notes, and snippets.

@she3o
Created October 5, 2019 20:21
Show Gist options
  • Save she3o/655b92bf35d36d228be1edd0af49ff8e to your computer and use it in GitHub Desktop.
Save she3o/655b92bf35d36d228be1edd0af49ff8e to your computer and use it in GitHub Desktop.
library(tidyverse)
library(latex2exp)
library(patchwork)
library(animation)
(
ggplot(data.frame(x = 0:30), aes(x = x)) +
stat_function(
fun = dnorm,
args = list(mean = 30, sd = 4),
geom = "density",
size = 1,
fill = "gray20",
alpha = 0.5,
linetype = 0
) +
stat_function(
fun = dnorm,
args = list(mean = 20, sd = 4),
geom = "density",
size = 1,
xlim = c(0, 30 + 4 * qnorm(0.05 / 2)),
fill = "darkred",
linetype = 0
) +
stat_function(
fun = dnorm,
args = list(mean = 30, sd = 4),
geom = "density",
size = 1,
xlim = c(0, 30 + 4 * qnorm(0.05 / 2)),
fill = "steelblue",
linetype = 0
) +
stat_function(
fun = dnorm,
args = list(mean = 30, sd = 4),
geom = "density",
size = 1,
xlim = c(0, 30 + 4 * qnorm(0.0176 / 2)),
fill = "deeppink",
linetype = 0
) +
# stat_function(fun = dnorm, args = list(mean = 30, sd = 4), geom = "col", width = 0.08, xlim = c(0, 30 + 4* qnorm(0.0176/2)), fill = "deeppink", linetype = 2) +
stat_function(
fun = dnorm,
args = list(mean = 30, sd = 4),
geom = "density",
size = 1,
xlim = c(30 - 4 * qnorm(0.05 / 2), 60),
fill = "steelblue",
linetype = 0
) +
stat_function(
fun = dnorm,
args = list(mean = 30, sd = 4),
geom = "density",
size = 1,
xlim = c(30 - 4 * qnorm(0.0176 / 2), 60),
fill = "deeppink",
linetype = 0
) +
# stat_function(fun = dnorm, args = list(mean = 30, sd = 4), geom = "col",width = 0.08, xlim = c( 30 - 4* qnorm(0.0176/2),60), fill = "deeppink", linetype =\ 2) +
stat_function(
fun = dnorm,
args = list(mean = 20, sd = 4),
geom = "density",
size = 1,
linetype = 0
) +
stat_function(
fun = dnorm,
args = list(mean = 20, sd = 4),
geom = "density",
size = 1,
xlim = c(30 + 4 * qnorm(0.05 / 2), 60),
fill = "orange",
linetype = 0
) +
annotate(
"text",
25,
0.02,
label = parse(text = TeX("$\\beta$")),
size = 13,
col = "white"
) +
annotate(
"text",
17,
0.02,
label = parse(text = TeX("$1-\\beta$")),
size = 13,
col = "white"
) +
annotate(
"text",
21.5,
0.005,
label = parse(text = TeX("$\\frac{\\alpha}{2}$")),
size = 8,
col = "white"
) +
annotate(
"text",
38.5,
0.005,
label = parse(text = TeX("$\\frac{\\alpha}{2}$")),
size = 8,
col = "white"
) +
geom_segment(
aes(
x = 21,
y = 0.1,
xend = 29,
yend = 0.1
),
arrow = arrow(length = unit(0.01, "npc")),
size = 1
) +
geom_segment(
aes(
xend = 21,
yend = 0.1,
x = 29,
y = 0.1
),
arrow = arrow(length = unit(0.01, "npc")),
size = 1
) +
theme_void()
) %>%
ggsave("frequentialhypothesistesting.png",., width = 16, height = 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment