Exponential Distribution

Exponential distribution is closely related to the Poisson distribution of the discrete case. Like the Poisson distribution, it takes one parameter $\lambda$ which is the rate of events. The exponential distributions measure the time between two events. Below are a few examples of variables that can be modeled with the Exponential Distribution:

  1. How long does it take until a customer service call is answered
  2. How long does it take until a new machine breaks

If you think about it, the exponential distribution is similar to the discrete geometric distribution. If you recall, the geometric distribution models the number of trials until the first success is observed.

We represent the exponential distribution at:


$$ X \sim Exponential(\lambda) $$

where:
$x$: Random variable for time between two events
$\lambda$: is the rate of the distribution and $\lambda > 0$

Exponential Random Variable

Using scipy's expon method, we can generate a random variable from the exponential family. We provide the parameters for the distribution $\mu$ and $\lambda$ which are with the key arguments $loc$ and $scale$ respectively.

$loc$: this is the mean/expected value of the distribution
$scale$: this is equivalent to $\frac{1}{\lambda}$ parameter of the distribution

In the example below, we generate a random variable with expected time of $\mu = 4$ means and a rate of $.2$ i.e $scale = \frac{1}{.2} $

from scipy.stats import expon
expon.rvs(loc=4, scale=1/.2 , size=30 )
array([ 4.61397992, 25.58160681, 4.97118544, 10.82037415, 4.59582235, 6.36692955, 8.00951997, 7.62542535, 10.30687284, 9.29939128, 14.18148262, 9.55711778, 7.19650536, 5.46086883, 5.99450672, 4.51232981, 8.78213477, 9.40221657, 8.74229273, 11.87403468, 30.07051703, 5.95930671, 6.08870077, 15.87018507, 9.90876996, 22.52538556, 15.36645721, 10.37153076, 4.05751705, 13.24346723])

Visualization

Visualizing the exponential distribution can tell us a great deal about the random variables that follow this family of distribution by change the rate parameter. In the example below, we generate a few random variables with the same mean but varying rates $\lambda$ parameters

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace( 1, 10, 50 )

lambda_low = .5* np.exp( -.5 * x )
lambda_med = .9* np.exp( -.9 * x )
lambda_high = 2* np.exp( -2 * x )

plt.plot( lambda_low,  label='λ =.5', linewidth=2.5, linestyle='-.' )
plt.plot( lambda_med,  label='λ = 1', linewidth=2.5, linestyle='--' )
plt.plot( lambda_high, label='λ = 4', linewidth=2, linestyle='-' )
plt.legend()
Exponential Distribution

Probability Density Function

The probability density function of the exponential distribution is given in the form below:

$$ p(x) = \begin{cases} \lambda e^{-\lambda x} & x > 0 \\ 0 & \text{ otherwise } \\ \end{cases} $$

Its to be noted that both the $x$ and $\lambda$ parameter are always positive.

Example
Suppose that the call times of customer service support follows a normal distribution with $\lambda = 1/5$. Given that someone just called ahead of you for customer service support, what is the probability that you will wait for 5 minutes before you are the next call?

Recall that the $scale$ argument is $\frac {1}{\lambda}$ therefore $\lambda = 5$ means $scale = \frac{1}{5}$

expon.pdf(x=5, scale=5)
0.07357588823428847

Expected Value

The expected value of the exponential distribution is given by the generalized formula:

$$ E(X) = \frac {1}{\lambda} $$

In the example below, we initialize a random variable with the $scale = 4$ paramater. Notice that the $\lambda = \frac {1}{4}$.

x_var = expon.rvs(scale=4, size=1000 )
x_var.mean()
4.107944535291936

Variance

The variance value of the exponential distribution is given by the generalized formular:

$$ Var(X) = \frac {1}{\lambda^2}$$

x_var = expon.rvs(scale=4, size=1000 )
x_var.var()
16.1703604399666

Standard Deviation

The standard deviation of the exponential distribution is the square root of the variance above.

$$ \sigma = \frac {1}{\lambda} $$

x_var = expon.rvs(scale=4, size=10000 )
x_var.std()
3.9362902161922753