flips <- as_tibble(rbinom(100000,1,0.5))
flips <- flips %>%
mutate(n = row_number()) %>%
mutate(heads = cumsum(value)) %>%
mutate(halfN = n / 2) %>%
mutate(HdProMinusHalf = (heads/n) - 0.5) %>%
mutate(NumHdMinusHalfN = heads - halfN) %>%
mutate(flag = if_else(n %% 100==0,1,0)) %>%
filter(flag ==1) %>%
select(n, HdProMinusHalf, NumHdMinusHalfN) Toss a coin n times and print out afterevery 100 tosses the proportion of heads minus 1/2. Do these numbers appear to approach 0 as n increases?
Yes this appears to approach 0
p = ggplot() +
geom_line(data = flips, aes(x = n, y = HdProMinusHalf), color = "blue") +
xlab('n') +
ylab('Value')
pModify the program again to print out, every 100 times, both of the following quantities: 1. the proportion of heads minus 1/2,and 2. the number of heads minus half the number of tosses.
The number of heads minus half the number of tosses doesn’t seem to be approching 0, but I’m not sure why
o = ggplot() +
geom_line(data = flips, aes(x = n, y = NumHdMinusHalfN), color = "red") +
geom_line(data = flips, aes(x = n, y = HdProMinusHalf), color = "blue") +
xlab('n') +
ylab('Value')
o