#binomial distribution

n<-40 #number of trials
p<-0.6 #probability of success
#(a)probability of success
psuccess <- pbinom(11,size=n,prob=p,lower.tail=FALSE)
print(paste("(a)probability of more than 11 successess:",psuccess))
## [1] "(a)probability of more than 11 successess: 0.999968362869618"
#poisson question
#(a)probability of 0 typos in a 300-page book
lambda <-4 #mean value
pages <-300
pnotypos <-dpois(0, lambda*(pages/100))
print(paste("(a)probability of 0 typos in a 300-page book:",pnotypos))
## [1] "(a)probability of 0 typos in a 300-page book: 6.14421235332821e-06"
#(b)probability of more than 5 typos in a 300-page book
pmorethan5typos <- 1-ppois(5,lambda*(pages/100))
print(paste("(b)probability of more than 5 typos in a 300-page book:",pmorethan5typos))
## [1] "(b)probability of more than 5 typos in a 300-page book: 0.979658970583072"
#(c)probability of 0 typos in a 157-page book
pages <- 157
pnotypos157 <- dpois(0,lambda*(pages/100))
print(paste("(c)probability of 0 typos in a 157-page book:",pnotypos157))
## [1] "(c)probability of 0 typos in a 157-page book: 0.00187340059422242"
#(d)simulations to confirm
simulatedtypos <- rpois(10000,lambda=lambda*(pages/100))
psimulatednotypos <- mean(simulatedtypos==0)
print(paste("d)simulated probabilty of 0 typos in a 157-page book:",psimulatednotypos))
## [1] "d)simulated probabilty of 0 typos in a 157-page book: 0.0018"
#more accidents are registered in auto body repair shops during May and June
#(a)probability of more than 7 accidents in May
lambda <- 4 #average accidents per month
pmorethan7may <- 1-ppois(7,lambda)
print(paste("(a)probability of more than 7 accidents in May:",pmorethan7may))
## [1] "(a)probability of more than 7 accidents in May: 0.0511336157928474"
#(b)probability no more than 3 accidents will occur during May and June
pnomorethan3mayjune <- ppois(3,lambda)*ppois(3,lambda)
print(paste("(b)probability no more than 3 accidents will occur in May and June:",pnomorethan3mayjune))
## [1] "(b)probability no more than 3 accidents will occur in May and June: 0.187896345250729"
#telephone calls to a local 911 number folow a poisson distribution with an average of two calls per minute
#(a)probability of zero calls in one minute
lambda <- 2
pzerocalls <- dpois(0,lambda)
print(paste("(a)probability of zero calls in one minute:",pzerocalls))
## [1] "(a)probability of zero calls in one minute: 0.135335283236613"
#(b)probability of less than five calls in one minute
plessthan5calls <- ppois(4,lambda)
print(paste("(b)probability of less than 5 calls in 1 minute:",plessthan5calls))
## [1] "(b)probability of less than 5 calls in 1 minute: 0.947346982656289"
#(c)probability of less than 6 calls in 1 hour
lambda <- 2*60 #calls per hour
plessthan6calls1hour <- dpois(5,lambda)
print(paste("(c)probability of less than 6 calls in 1 hour:",plessthan6calls1hour))
## [1] "(c)probability of less than 6 calls in 1 hour: 1.58996350456699e-44"
#family income is normally distributed with mean $25000 and standard deviaton $10000
#(a)percentage of population living in poverty(income<$10000)
meanincome <- 25000
stddev <- 10000
povertylevel <- 10000
ppoverty <- pnorm(povertylevel,mean=meanincome,sd=stddev)
percentagepoverty <- ppoverty*100
print(paste("(a)percentage of population living in poverty:",percentagepoverty))
## [1] "(a)percentage of population living in poverty: 6.68072012688581"
#(b)percentage of populaton benefitting from tax law(income between $20000 and $30000)
incomebelow <- 20000
incomeabove <- 30000
pbelow <- pnorm(incomebelow,mean=meanincome,sd=stddev)
pabove <- pnorm(incomeabove,mean=meanincome,sd=stddev)
percentagebenefitting <- (pabove-pbelow)*100
print(paste("(b)percentage of people benefitting from tax law:",percentagebenefitting))
## [1] "(b)percentage of people benefitting from tax law: 38.2924922548026"
#exponential probability distribution
#life of certain light bulb with a mean of 8 months
meanlife <- 8

#(a)probability that a randomly selected light bulb lasts between 3 and 12 months
pbetween3and12 <- pexp(12,rate=1/meanlife)-pexp(3,rate=1/meanlife)
print(paste("(a)probability that a randomly selected light bulb lasts between 3 and 12 months:",pbetween3and12))
## [1] "(a)probability that a randomly selected light bulb lasts between 3 and 12 months: 0.464159118642542"
#(b)the 95th percentile of the distribution
percentile95 <- qexp(0.95,rate=1/meanlife)
print(paste("(b)the 95th percentile:",percentile95))
## [1] "(b)the 95th percentile: 23.9658581884319"
#(c)probability that a light bulb that has lasted for 10 months will last more than 25 months
pmorethan25given10 <- 1-pexp(25,rate=1/meanlife,lower.tail=TRUE)
print(paste("(c)probability that a light bulb that has lasted for 10 months will last more that 25 months:",pmorethan25given10))
## [1] "(c)probability that a light bulb that has lasted for 10 months will last more that 25 months: 0.0439369336234074"