Derivation of PDF, CDF, Quantiles, Mean, and Variance
Parameter visualizations & R implementation
Applied Problems: Real-world examples solved analytically and in R
Part I: Discrete Waiting Times
From Geometric to Negative Binomial
Bernoulli Trial: Independent trials with success probability \(p \in (0, 1)\) and failure probability \(q = 1 - p\).
Geometric Distribution: Models the number of failures\(X\) before the 1st success (or total trials \(Y = X + 1\)).
Negative Binomial Distribution: Generalizes the Geometric by modeling the number of failures\(X\) before the \(r\)-th success (\(r \in \mathbb{Z}^+\)).
Because \(X\) is discrete, the quantile function for probability \(u \in (0, 1)\) is the smallest integer \(x\) satisfying the CDF threshold:
\[Q(u) = \inf \{ x \in \mathbb{Z}_{\ge 0} : F(x) \ge u \}\]
Negative Binomial: Mean & Variance
Since \(X\) is the sum of \(r\) independent \(\text{Geom}(p)\) random variables (\(X = \sum_{i=1}^r G_i\)), we use linearity of expectation and independence:
PMF CDF Quantile_90 Mean Variance
0.04913443 0.30181012 28.00000000 16.00000000 80.00000000
Part II: Continuous Waiting Times
From Exponential to Gamma
Poisson Process: Events occur continuously and independently at a constant average rate \(\lambda > 0\).
Exponential Distribution: Models the continuous waiting time \(T_1\) until the 1st event.
Gamma Distribution: Generalizes the Exponential by modeling the total waiting time \(Y = \sum_{i=1}^{\alpha} T_i\) until the \(\alpha\)-th event (shape \(\alpha > 0\), rate \(\lambda > 0\)).
(For integer \(\alpha = n\), this simplifies to \(F(y) = 1 - \sum_{k=0}^{n-1} \frac{(\lambda y)^k e^{-\lambda y}}{k!}\)).
Quantile Function
Because \(F(y)\) has no closed-form elementary inverse for general \(\alpha\), \(Q(u) = F^{-1}(u)\) for \(u \in (0, 1)\) is computed numerically via root-finding algorithms.
Gamma: Mean & Variance
Using the definition of \(\Gamma(\alpha)\) and the property \(\Gamma(\alpha + 1) = \alpha\Gamma(\alpha)\):
Mean (\(E[Y]\))
\[E[Y] = \int_0^\infty y \frac{\lambda^\alpha}{\Gamma(\alpha)} y^{\alpha-1} e^{-\lambda y} \, dy = \frac{\lambda^\alpha}{\Gamma(\alpha)} \frac{\Gamma(\alpha+1)}{\lambda^{\alpha+1}} = \frac{\alpha}{\lambda}\]
y <-seq(0.01, 20, length.out =300)df_gam <-expand.grid(y = y, alpha =c(1, 2, 5), rate =c(0.5, 1))df_gam$pdf <-dgamma(df_gam$y, shape = df_gam$alpha, rate = df_gam$rate)df_gam$params <-paste0("α = ", df_gam$alpha, ", λ = ", df_gam$rate)ggplot(df_gam, aes(x = y, y = pdf, color = params)) +geom_line(linewidth =1) +ylim(0, 0.6) +labs(title ="Gamma PDF Across Parameters (α = 1 is Exponential)",x ="Waiting Time (y)", y ="Density f(y)", color ="Parameters") +theme_minimal(base_size =13)
Figure 3
Simulating the Gamma Distribution with rgamma()
Using rgamma(n, shape, rate), we generate \(n = 10,000\) random waiting times for \(\alpha = 5\) events arriving at rate \(\lambda = 3\) per hour, and compare the simulated sample to theoretical values:
More about the Distributions Ross, S. M. (2014). A First Course in Probability (9th ed.). Pearson.
Computational Software: R Core Team (2026). R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria. Available at https://www.R-project.org/.
About This Presentation
Content Design: Developed by the instructor to introduce the Negative Binomial Distribution and the Gamma Distribution.
AI Assistance:Google Gemini was provided with a detailed structural prompt to generate the foundational Quarto layout, technical R code chunks, and mathematical explanations and examples.
Verification: All statistical definitions, R code logic, and visualizations were reviewed, verified, and finalized by the instructor for educational accuracy.