Created
February 20, 2023 16:45
-
-
Save rasmusab/dc8363277d75e2cfafdfadec0cf945e8 to your computer and use it in GitHub Desktop.
A much improved bowling T-test in R
This file contains 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
bowling_animation_urls <- c( | |
"0.01" = "https://i.imgur.com/Kn8CQbj.gif", | |
"0.05" = "https://i.imgur.com/HFTKdDL.gif", | |
"0.1" = "https://i.imgur.com/8Sw54Mz.gif", | |
"1" = "https://i.imgur.com/kjROdhj.gif" | |
) | |
# We need to download the animations to the session temp dirercorty to display | |
# them in the Rstudio Viever pane | |
bowling_animation_html <- sapply(bowling_animation_urls, function(url) { | |
animation_path = tempfile(pattern = "bowling_animation", fileext = ".gif") | |
download.file(url, animation_path) | |
html_path = tempfile(pattern = "bowling_animation", fileext = ".html") | |
html <- paste0( | |
'<html><body><img src="', | |
basename(animation_path) , | |
'" style="width: 100%;height: auto;"/></body></html>' | |
) | |
writeLines(html, html_path) | |
html_path | |
}) | |
# A much improved t.test function | |
bowling.t.test <- function(...) { | |
test_result <- t.test(...) | |
selected_animation_html <- bowling_animation_html[ | |
test_result$p.value < as.numeric(names(bowling_animation_urls)) | |
][1] | |
rstudioapi::viewer(selected_animation_html) | |
test_result | |
} | |
set.seed(123) | |
y1 = rnorm(30, mean = 2) | |
y2 = rnorm(30) | |
# A successful experiment, we're great scientists. | |
bowling.t.test(y1, y2) | |
set.seed(123) | |
y1 = rnorm(30, mean = 0.7) | |
y2 = rnorm(30) | |
# Oh, that was close, but we're still great scientists. | |
bowling.t.test(y1, y2) | |
set.seed(123) | |
y1 = rnorm(30, mean = 0.65) | |
y2 = rnorm(30) | |
# What bad luck! Let's say it's trending towards significance maybe? | |
bowling.t.test(y1, y2) | |
set.seed(123) | |
y1 = rnorm(30, mean = 0.5) | |
y2 = rnorm(30) | |
# What are we even doing with our lives... | |
bowling.t.test(y1, y2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment