Last active
November 1, 2021 03:43
-
-
Save sysilviakim/23b1dde0237a05d084831bd05eb68beb to your computer and use it in GitHub Desktop.
Simulation of Probability Estimate with Repeated Experiments (Coin Toss)
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
library(tidyverse) | |
set.seed(100) | |
df <- tibble( | |
n = seq(1e5), | |
x = rbinom(1e5, 1, 0.5), | |
y = cumsum(x) / n | |
) | |
## In base R, plot(df$n, df$y) | |
ggplot(df, aes(x = n, y = y)) + | |
geom_point() + | |
xlab("Number of Trials") + | |
ylab("Estimated Probability of Heads") + | |
scale_y_continuous( | |
limits = c(0, 0.6), | |
breaks = seq(0, 0.6, by = 0.1) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment