Exercise 1: A lab network consisting of 15 computers was attacked by a computer virus. This virus enters each computer with probability 0.20, independently of other computers. Use R commands to answers the following questions.

(a) Find the probability that the virus enters exactly 4 computers.

P(X=4):

n=15
p=0.20
ans=dbinom(4,n,p)
ans
## [1] 0.1876042

(b) Find the probability that the virus enters at most 4 computers.

P(X<=4):

ans=pbinom(4,n,p)
ans
## [1] 0.8357663

(c) Find the probability that the virus enters at least 4 computers.

P(X>=4):

ans = 1 - pbinom(3,n,p)
ans
## [1] 0.3518379

(d) Find the probability that the virus enters more than 4 computers.

P(X>4):

ans = pbinom(4,n,p,lower.tail=F)
ans
## [1] 0.1642337

Exercise 2: A voting district has 205 female voters and 195 male voters. A random sample of 15 voters is drawn. Use R commands to answer the following questions.

(a) What is the probability exactly 7 of the voters will be female?

P(X=7):

m = 205
n = 195
k = 15
ans = dhyper(7, m, n, k)
ans
## [1] 0.1938501

(b) What is the probability that at most 7 of the voters will be female?

P(X<=7):

ans = phyper(7, m, n, k)
ans
## [1] 0.4600768

(c) If a binomial approximation is appropriate, use it to answer (a) again and compare the answers.

P(X=7) using binomial:

p = m / (m + n)
ans = dbinom(7, k, p)
ans
## [1] 0.190635

(d) If a binomial approximation is appropriate, use it to answer (b) again and compare the answers.

P(X<=7) using binomial:

ans = pbinom(7, k, p)
ans
## [1] 0.4607811

Exercise 3: Bob is a high school basketball player. He is a 50% free throw shooter. That means his probability of making a free throw is 0.50. Use R commands to answer the following questions.

(a) During the season, what is the probability that Bob makes his second free throw on his fifth shot?

P(X=2nd success on 5th shot):

ans = dnbinom(3, 2, 0.5)
ans
## [1] 0.125

(b) What is the probability that Bob makes his first free throw on his third shot?

P(X=1st success on 3rd shot):

ans = dgeom(2, 0.5)
ans
## [1] 0.125

Exercise 4: An article in the Los Angeles Times (Dec. 3, 1993) reports that 1 in 500 people carry the defective gene that causes inherited colon cancer. In a sample of 2000 individuals, we are interested in the number of individuals who carry this gene. Typically binomial distribution can be used to model this number. However, in the case of large n and small p, we can use Poisson distribution approximately. Answer the following questions using R commands.

(a) Use binomial distribution to calculate the the probability that between 6 and 9 (in-clusive) carry the gene.

P(6 <= X <= 9) using binomial:

n = 2000
p = 1 / 500
ans = sum(dbinom(6:9, n, p))
ans
## [1] 0.2066469

(b) Use binomial distribution to calculate the the probability that at most 8 carry the gene.

P(X<=8) using binomial:

ans = pbinom(8, n, p)
ans
## [1] 0.9787556

(c) Use Poisson distribution to recalculate the approximated probability for part(a) and make comparison.

P(6 <= X <= 9) using Poisson:

lambda = n * p
ans = sum(dpois(6:9, lambda))
ans
## [1] 0.2067374

(d) Use Poisson distribution to recalculate the approximated probability for part(b) and make comparison.

P(X<=8) using Poisson:

ans = ppois(8, lambda)
ans
## [1] 0.9786366