Here is a single exponential example:
library(tidyverse)
# Single Exponential ----
set.seed(1)
n <- 100e3
p <- 0.75
rate <- 1/110000000
distrib <- rexp(n, rate) %>% quantile(p)
analytical <- qexp(p, rate)
Both the distrib
and analytical
methods produce similar results ~152m
However, when I add 3 exponential distributions together the results from distrib
and analytical
diverge:
m9 <- 11000000
m10 <- 34785054
m11 <- 110000000
w9 <- 0.06756349
w10 <- 0.00030828
w11 <- 0.04856016
# Triple Exponential Function ----
r3exp2 <- function(n, w1, w2, w3, m1, m2, m3){
sim <- n
w1 * rexp(sim, 1 / m1) + w2 * rexp(sim, 1 / m2) + w3 * rexp(sim, 1 / m3)
}
q3exp <- function(p, w1, w2, w3, m1, m2, m3) w1 * qexp(p, 1 / m1) + w2 * qexp(p, 1 / m2) + w3 * qexp(p, 1 / m3)
# Output ----
distrib <- r3exp2(n, w9, w10, w11, m9, m10, m11) %>% quantile(p)
analytical <- q3exp(p, w9, w10, w11, m9, m10, m11)
i.e. 8.4m
vs. 8.2m
; this is the case even with a higher number of simulations.
The divergence gets bigger yet when I add more exp distributions.
Are these two approaches (distrib
vs. analytical
) equivalent? I am unsure what is driving the difference.
Thanks.