R Code for Discrete Probability Example 3
fair.sim<-rbinom(100,1,0.5) # Fair: there is a 50-50 chance of flipping heads (or tails)
heads.fair <- sum(fair.sim)/100
biased.sim<-rbinom(100,1,0.8) # Biased: there is a higher chance of flipping heads
# than tails (or tails than heads) - here we set heads as the more likely outcome (heads # 0.80 and tails 0.20)
heads.biased<- sum(biased.sim)/100
compare <- data.frame(heads.fair,heads.biased)
rownames(compare) <- "experimental probability"
compare
barplot(c(heads.fair,heads.biased),names.arg=c("Fair","Biased"),ylab="Number of Heads", main="Number of Heads in 100 Simulated Flips")