Exponential Distribution in R Programming:–
dexp(), pexp(), qexp(), and rexp() Functions
The exponential distribution in R Language is the probability distribution of
the time between events in a Poisson point process, i.e., a process in which
events occur continuously and independently at a constant average rate. It
is a particular case of the gamma distribution. In R Programming Language,
there are 4 built-in functions to generate exponential distribution:
unction
••
Function Description
dexp Probability Density Function
pexp Cumulative Distribution Function
qexp Quantile Function of Exponential Distribution
rexp Generating random numbers which are Exponentially Distributed
Model the time between the event:
In R, you can model the time between events using the exponential distribution by using the
rexp() function, which generates random numbers from an exponential distribution. The
exponential distribution is commonly used to model the time between events in a Poisson
process, where events occur continuously and independently at a constant average rate .
Here's an example of how you can generate random samples from an exponential distribution
in R:
Code:
# Set the parameters
lambda <- 0.2 # Average rate (events per unit time)
# Generate random samples from exponential distribution
n <- 1000 # Number of samples
time_between_events <- rexp(n, rate = lambda)
# Plot the histogram of generated samples
hist(time_between_events, breaks = 30, freq = FALSE,
Ajeet Singh – 21BCS10830
main = "Histogram of Time Between Events",
xlab = "Time between Events",
ylab = "Density",
col = "skyblue")
# Overlay the theoretical density function
curve(dexp(x, rate = lambda), add = TRUE, col = "red", lwd = 2, n = 1000,
label = paste("λ =", lambda))
legend("topright", legend = "Exponential Density Function", col = "red", lwd = 2)
• lambda is the average rate of events per unit time.
• rexp() generates n random samples from the exponential distribution with a rate
parameter of lambda.
• We then plot a histogram of the generated samples and overlay the theoretical density
function of the exponential distribution using curve().
Output:
Ajeet Singh – 21BCS10830