The pdf of exponential distribution is given as
`f(x; \theta) = \frac{1}{\theta} e^{-x / \theta}, \quad x \geq 0, \, \theta > 0.`
The MLE estimator is given by considering the likelihood function
`L(\theta ; X) = \prod_{i=1}^n f(x_i; \theta) = \prod_{i=1}^n \frac{1}{\theta} e^{-x_i / \theta}.`
`L(\theta; X) = \frac{1}{\theta^n} exp{-\sum_{i=1}^n x_i / \theta}.`
Now taking log both sides to make calculus easy
`\log L(\theta) = \log \left( \frac{1}{\theta^n} exp({-\frac{\sum_{i=1}^n x_i}{\theta}}) \right).`
`\log L(\theta) = -n \log \theta - \frac{\sum_{i=1}^n x_i}{\theta}.`
Differentiating partially with respect to `theta` both sides
`\frac{\partial \log L(\theta)}{\partial \theta} = -\frac{n}{\theta} + \frac{\sum_{i=1}^n x_i}{\theta^2}.`
Putting it equal to zero
`-\frac{n}{\theta} + \frac{\sum_{i=1}^n x_i}{\theta^2} = 0.`
`\frac{\sum_{i=1}^n x_i}{\theta^2} = \frac{n}{\theta}.`
`\sum_{i=1}^n x_i = n \theta.`
`\hat \theta_{MLE}= \frac{\sum_{i=1}^n x_i}{n}.`
# R code to plot an exponential distribution curve
# Define the rate parameter (lambda = 1/theta)
lambda <- class="keyword" span="">as.numeric->