MATH 3510 Probability Teaching

Law of Large Numbers and Simulations – MATH 3510

Comments on Law of Large Numbers and simulations


Below you can find the code in R that generated the above animation


# Number of tosses
number_of_tosses <- 1000

outcome <- sample(c(0,1), size=number_of_tosses, replace = TRUE)

proportion_of_heads_at_each_time <- cumsum(outcome)/1:number_of_tosses

df <- data.frame(proportion_of_heads_at_each_time)

g <- ggplot( df, aes(x=1:number_of_tosses,y=proportion_of_heads_at_each_time)) + 
  labs(x="Number of tosses", y= "Proportion of heads") +
  geom_hline(yintercept = 0.5, show.legend = TRUE, linetype = "dashed")+
  geom_line() +
  geom_point() +
  geom_text(aes(label=round(fracs,digits = 3)),hjust=-0.2, vjust=-0.2) +
  transition_reveal(1:steps) +
  ease_aes('sine-in-out') +
  theme(panel.border = element_blank())

animate(g, renderer = gifski_renderer(), duration = 15, width=800, height=600)


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: