1
$\begingroup$

Erica tosses a fair coin $n$ times and, independently, Fred tosses a fair coin $n+1$ times. What is the probability Fred gets more heads than Erica?

I have been able to solve this problem theoretically, and found that the probability is $1/2.$ The next step is to code it in R, and I am not sure where to begin.

  • 0
    How many points do we get for solving the problem and writing the R function?2017-01-18
  • 0
    I suppose, however much you'd like. I am new on this site and I'm still figuring out how it works.2017-01-18
  • 1
    Welcome to the site. I was being facetious about the points, because it seems that you are asking us to do your homework for you, which is not well received here. It will help tremendously if you provide more context and offer your own progress. What exactly are you stuck on? What is your question?2017-01-18
  • 2
    The votes to close seem a bit hasty to me. You showed engagement by giving the result of your theoretical work. (You might have summarized that briefly.) But the majority of mathematicians on this site do not use R.2017-01-18
  • 1
    @BruceET I voted to close when the question was first posted, because it was presented as a directive ("Solve the problem and implement a simulation in R") with no further information. I've now voted to reopen.2017-01-18
  • 0
    @Theophile. Got it. Thanks.2017-01-18
  • 0
    @user407935 It would be interesting to know how you theorically solved it (by symmetry?)2017-01-18

1 Answers 1

2

If you want R code for a simulation, here is about the simplest possible version. I used a million iterations with $n = 9.$ With a million iterations, you can expect about three place accuracy.

m = 10^6;  n = 9
erica = rbinom(m,n,.5); fred = rbinom(m,n+1,.5)
mean(fred > erica)   # mean of logical vector is proportion of TRUEs
## 0.500542          # aprx P(F > E) = 1/2

Extras:

MAT = cbind(fred, erica)
head(MAT)            # first 6 rows of m x 2 matrix
     fred erica
[1,]    3     4
[2,]    4     4
[3,]    3     3
[4,]    3     5
[5,]    5     6
[6,]    5     3

mean(fred);  mean(erica)
## 4.999831          # aprx 5 = 10(.5)
## 4.498146          # aprx 4.5 = 9(.5)

d = fred - erica
summary(d)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
-9.0000 -1.0000  1.0000  0.5017  2.0000 10.0000 
sd(d)
## 2.178673

hist(d, br=(-10:10)+.5, prob=T, col="skyblue2")
abline(v=mean(d), col="red", lty="dashed", lwd=2)
curve(dnorm(x, mean(d), sd(d)), col="blue", lwd=2, add=T)

enter image description here

  • 0
    (+1) When it comes to R, your answers are always very well written!2017-01-18