Q)Let’s assume that a hospital’s neurosurgical team performed N procedures for in-brain bleeding last year. X of these procedures resulted in death within 30 days. If the national proportion for death in these cases is pi, then is there evidence to suggest that your hospital’s proportion of deaths is more extreme than the national proportion? Pick your own values of N, X, and pi. X is necessarily less than or equal to N, and pi is a fixed probability of success. The probability should be greater than or equal to X. Then model both as a binomial and a Poisson, and provide your R code solutions.

#Binomial Model :
#Let assume 
choose(n = 30, k = 5) * 0.5^5 * (1-0.5)^(30-5)
## [1] 0.0001327191
N  <- 30
K  <- 5
pi <- 0.5
choose(n = N, k = K) * pi^K * (1-pi)^(N-K) # gives same answer as above
## [1] 0.0001327191
# Again, gives same answer as above
dbinom(x   = 5, 
       size = 30, 
       prob = 0.5
       )
## [1] 0.0001327191
1 - pbinom(4,30,0.5)
## [1] 0.9999703
# Mean of Binomial
#N * pi
30 * 0.5
## [1] 15
#Variance of Binomial
#size * prob * (1-prob)
30 * 0.5 * 0.5
## [1] 7.5
#Poisson Model 

dpois(x = 4,lambda = 15)
## [1] 0.0006452627
# discrete variable adjustment - read lower tail argument specification P[X≤x]
ppois(q= 4,lambda= 15,lower.tail = TRUE)
## [1] 0.0008566412
# discrete variable adjustment - read lower tail argument specification P[X>x]
ppois(q= 4,lambda= 15,lower.tail = FALSE)
## [1] 0.9991434
hist(rpois(n = 30,lambda = 15)) # mean of poison

sum(dbinom(x=5:30, size= 30, prob= 0.5))
## [1] 0.9999703
pbinom(q = 4 ,size = 30,prob = 0.5, lower.tail = F)
## [1] 0.9999703
1 - ppois(q = 4,lambda = 15,lower.tail=T)
## [1] 0.9991434