dexp, pexp, qexp, and rexpRandom variable \(X\) is distributed \(X \sim Exponential(\theta)\) with mean \(\mu=\theta\) and variance \(\sigma^2 = \theta^2\) if \(X\) is the intervals until the first successful event when the average interval is \(\theta\). The probability of an interval of \(X=x\) \(f(X=n) =\frac{{1}}{{\theta}}e^{-x/\theta}\). The probability of an interval between \(a\) and \(b\) is \(F_X(x) =\int_a^b\frac{{1}}{{\theta}}e^{-x/\theta}dx=e^{-a/\theta}-e^{-b/\theta}\).
R function dexp(x, reate) is the probability of interval x until first successful event when successful events occur with rate =\(1/\theta\). R function pexp(q, rate, lower.tail) is the cumulative probability (lower.tail = TRUE for left tail, lower.tail = FALSE for right tail) of less than or equal to an interval of q prior to success. R function rexp(n, rate) returns n random numbers from the exponential distribution X~Exponential(theta). R function qexp(p, rate, lower.tail) is the interval at the qth percentile (lower.tail = TRUE).
Customers arrive at a rate of 0.5 persons per minutes, \(\lambda\)&=0.50, or \(\theta\)=2. What is the probability of a customer arriving within an interval of x=0 to 3 minutes?
theta = 2
# exact
pexp(q = 3, rate = 1 / theta)
## [1] 0.7768698
# simulated
mean(rexp(n = 10000, rate = 1 / theta) <= 3)
## [1] 0.7795
library(dplyr)
library(ggplot2)
data.frame(x = 0:1000 / 100, prob = pexp(q = 0:1000 / 100, rate = 1 / theta, lower.tail = TRUE)) %>%
mutate(Interval = ifelse(x >= 0 & x <= 3, "0 to 3", "other")) %>%
ggplot(aes(x = x, y = prob, fill = Interval)) +
geom_area(alpha = 0.3) +
labs(title = "Cumulative Probability of Interval X until First Success",
subtitle = "X ~ Exponential(2)",
x = "Interval (x)",
y = "Cum Probability")
Customers arrive at a rate of 0.5 persons per minutes, \(\lambda\)&=0.50, or \(\theta\)=2. What is the probability of a customer not arriving within an interval of x=0 to 3 minutes?
theta = 2
# exact
pexp(q = 3, rate = 1 / theta, lower.tail = FALSE)
## [1] 0.2231302
# simulated
mean(rexp(n = 10000, rate = 1 / theta) > 3)
## [1] 0.2254
library(dplyr)
library(ggplot2)
data.frame(x = 0:1000 / 100, prob = pexp(q = 0:1000 / 100, rate = 1 / theta, lower.tail = TRUE)) %>%
mutate(Interval = ifelse(x > 3, ">3", "other")) %>%
ggplot(aes(x = x, y = prob, fill = Interval)) +
geom_area(alpha = 0.3) +
labs(title = "Cumulative Probability of Interval X until First Success",
subtitle = "X ~ Exponential(2)",
x = "Interval (x)",
y = "Cum Probability")
Customers arrive at a rate of 0.5 persons per minutes, \(\lambda\)&=0.50, or \(\theta\)=2. What is the probability of a customer arriving within an interval of x=3 to 7 minutes?
theta = 2
# exact
pexp(q = 7, rate = 1 / theta) - pexp(q = 3, rate = 1 / theta)
## [1] 0.1929328
library(dplyr)
library(ggplot2)
data.frame(x = 0:1000 / 100, prob = pexp(q = 0:1000 / 100, rate = 1 / theta, lower.tail = TRUE)) %>%
mutate(Interval = ifelse(x > 3 & x <= 7, "3 to 7", "other")) %>%
ggplot(aes(x = x, y = prob, fill = Interval)) +
geom_area(alpha = 0.3) +
labs(title = "Cumulative Probability of Interval X until First Success",
subtitle = "X ~ Exponential(2)",
x = "Interval (x)",
y = "Cum Probability")