The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.

mean— title: “Demonstrating the Central Limit Theorem” author: “Companion Package for Biostatistical Analysis of Proportions and Rates” date: “2026-09-01” output: rmarkdown::html_vignette vignette: > % % % —

Introduction

In this vignette, we demonstrate the Central Limit Theorem (CLT) using the cltdemo() 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.

Load Required Packages

Gamma Distribution with Shape = 0.5

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 = 10000,
         shape = 0.5, rate = 1, pmean = 0.5, psd = sqrt(0.5))

Gamma Distribution with Shape = 1

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.

demo_clt(rgamma, n = c(5, 10, 20, 40), nrep = 10000,
         shape = 1, rate = 1, pmean = 1, psd = sqrt(1))

Gamma Distribution with Shape = 2

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.

demo_clt(rgamma, n = c(5, 10, 20, 40), nrep = 10000,
         shape = 2, rate = 1, pmean = 2, psd = sqrt(2))

A General Distribution Constructed from a Mixture

When the population mean and sd are unspecified, the will be approximated by a large sample (10,000) and then used in standardization. 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))

Conclusion

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.

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.