# Set the seed
# Generate random variable with Gamma distribution
set.seed(0)
n <- 5
lambda <- 5
X <-rgamma(10000, rate=n, shape=lambda)
# Check the summary statistics of the generated random variable
summary(X)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0796 0.6709 0.9330 1.0001 1.2577 4.0783
# Generate observations from the sum of n exponential PDFs
Y <- replicate(n, rexp(10000, lambda))
Y <- rowSums(Y)
# Check the summary statistics of the generated observations
summary(Y)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.09313 0.67040 0.93495 1.00016 1.25784 3.23172
# Generate observations from a single exponential PDF
Z <- rexp(10000, rate = lambda)
# Check the summary statistics of the generated observations
summary(Z)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000208 0.0579385 0.1371881 0.1995976 0.2784449 1.9065101
# Calculate empirical mean and variance of the Gamma PDF
gamma_mean <- mean(X)
gamma_variance <- var(X)
cat("Gamma PDF - Empirical Mean:", gamma_mean, "\n")
## Gamma PDF - Empirical Mean: 1.000132
cat("Gamma PDF - Empirical Variance:", gamma_variance, "\n")
## Gamma PDF - Empirical Variance: 0.1993912
sum_exp_mean <- mean(Y)
sum_exp_variance <- var(Y)
cat("Sum of Exponential PDFs - Empirical Mean:", sum_exp_mean, "\n")
## Sum of Exponential PDFs - Empirical Mean: 1.000158
cat("Sum of Exponential PDFs - Empirical Variance:", sum_exp_variance, "\n")
## Sum of Exponential PDFs - Empirical Variance: 0.201989
exp_mean <- mean(Z)
exp_variance <- var(Z)
cat("Single Exponential PDF - Empirical Mean:", exp_mean, "\n")
## Single Exponential PDF - Empirical Mean: 0.1995976
cat("Single Exponential PDF - Empirical Variance:", exp_variance, "\n")
## Single Exponential PDF - Empirical Variance: 0.03936069
with shape parameter n and scale parameter lambda
E(X)=n * (1/lambda) var(X)=(1/lambda)^2 * n
gamma_mean_derived <- n * 1/lambda
gamma_variance_derived <- n * (1/lambda)^2
cat("Gamma PDF - Expected Value:", gamma_mean_derived, "\n")
## Gamma PDF - Expected Value: 1
cat("Gamma PDF - Expected Variance:", gamma_variance_derived, "\n")
## Gamma PDF - Expected Variance: 0.2
with shape parameter n and scale parameter lambda
E(X)=n / lambda var(X)= n/ lambda^2
sum_exp_mean_derived <- n / (lambda)
sum_exp_variance_derived <- n / (lambda^2)
cat("Sum of Exponential PDFs - Expected Value:", sum_exp_mean_derived, "\n")
## Sum of Exponential PDFs - Expected Value: 1
cat("Sum of Exponential PDFs - Expected Variance:", sum_exp_variance_derived, "\n")
## Sum of Exponential PDFs - Expected Variance: 0.2
E(X)= 1/ lambda var(X)= 1/ lambda^2
exp_mean_derived <- 1/ (lambda)
exp_variance_derived <- 1 / (lambda^2)
cat("Exponential PDFs - Expected Value:", exp_mean_derived, "\n")
## Exponential PDFs - Expected Value: 0.2
cat("Exponential PDFs - Expected Variance:", exp_variance_derived, "\n")
## Exponential PDFs - Expected Variance: 0.04
alt text
alt text
alt text
I liked this simple linear method as it was super clear, and easily
noticed from the prior Expected Value