Discrete Distributions in R

Question 1

A quality control inspector randomly samples 25 products from a production line and counts the number of defective products in the sample. Suppose it is known that the probability any one product is defective is 0.12.

1.a

Plot the probability distribution:

1.b

What is the probability that there are exactly 3 defective products in the sample?

## [1] 0.2387209

1.c

What is the probability there are more than 3 defective products in the sample?

## [1] 0.5911838

Question 2

The arrival of customers to a queue follows a Poisson process with an average rate of 14.25 per hour.

2.a

Plot the probability distribution from 10 to 20:

2.b

What is the probability that exactly 14 customers will arrive in the next hour?

## [1] 0.1057556

2.c

What is the probability that there will be less than 12 customers who arrive in the next hour?

## [1] 0.3343031


Continuous Distributions in R

Question 1

A particular random variable is normally distributed with a mean of 20 and a standard deviation of 2.5.

1.a

Plot the probability density function of X for all x between 10 and 30, be sure to add a title and label to the axes.

1.b

Plot the cumulative density function of X for all x between 10 and 30, be sure to add a title and label to the axes.

1.c

Find the probability X<19.73

## [1] 0.2945985

1.d

Find the probability 18.5<X<19.73

## [1] 0.2932486

Question 2

A particular random variable is exponentially distributed with a mean of 5.

2.a

Plot the probability density function of X for all x between 0 and 25, be sure to add a title and label to the axes.

2.b

Plot the cumulative density function of X for all x between 0 and 25, be sure to add a title and label to the axes.

2.c

Find the probability X<10.27

## [1] 0.871779

2.d

Find the probability 3.84<X<10.27

## [1] 0.335719

Question 3

A particular random variable is gamma distributed with a shape parameter of 2.3 and a scale parameter of 8.4.

3.a

Plot the probability density function of X for all x between 0 and 50, be sure to add a title and label to the axes.

3.b

Plot the cumulative density function of X for all x between 0 and 50, be sure to add a title and label to the axes.

3.c

Find the probability X<27.4

## [1] 0.7816395

3.d

Find the probability 17.3 <X<27.4

## [1] 0.258114

Complete R Code

It is a good idea to include this at the end of every RMarkdown document

#Discrete
#1.a
plot(x=0:25,dbinom(x=0:25,size=25,prob=.12),main="PDF of X",xlab="X",ylab="P(X)")
#1.b
dbinom(3,25,.12)
#1.c
pbinom(25,25,.12)-pbinom(2,25,.12)
#2.a
plot(x=10:20,dpois(x=10:20,lambda=14.25),main="PDF of X",xlab="X",ylab="P(X)")
#2.b
dpois(14,14.25)
#2.c
ppois(12,14.25)

#Continuous
#1.a
curve(dnorm(x,20,.5),10,30,main="PDF of X",xlab="X",ylab="P(X)")
#1.b
curve(pnorm(x,20,.5),10,30,main="CDF of X",xlab="X",ylab="F(X)")
#1.c
pnorm(19.73,20,.5)
#1.d
pnorm(19.73,20,.5)-pnorm(18.5,20,.5)
#2.a
curve(dexp(x,.2),0,25,main="PDF of X",xlab="X",ylab="P(X)")
#2.b
curve(pexp(x,.2),0,25,main="CDF of X",xlab="X",ylab="F(X)")
#2.c
pexp(10.27,.2)
#2.d
pexp(10.27,.2)-pexp(3.84,.2)
#3.a
curve(dgamma(x,shape=2.3,scale=8.4),0,50,main="PDF of X",xlab="X",ylab="P(X)")
#3.b
curve(pgamma(x,shape=2.3,scale=8.4),0,50,main="CDF of X",xlab="X",ylab="F(X)")
#3.c
pgamma(27.4,shape=2.3,scale=8.4)
#3.d
pgamma(27.4,shape=2.3,scale=8.4)-pgamma(17.3,shape=2.3,scale=8.4)