Rexp – Simulating Exponential Distributions Using R

This article about R’s rexp function is part of a series  about generating random numbers using R. The rexp function can be used to simulate the exponential distribution. It is commonly used to model the expected lifetimes of an item.

Our earlier articles in this series dealt with:

R and the Exponential Distribution

We’re going to start by introducing the rexp function and then discuss how to use it.

The exponential distribution is concerned with the amount of time until a specific event occurs. For example, the amount of time until the next rain storm likely has an exponential probability distribution. Other random variable examples include the mean simulation duration of long distance telephone calls, and the mean amount of time until an electronics component fails.

For an exponential density function, there are few large data values and more smaller data values. For example, if we look at customer purchases in a store, there usually a few large customers and many smaller ones.

The exponential probability distribution function is widely used in the field of reliability. Reliability deals with the amount of time a product or value lasts.

The exponential distribution function is an appropriate model if the following expression and parameter conditions are true.

  • X is the time (or distance) between events, with X > 0.
  • The events occur independently. That is to say, the occurrence of one event does not affect the probability that a second event will occur.
  • The rate at which events occur is constant for all intervals in the sample size.
  • Two events cannot occur at exactly the same instant.

The Rexp in R function generates values from the exponential distribution and return the results, similar to the dexp exponential function. The exponential density function, the dexp exponential function, and the rexp cumulative distribution function take two arguments:

  • Number of observations you want to see
  • The estimated rate of events for the distribution; this is usually 1/expected service life or wait time

The expected syntax is:

# r rexp - exponential distribution in r
rexp(# observations, rate=rate )

For this Rexp in R function example, lets assume we have six computers, each of which is expected to last an average of seven years. Can we simulate the expected failure dates for this set of machines?

# r rexp - exponential distribution in r
rexp(6, 1/7)
[1] 10.1491772 2.9553524 24.1631472 0.5969158 1.7017422 2.7811142

Related Topics

This is part of our series on sampling in R. To hop ahead, select one of the following links. We discuss the Poisson distribution and the Poisson process, as well as how to get a standard normal distribution, a weibull distribution, a uniform distribution, a gamma distribution, and how to perform a Monte Carlo simulation:

Scroll to top
Privacy Policy