In the following some of the most important members of the Exponential Family distributions.
The next subsections introduce one example per distribution and how to calculate relevant quantities about them in R.
This is a typical situation where a G distribution is useful:
In a biomedical study with rats, a dose-response investigation is used to determine the effect of the dose of a toxicant on their survival time. The toxicant is one that is frequently discharged into the atmosphere from jet fuel. For a certain dose of the toxicant, the study determines that the survival time, in weeks, has a Gamma distribution with a = 5 and s = 10. What is the probability that a rat survives no longer than 60 weeks? Walpole et. al (2012), pag. 198.
The mean and variance expressions of a \(G(a,s)\) are: \(E(X) = s/a\), \(Var(X) = as^2\), respectively.
Some examples, with different parameters values of the density function of a G distribution:
soporte <- seq(0.01,10,length=50)
s <- 1
a <- 0.8
valores1_fd <- dgamma(soporte,shape=s,scale=a)
plot(soporte,valores1_fd,type='l',main="Gamma Densities")
a2 <- 3
valores2_fd <- dgamma(soporte,shape=s,scale=a2)
points(soporte,valores2_fd,type='l',col=2)
s2 <- 2
valores3_fd <- dgamma(soporte,shape=s2,scale=a)
points(soporte,valores3_fd,type='l',col=3)
In this subsection we illustrate how to generate a random sample of a G distribution.
datos_G <- rgamma(20000,shape=s,scale=a)
hist(datos_G,main="Histogram of Gamma data")
# True mean
MT <- s*a
MT
## [1] 0.8
# Sample mean
mean(datos_G)
## [1] 0.797204
# True variance
VART <- a*(s^2)
VART
## [1] 0.8
# Sample variance
round(var(datos_G),2)
## [1] 0.64
We can calculate the cumulative distribution function at \(x\), \(F_X(x) =P(X \leq x)\), as follows,
pgamma(1,shape=s,scale=a)
## [1] 0.7134952
# Empirical check
p_emp <- mean(datos_G < 1)
p_emp
## [1] 0.71595
This is an example of how to obtain the r quantile of a G distribution:
q_10 <- qgamma(0.1,shape=s,scale=a)
q_10
## [1] 0.08428841
# Empirical check
r_emp <- mean(datos_G <= q_10)
r_emp
## [1] 0.103
The IG has been useful modeling failure times for air conditioning in Boeing 720 jets and levels of precipitation in storms, D. J. Best (2012) et. al. Advances of Decision Sciences, doi:10.1155/2012/150303.
The mean and variance expressions of a \(IG(\mu,\phi)\) are: \(E(X) = \mu\), \(Var(X) = \phi\mu^3\), respectively.
Some examples, with different parameters values of the density function of a IG distribution:
# In this case we are using the package "statmod"
require(statmod)
## Loading required package: statmod
## Warning: package 'statmod' was built under R version 3.6.3
soporte <- seq(0.01,6,length=200)
mu <- 1
phi <- 0.8
valores1_fd <- dinvgauss(soporte,mean=mu,dispersion=phi)
plot(soporte,valores1_fd,type='l',main="Inverse Gaussian Densities ",ylim=c(0,1.5))
mu2 <- 3
valores2_fd <- dinvgauss(soporte,mean=mu2,dispersion=phi)
points(soporte,valores2_fd,type='l',col=2)
phi2 <- 2
valores3_fd <- dinvgauss(soporte,mean=mu,dispersion=phi2)
points(soporte,valores3_fd,type='l',col=3)
In this subsection we illustrate how to generate a random sample of a IG distribution.
datos_IG <- rinvgauss(20000,mean=mu,dispersion=phi)
hist(datos_IG,main="Histogram of Inverse Gaussian Data")
# True mean
MT <- mu
MT
## [1] 1
# Sample mean
mean(datos_IG)
## [1] 1.008163
# True variance
VART <- phi*(mu^3)
VART
## [1] 0.8
# Sample variance
round(var(datos_IG),3)
## [1] 0.825
We can calculate the cumulative distribution function at \(x\), \(F_X(x) =P(X \leq x)\), as follows,
pinvgauss(1,mean=mu,dispersion=phi)
## [1] 0.6543968
# Empirical check
p_emp <- mean(datos_IG < 1)
p_emp
## [1] 0.6546
This is an example of how to obtain the r quantile of a IG distribution:
r <- 0.1
q_10 <- qinvgauss(r,mean=mu,dispersion=phi)
q_10
## [1] 0.2738706
# Empirical check
r_emp <- mean(datos_IG <= q_10)
round(r_emp,3)
## [1] 0.1
This is a typical situation where a B distribution is useful:
The probability that a patient recovers from a rare blood disease is 0.4. If 15 people are known to have contracted this disease, what is the probability that
a- at least 10 survive
b- from 3 to 8 survive, and
c- exactly 5 survive? Walpole et. al (2012), pag. 146.
The mean and variance expressions of a \(B(p,n)\) are: \(E(X) = np\), \(Var(X) = n(1-p)p\), respectively.
Some examples, with different parameters values of the density function of a B distribution:
p <- 0.2
size <- 20
par(mfrow = c(1,3))
soporte <- seq(0,size)
valores1_fd <- dbinom(soporte,prob=p,size=size)
plot(soporte,valores1_fd,type='h',ylab= " ",main="B Densities")
p2 <- 0.4
valores2_fd <- dbinom(soporte,prob=p2,size=size)
plot(soporte,valores2_fd,type='h',col=2)
p3 <- 0.7
valores3_fd <- dbinom(soporte,prob=p3,size=size)
plot(soporte,valores3_fd,type='h',col=3)
In this subsection we illustrate how to generate a random sample of a B distribution.
set.seed(2020)
datos_B <- rbinom(10000,prob=p,size=size)
hist(datos_B,main="Histogram of Binomial Data")
# True mean
MT <- p*size
MT
## [1] 4
# Sample mean
mean(datos_B)
## [1] 3.9787
# True variance
VART <- p*(1-p)*size
VART
## [1] 3.2
# Sample variance
round(var(datos_B),2)
## [1] 3.18
We can calculate the cumulative distribution function at \(x\), \(F_X(x) =P(X \leq x)\), as follows,
x <- 1
pbinom(x,prob=p,size=size)
## [1] 0.06917529
# Empirical probability
p_emp <- mean(datos_B <= x)
p_emp
## [1] 0.0716
This is an example of how to obtain the r quantile of a B distribution:
r <- 0.5
q_50 <- qbinom(r,prob=p,size=size,lower.tail=TRUE)
q_50
## [1] 4
# Empirical check
r_emp <- mean(datos_B <= q_50)
r_emp
## [1] 0.6343
This is a typical situation where a P distribution is useful:
Hospital administrators in large cities anguish about traffic in emergency rooms. At a particular hospital in a large city, the staff on hand cannot accommodate the patient traffic if there are more than 10 emergency cases in a given hour. It is assumed that patient arrival follows a Poisson process, and historical data suggest that, on the average, 5 emergencies arrive per hour.
a- What is the probability that in a given hour the staff cannot accommodate the patient traffic?
b- What is the probability that more than 20 emergencies arrive during a 3 hour shift?. Walpole et. al \((2012)\), pag. 166.
The mean and variance expressions of a \(P(\lambda)\) are: \(E(X) = \lambda\), \(Var(X) = \lambda\), respectively.
Some examples, with different parameters values of the density function of a P distribution:
soporte <- seq(0,30)
lambda <- 1
par(mfrow = c(1,3))
valores1_fd <- dpois(soporte,lambda)
plot(soporte,valores1_fd,type='h',main="P Densities")
lambda2 <- 9
valores2_fd <- dpois(soporte,lambda2)
plot(soporte,valores2_fd,type='h',col=2)
lambda3 <- 17
valores3_fd <- dpois(soporte,lambda3)
plot(soporte,valores3_fd,type='h',col=3)
In this subsection we illustrate how to generate a random sample of a P distribution.
lambda <- 9
datos_P <- rpois(10000,lambda)
hist(datos_P,main="Histogram of Poisson Data")
# True mean
lambda
## [1] 9
# Sample mean
mean(datos_P)
## [1] 9.0176
# True variance
lambda
## [1] 9
# Sample variance
round(var(datos_P),2)
## [1] 8.87
We can calculate the cumulative distribution function at \(x\), \(F_X(x) =P(X \leq x)\), as follows,
x <- 3
round(ppois(x,lambda),2)
## [1] 0.02
# Empirical probability
p_emp <- mean(datos_P <= x)
p_emp
## [1] 0.0182
This is an example of how to obtain the r quantile of a P distribution:
r <- 0.4
q_40 <- qpois(r,9,lower.tail=TRUE)
q_40
## [1] 8
# Empirical Check
r_emp <- mean(datos_P <= q_40)
r_emp
## [1] 0.4546
This is a typical situation where a NB distribution is useful:
Consider the use of a drug that is known to be effective in \(60%\) of the cases where it is used. The drug will be considered a success if it is effective in bringing some degree of relief to the patient. We are interested in finding the probability that the fifth patient to experience relief is the seventh patient to receive the drug during a given week. Walpole et. al \((2012)\), pag. 158.
The mean and variance expressions of a \(NB(k,p)\) are: \(E(X) = k(1-p)/p\), \(Var(X) = k(1-p)/p^2\), respectively.
Some examples, with different parameters values of the density function of a NB distribution:
soporte <- seq(0,25)
p <- 0.75
k <- 2
par(mfrow = c(2,2))
valores1_fd <- dnbinom(soporte,prob=p,size=k)
plot(soporte,valores1_fd,type='h',main="NB Density")
p2 <- 0.5
valores2_fd <- dnbinom(soporte,prob=p2,size=k)
plot(soporte,valores2_fd,type='h',col=2)
k <- 5
valores3_fd <- dnbinom(soporte,prob=p2,size=k)
plot(soporte,valores3_fd,type='h',col=3)
k <- 10
valores4_fd <- dnbinom(soporte,prob=p2,size=k)
plot(soporte,valores4_fd,type='h',col=4)
In this subsection we illustrate how to generate a random sample of a NB distribution.
# Number of success
p <- 0.75
size <- 5
datos_NB <- rnbinom(10000,prob=p,size=size)
datos_NB[1:20]
## [1] 2 1 3 4 2 7 1 4 2 2 1 0 2 0 0 3 3 4 1 2
hist(datos_NB,main="Histogram of Negative Binomial Data")
# True mean
MT <- size*(1-p)/p
MT
## [1] 1.666667
# Sample mean
mean(datos_NB)
## [1] 1.6618
# True variance
VART <- size*(1-p)/p^2
VART
## [1] 2.222222
# Sample variance
round(var(datos_NB),2)
## [1] 2.21
We can calculate the cumulative distribution function at \(x\), \(F_X(x) =P(X \leq x)\), as follows,
x <- 5
size <- 5
round(pnbinom(x,p=p,size=size),4)
## [1] 0.9803
# Empirical probability
p_emp <- mean(datos_NB <= x)
p_emp
## [1] 0.9801
This is an example of how to obtain the r quantile of a NB distribution:
r <- 0.5
size <- 5
q_50 <- qnbinom(r,prob=p,size=size,lower.tail=TRUE)
q_50
## [1] 1
# Empirical Check
r_emp <- mean(datos_NB <= q_50)
r_emp
## [1] 0.534