Discussion 6

P.114 Problem #5

Use the program BinomialProbabilities to find the probability that, in 100 tosses of a fair coin, the number of heads that turns up lies between 35 and 65, between 40 and 60, and between 45 and 55.

#n -> number of repeated trials
#p -> probability of success
#k -> number of success trials

#Create binomial probabilities function
Binomial_Prob_fun <- function(n,p,k) {
    result <- (factorial(n)/(factorial(k) * factorial(n-k)))*(p^k)*((1-p)^(n-k))
    print(result)
    }

#Create sequences 

#Between 35 adn 65 heads
a <- seq(35, 65, by = 1)

#Between 40 and 60 heads
b <- seq(40, 60, by = 1)

#Between 45 and 55 heads
c <- seq(45, 55, by = 1)


#Insert sequences into function for k
a1 <- Binomial_Prob_fun(100,0.5,a)
##  [1] 0.0008638557 0.0015597394 0.0026979276 0.0044728800 0.0071107323
##  [6] 0.0108438667 0.0158690732 0.0222922695 0.0300686426 0.0389525598
## [11] 0.0484742966 0.0579583981 0.0665905000 0.0735270104 0.0780286641
## [16] 0.0795892374 0.0780286641 0.0735270104 0.0665905000 0.0579583981
## [21] 0.0484742966 0.0389525598 0.0300686426 0.0222922695 0.0158690732
## [26] 0.0108438667 0.0071107323 0.0044728800 0.0026979276 0.0015597394
## [31] 0.0008638557
b1 <- Binomial_Prob_fun(100,0.5,b)
##  [1] 0.01084387 0.01586907 0.02229227 0.03006864 0.03895256 0.04847430
##  [7] 0.05795840 0.06659050 0.07352701 0.07802866 0.07958924 0.07802866
## [13] 0.07352701 0.06659050 0.05795840 0.04847430 0.03895256 0.03006864
## [19] 0.02229227 0.01586907 0.01084387
c1 <- Binomial_Prob_fun(100, 0.5, c)
##  [1] 0.04847430 0.05795840 0.06659050 0.07352701 0.07802866 0.07958924
##  [7] 0.07802866 0.07352701 0.06659050 0.05795840 0.04847430
#Add the probabilities within those ranges
sum(a1)
## [1] 0.9982101
sum(b1)
## [1] 0.9647998
sum(c1)
## [1] 0.728747