Created
September 3, 2025 10:59
-
-
Save abikoushi/022e109b6f93c73b97d30a6f0260dcdb to your computer and use it in GitHub Desktop.
佐藤俊哉『宇宙怪人しまりす統計よりも重要なことを学ぶ』第1話の最初の表の数値例
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
| ######## | |
| ## 佐藤俊哉『宇宙怪人しまりす統計よりも重要なことを学ぶ』(朝倉書店) | |
| ## Chapter 1: 再現性 | |
| ######## | |
| library(dplyr) | |
| library(ggplot2) | |
| reproducibility = function(true_ratio, | |
| beta = 0.8, | |
| alpha = 0.05){ | |
| study1 =cbind(true_ratio*c(beta,1-beta), | |
| (1-true_ratio)*c(alpha*0.5, 1-alpha*0.5)) | |
| (study1[1,1]*beta+study1[1,2]*alpha*0.5)/sum(study1[1,]) | |
| } | |
| z = seq(0, 1, length.out=201) | |
| condf = expand.grid(alpha = c(0.01, 0.05, 0.1), | |
| beta = c(0.7,0.8)) %>% | |
| group_by(alpha, beta) %>% | |
| reframe(z=z, | |
| value = sapply(z, reproducibility, alpha=alpha, beta=beta)) | |
| ggplot(condf, aes(x=z, y=value, | |
| colour = alpha, | |
| group = interaction(alpha, beta)))+ | |
| facet_grid(col=vars(beta), labeller = label_both) + | |
| geom_line() + ylim(c(0,1)) + | |
| labs(color="alpha", | |
| x = "true positive ratio in the population", | |
| y = "reproducibility")+ | |
| theme_bw(16) | |
| #ggsave("repro.png", width=8, height=7) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment