Two Plus Two Publishing LLC
Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > >

Notices

Probability Discussions of probability theory

Reply
 
Thread Tools Display Modes
Old 10-01-2018, 07:00 PM   #1
wait
grinder
 
Join Date: Oct 2017
Posts: 639
Coin flips question

Friend asked me this. Hope it makes sense.

If 100 people flip a coin once a day for a year, what percentage can be expected to have a wider spread than 52.38/47.62 heads/tails ratio?
wait is online now   Reply With Quote
Old 10-01-2018, 08:19 PM   #2
mkind0516
Carpal \'Tunnel
 
mkind0516's Avatar
 
Join Date: Aug 2006
Location: And the home...of the...JETS
Posts: 6,266
Re: Coin flips question

Quote:
Originally Posted by wait View Post
Friend asked me this. Hope it makes sense.

If 100 people flip a coin once a day for a year, what percentage can be expected to have a wider spread than 52.38/47.62 heads/tails ratio?
I did a quick simulation of your question (written in R and the code is below in case any users wanted to play around with parameters). I had a person flip a coin 365 times, calculated the absolute difference of heads and tails, and then counted how many reached the threshold you asked for (which came out to a difference 17.374. So a success is any trial where the person flipped at least 17.37 more of one than the other). I repeated this 20,000 times.

The probability of one person getting a difference of at least 52.38% on one outcome or the other was about 34.06%. Since coin flips are all independent, that would mean that on average 34 out of 100 people would hit the threshold.

Here's a histogram of the difference in all 20,000 sims (red line is >= 52.38%):


Code:
#Number of days a coin is flipped
days.sample = 365

#Calculating what the difference in heads from tails would need to be to hit the threshold
ratio.spread = 52.38 - 47.62
ratio.target = days.sample * ratio.spread/100

#Simulation trials
n.trials = 20000

#initialize results vector for ratio of heads to tails
ratios = c()

for(trial in 1:n.trials){
  #In every trial, a person flips a coin days.sample days in a row. The loop stores the number of heads and tails in the sample and then repeats

  heads=c()
  tails=c()

  for(day in 1:days.sample){
    
    #flip coin
    coin = sample(0:1,1)
    
    if(coin == 1){
      heads[day] = 1
      tails[day] = 0
      
    } else{
      heads[day] = 0
      tails[day] = 1
    }
    
  }
  ratios[trial] = abs(sum(heads) - sum(tails))
}

#Number of successes in sample
successes = sum(ratios >= ratio.target) 

#Likelihood of a person reaching the difference threshhold of heads from tails
successes / n.trials

ggplot(data.frame(ratios), aes(x=ratios)) + geom_histogram() + geom_vline(xintercept = ratio.target, col="red")

Last edited by mkind0516; 10-01-2018 at 08:25 PM.
mkind0516 is offline   Reply With Quote
Old 10-01-2018, 08:27 PM   #3
heehaww
Pooh-Bah
 
heehaww's Avatar
 
Join Date: Aug 2011
Location: Tacooos!!!!
Posts: 4,462
Re: Coin flips question

[Sum of C(365, k) from k=192 to k=365] / 2^365

≈ 17.3%

Or twice that if it can also be .5238 tails to heads.
heehaww is offline   Reply With Quote
Old 10-01-2018, 08:29 PM   #4
wait
grinder
 
Join Date: Oct 2017
Posts: 639
Re: Coin flips question

Thanks
wait is online now   Reply With Quote
Old 10-01-2018, 08:32 PM   #5
mkind0516
Carpal \'Tunnel
 
mkind0516's Avatar
 
Join Date: Aug 2006
Location: And the home...of the...JETS
Posts: 6,266
Re: Coin flips question

Quote:
Originally Posted by heehaww View Post
[Sum of C(365, k) from k=192 to k=365] / 2^365

≈ 17.3%

Or twice that if it can also be .5238 tails to heads.
Just to clarify, I assumed it didn't matter if it was .5238 heads or tails. If it had to be heads> tails, then you'd cut my simulation result in half, which would be 17.03%.

So at the very least since heehaww solved it formally I now know that I didn't screw up my simulation!
mkind0516 is offline   Reply With Quote
Old 10-03-2018, 12:04 PM   #6
nickthegeek
journeyman
 
Join Date: Sep 2011
Posts: 248
Re: Coin flips question

Quote:
Originally Posted by mkind0516 View Post
I did a quick simulation of your question (written in R ...)
Your simulation is highly inefficient. Just vectorize. After defining the initial parameters, without any loop you can just do this:

Code:
sims<-matrix(rbinom(n.trials*days.sample,1,0.5),ncol=days.sample)
ratios<-abs(2*rowSums(sims)-ncol(sims))
Still better is just to simulate all the days.sample together for each simulation:

Code:
sims<-rbinom(n.trials,days.sample,0.5)
ratios<-abs(2*sims-days.sample)
nickthegeek is offline   Reply With Quote
Old 11-18-2018, 04:41 PM   #7
kraps2312
stranger
 
Join Date: Jan 2018
Posts: 6
Re: Coin flips question

Quote:
Originally Posted by nickthegeek View Post
Your simulation is highly inefficient. Just vectorize.
thanks for sharing this
many do want to lower the time to run some code (as long as they can also understand it)
some do not care how long it takes

on my machine (win10 64bit, i7 quad-core. R version 3.4.4 64-bit)
the original R code using the for(), where many can easily follow and understand the code
> successes / n.trials
[1] 0.3455
> end.time <- Sys.time()
> print(end.time - start.time)
Time difference of 1.063789 mins

1st change
> successes / n.trials
[1] 0.34175
> end.time <- Sys.time()
> print(end.time - start.time)
Time difference of 0.880959 secs

2nd change
> successes / n.trials
[1] 0.348
> end.time <- Sys.time()
> print(end.time - start.time)
Time difference of 0.224988 secs
*****
anyone pick up on the reason for the OP?
the 52.38
looks to be the sportsbetting break even percentage for -110 wagers

I like seeing the calculated version also
just as a check
using pari/gp calculator
here online
pari/gp calculator
sum(k=192,365,binomial(365,k)/2^365.)

gp > x=sum(k=192,365,binomial(365,k)/2^365.);
gp > x
%2 = 0.17306096977676108864963708535391833549
(just what it prints)

gp also can give an exact result (to many is meaningless)
Code:
%4 = 203220528468429389799192225657901180620928791059635491607434982152500715968661876726960266553086443136419117/1174271291386916613944740298394668513687841274454159935353645485766104512557304221731849499192384351515967488

Last edited by kraps2312; 11-18-2018 at 04:54 PM. Reason: fix spelling errors
kraps2312 is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Forum Jump


All times are GMT -4. The time now is 07:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright © 2008-2017, Two Plus Two Interactive
 
 
Poker Players - Streaming Live Online