1 1. Binomial Distribution Example:

A shipment contains 40 electronic components. Each component has a 0.1 probability of being defective.

A quality control inspector tests 15 components.

a. What is the probability that exactly 2 components are defective?

# sample size is 15, exactly 2 comp are defective and .1 probability being defective.

dbinom(2,15,.1)
## [1] 0.2668959

b. What is the probability that at most 3 components are defective?

pbinom(3,15,.10)
## [1] 0.9444444

c. Plot the PMF for the number of defectives from 0 to 15

plot(0:15, dbinom(0:15,15,.1),type="h",main="Binomial PMF,n=15,p=0.1", 
     xlab="Number of Defectives",ylab="Probability") 

2 Poisson Distribution Example:

A help desk receives an average of 6 calls per hour.

a. What is the probability that exactly 8 calls are received in an hour?

dpois(8,6)
## [1] 0.1032577

b. What is the probability that fewer than 5 calls are received?

ppois(4,6)
## [1] 0.2850565

c. Plot the PMF for call counts between 0 and 15.

plot(dpois(0:15,6),type="h",main="Pois PMF,n=15,average is 6",
     xlab="Time",ylab="Call counts")

3 Normal Distribution Example:

The weights of boxes shipped from a warehouse are normally distributed with a mean of 22 kg and standard deviation 3 kg.

a. What is the probability a randomly selected box weighs less than 20.5 kg?

pnorm(20.5,22,3)
## [1] 0.3085375

b. What is the probability a box weighs between 19 kg and 24 kg?

pnorm(24,22,3)-pnorm(19,22,3)
## [1] 0.5888522

c. Plot the PDF and CDF from 15 kg to 30 kg.

# PDF 
curve(dnorm(x,22,3),from=15,to=30,main="Normal PDF:mean=22,sd=3",
      xlab="Weight",ylab="Chance")

curve(pnorm(x,22,3),from=15,to=30,main="Normal CDF:mean=22,sd=3",
      xlab="Weight",ylab="Chance")

4 Exponential Distribution Example:

A customer service center takes on average 12 minutes to resolve a ticket. Let X ~ Exp(rate = 1/12).

a. What is the probability that a resolution takes less than 8 minutes?

pexp(8,1/12)
## [1] 0.4865829

b. What is the probability that it takes between 10 and 18 minutes?

pexp(18,1/12)-pexp(10,1/12)
## [1] 0.211468

c. Plot the PDF and CDF from 0 to 40 minutes.

# PDF:

curve(dexp(x,1/12),from=0,to=40,main="Exp PDF: rate1/12",xlab="X",ylab="Time")

# CDF:

curve(pexp(x,1/12),from=0,to=40,main="Exp CDF: rate1/12",xlab="X",ylab="Time")

5 Gamma Distribution Example:

The life of a machine component is modeled as a Gamma distribution with shape = 3.5 and scale = 4.2 hours.

a. What is the probability the component lasts more than 18 hours?

# where shape is Alpha and scale is Beta

1-pgamma(18,shape=3.5,scale=4.2)
## [1] 0.2849066

b. What is the probability it lasts between 10 and 16 hours?

pgamma(16,shape=3.5,scale=4.2)-pgamma(10,shape=3.5,scale=4.2)
## [1] 0.3216122

c. Plot the PDF and CDF from 0 to 40 hours.

# PDF:

curve(dgamma(x,shape=3.5,scale=4.2),from=0,to=50,main="Gamma PDF,shape=3.5,4.2 scale")

# CDF:

curve(pgamma(x,shape=3.5,scale=4.2),from=0,to=50,main="Gamma CDF,shape=3.5,4.2 scale")