In this vignette, we demonstrate the Central Limit Theorem (CLT)
using the demo_clt() function. The CLT states that,
regardless of the original population distribution, the distribution of
the sample mean approaches a normal distribution as the sample size
increases.
Here, we use the Gamma distribution with varying skewness, which is
controlled by the shape parameter:
We explore the behavior of the sample mean for different sample sizes
(n = 5, 10, 20, 40) to illustrate the convergence towards
the normal distribution.
The Gamma distribution with shape = 0.5 is highly
skewed. We expect to see the sample mean distribution becoming more
normal as the sample size increases.
demo_clt(rgamma, n = c(5, 10, 20, 40), nrep = 1000,
shape = 0.5, rate = 1, pmean = 0.5, psd = sqrt(0.5))The Gamma distribution with shape = 1 is equivalent to
the Exponential distribution. This example has moderate skewness, and we
observe the effect of increasing the sample size.
The Gamma distribution with shape = 2 has less skewness.
Here, the sample mean distribution converges more quickly to a normal
distribution even for smaller sample sizes.
When pmean and psd are not supplied,
demo_clt() estimates them from 100,000 simulated
observations. For instance, consider sampling from the following mixture
distribution.
mymix_rng <- function(n, rate = 0.5) {
ifelse(runif(n) < rate,
rgamma(n, shape = 0.5), rgamma(n, shape = 4))
}
demo_clt(mymix_rng, n = c(5, 10, 20, 40), nrep = 1000)The plots above demonstrate the Central Limit Theorem in action. As
the sample size increases, the distribution of the sample mean
approaches a normal distribution, even for highly skewed underlying
distributions like the Gamma distribution with
shape = 0.5.
This vignette illustrates the robustness of the CLT and its importance in statistical analysis, especially when dealing with non-normal data in biostatistical contexts.