Suppose that you have a possibly biased coin that gives Heads with prob- ability
ID: 2924997 • Letter: S
Question
Suppose that you have a possibly biased coin that gives Heads with prob- ability p, where p is unknown (0 p 1) a) Describe a way to simulate flipping a fair coin using only the possibly biased coin. Hint: By considering a sequence of pairs of flips of the possibly biased coin, find an event that has probability exactly 1/2 (for all values of p) (b) Implement the procedure from (a) in R with a coin for which p = 0.1. Use the command rbinom(1,1,p) as a way of 'flipping' this biased coin. Run your procedure 1000 times. Report your code Hint: you are being asked to run your procedure 1000 times: each run of your procedure may require several (simulations of) flips ojf the possibly biased coin (c) Report the average number of possibly biased coin flips per run of the procedure over these 1000 runsExplanation / Answer
a) Let us flip the coin twice. Then we have the respective probabilities.
P(HH)=p2; p(HT)=p(1-p); P(TH)=(1-p)p; p(TT)=(1-p)2.
Clearly, P(HT)=P(TH), i.e. having a Head first and then Tail and having Tail first and then Head-- these two events have equal chances. So to get results of a fair coin using a biased coin irresoective of its success probability we need to do:
Accept outcome pair HT as HEAD and pair TH as TAIL. HT and TH happen with equal chances so we have equal chance of getting a head or tail. Now, if we get HH or TT as outcomes, we pretend that it never happened and repeat the trial to generate another pair, repeat untill we get a HT or a TH, i.e. a unbiased toss. The probabbility of generating Head or Tail remains same for each round and we will be having p(head)=p(tail)=1/2 out of the given process.
So, the process is
flip the coin twice,
STOP if we get HT or TH, repeat flipping otherwise.
b) The method is implemented using R, and the result after 1000 runs we got,
HEAD TAIL
498 502.
###---R-code----###
result=NULL
l=NULL
for(i in 1:1000)
{
p=.1
x=NULL
repeat{
x=c(x,rbinom(1,1,p),rbinom(1,1,p))
l[i]=length(x)
if(x[(length(x)-1)]==1 & x[length(x)]==0)
{result[i]="HEAD"
break
}
if(x[(length(x)-1)]==0 & x[length(x)]==1)
{result[i]="TAIL"
break}
}
}
average_length_run=mean(l)
print(table(result))
average_length_run
##################################
c) The avearage number biased coin flips per run comes as 11.532 per run.
[NOTE: theoretically for the process the expected number of flips per run comes as 1/(p(1-p)). For p=0.1, expected number comes as 11.11, which is much close to what we get from our results.]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.