#1.

#B=Positive test
#A1= HIV (+)
#A2= HIV (-)
#let check  for P(A1 | B)
#USE Bayes
#P(A1 | B) =  P (B|A1)P(A1) / P(B|A1)P(A1)+P(B|A2)P(A2)
#P(B|A1)=.96
#P(B|A2)=1-.98=.02
#P(A1)=.001
#P(A2)=.999
#P(A1 | B)=(.96*.001)/((.96*.001)+(.02*.999))
(.96*.001)/((.96*.001)+(.02*.999))
## [1] 0.04584527
# total first-year cost for treating 100,000 individuals:

indiv=100000*.001
Costoftest=1000*100000
Costforindiv=indiv*100000
TotalCost=Costoftest+Costforindiv
TotalCost
## [1] 1.1e+08
#2.

#prob=2
dbinom(2,24,.05)
## [1] 0.2232381
#p>=2=1-P(1)-P(0)
1-(dbinom(1,24,.05)+dbinom(0,24,.05))
## [1] 0.3391827
#P<2=P(0)+P(1)
pbinom(1,24,.05)
## [1] 0.6608173
#E[X]=npq
 24*.05
## [1] 1.2
#Var[X]=npq
24*.05*.95
## [1] 1.14
#sd=(npq)^.5
(24*.05*.95)^.5
## [1] 1.067708
#3.

#P(3)
dpois(3,10)
## [1] 0.007566655
#p(more than 10)=1-P(0)-p(1)-.....P(10)
1-sum(dpois(0:10,10))
## [1] 0.4169602
#E(x) t=8
10*8
## [1] 80
# sd= var^.5
 
10^.5
## [1] 3.162278
80/72*100
## [1] 111.1111
#4.

#P(5), x=5,m=15,n=15,k=6
dhyper(5,15,15,6,log=FALSE)
## [1] 0.07586207
#E(X)=KM/N
6*15/30
## [1] 3
6-3
## [1] 3
#5.

#probability that the driver will be seriously injured during the course of the year
(1 - (1 - 0.001)^1200)
## [1] 0.6989866
#15 months
fifteen <- 1200*1.25
(1 - (1 - 0.001)^fifteen)
## [1] 0.7770372
#E[X]=1/p
1/.001
## [1] 1000
#P(injured next 100 hours|not injured 1200)
(1 - (1 - 0.001)^100)
## [1] 0.09520785
#6.

#p= fail more than twice in 1000 hours
1 - sum((1 - (1/1000))^(0:2 - 1) * (1/1000))
## [1] 0.997
#expected value
1 / (1/1000)
## [1] 1000
#7.

#wait >30minutes
1 - punif(10, 0, 30)
## [1] 0.6666667
#wait=10 minutes
1 - punif(15, 0, 30)
## [1] 0.5
# Expected waiting time =15 minutes
(0 + 30) / 2
## [1] 15
#8.

#E(x)=10
sd=1 / (1/10)
sd
## [1] 10
# Prob( will fail after 8 years)
1 - exp((-1/10) * 8)
## [1] 0.550671
#Prob(will fail in 2 years)
1 - exp((-1/10) * 2) 
## [1] 0.1812692