# The options message = FALSE, and echo = FALSE
# prevent this code and its output showing up in the
# knit document
library(tidyverse)
library(here)
# This reads in the pre-saved simulation
runs_big <- read_rds(here("results", "sim-output.rds"))

Introduction

A random sequence of H's and T's is generated by tossing a fair coin $n = 20$ times. What's the expected length of the longest run of consecutive heads or tails?

Taken from Tijms, Henk. Probability: A Lively Introduction. Cambridge University Press, 2017

A simulation study was conducted to explore the answers to these questions ... blah blah

Results

runs_big %>% 
  ggplot(aes(x = n, y = mean_max_length, color = factor(prob))) +
    geom_pointrange(aes(
      ymin = mean_max_length - 1.96*sd_max_length/sqrt(n_sims),
      ymax = mean_max_length + 1.96*sd_max_length/sqrt(n_sims))) +
    geom_line()  +
  facet_wrap(~ n_sims, labeller = "label_both") +
  labs(x = "Estimated expected longest run",
    y = "Coin toss sequence length",
    color = "Probability of heads") +
  scale_color_brewer(palette = "Set1") +
  theme_bw()

Unsurprising the longer the coin toss sequence the longest the expected longest run ... blah blah



ST541-Fall2018/cointoss documentation built on May 31, 2019, 1:53 p.m.