Simulates 2 coin toss and calculate emperical probability of
getting double heads.
# Function tossl() simulates coin toss
toss <- function(x) floor(2*runif(x))
# Let c1 tosses from coin 1 and c2 represent tosses of coin 2.
We’ll store 1000 coin tosses in c1 and c2
c1=toss(1000)
c2=toss(1000)
dheads=sum((c1+c2)==2)
# Double heads dheads will occurs when corresponding sum of
outcomes is 2
# == operator is TRUE only when the sum of corresponding tosses is
2 (Two
heads came up)
#sum((c1+c2)==2) then adds up all TRUE events and stores the count
in dheads.
#Print the output. Final results with comments should be the only
thing
printed out.
cat("Emperical probability of getting double heads is",
dheads/1000, ’\n’)
a) what is the final script file and discuss the results of your experiment?
b) Does the emperical proability matches theoretical one?
c) Modify the code so that 3 coins are tossed and calculate emperical probability of triple heads.
Get Answers For Free
Most questions answered within 1 hours.