####### R Code for the Normalized Spacings of an Exponential Random Sample ####### # # If X[1], X[2], ... X[n] are iid Exponential(theta) RVs, and we # define their "Normalized Spacings" as # # Y[j] = (n-j+1)[X(j) - X(j-1)], for j = 1, 2,..., n # # then Y[1], Y[2], ... Y[n] are also iid Exponential(theta) RVs. # # This result is called the Renyi Representation of Exponentials. # Intuitively, this result is a consequence of the Memoryless Proprty # of the Exponential Distribution. # # n = sample size # mean.expo = Exponential expected value Spacings.fn <- function(n, mean.expo){ ### Generate a random sample of Exponential RVs ### X <- rexp(n, rate = 1/mean.expo) ### Define the Normalized Spacings of the Sample ### ### Define the Order Statistics of the Sample ### index <- c(rep(NA, n)) Y <- c(rep(NA, n)) Z <- c(0, sort(X)) for(j in 1:n){ Y[j] <- (n - j + 1)*(Z[j+1] - Z[j]) } for(j in 1:(n+1)){ index[j] <- j-1 } normalized.spacings <- c(0, Y) order.stats <- Z print(cbind(index, order.stats, normalized.spacings)) print(summary(X)) print(summary(Y)) par(mfrow = c(2,2)) hist(X, freq = FALSE, main = "Histogram of Exponential Data") hist(Y, freq = FALSE, main = "Histogram of\n Normalized Spacings") qqplot(x = X, y = Y, main = "QQ Plot", xlab = "Quantiles of the Exponential Data", ylab = "Quantiles of the Normalized Spacings") abline(a = 0, b = 1, lty = 1) } ### Example ### Spacings.fn(250, 7.5)