1. Introduction
Computational statistics has gained significant importance in recent years due to the exponential growth of data and the increasing complexity of data-driven problems. Within computational statistics, the ability to simulate or generate random samples from a probability distribution is fundamental. These generated random samples are utilized for estimating probabilities, expectations, and testing hypotheses. The inverse transform method and the acceptance–rejection method are two of the most fundamental techniques for generating random samples, and these can be found in well-known computational statistics textbooks such as
Statistical Computing with R by [
1]. These methods rely on generating numbers from the uniform
distribution. The choice of method depends on the specific distribution being generated and the desired properties of the generated sample, such as efficiency or accuracy.
In certain cases, the data may not conform to commonly known distributions such as the normal or exponential distributions. Instead, they can be represented as a finite mixture model, which combines multiple probability density functions in a convex manner. These models find applications in various scientific domains. For instance, normal mixture distributions are used as parametric density estimators [
2], whereas finite mixture models are employed in medical studies [
3] and financial analyses [
4]. Finite mixture models have also been used by [
5] in the analysis of wind speeds, and Ref. [
6] have demonstrated their usefulness in Bayesian density estimation. Furthermore, Ref. [
7] provide a comprehensive overview of the different applications of mixture models.
Sampling from finite mixture models is a standard topic covered in many computational statistics textbooks, including works by [
1,
8], among others. In these texts, the primary approach for sampling from finite mixture models is typically the
composition method. However, although the composition method is effective, it does not directly use the uniform distribution.
The goal of this paper is to modify the standard composition algorithm by incorporating sampling from the uniform distribution to ensure consistency with primary sampling algorithms such as the inverse transform method and the acceptance–rejection method. This aspect could prove beneficial in teaching computational statistics courses, as sampling from the uniform distribution becomes a standard step in various sampling algorithms.
The remainder of this paper is organized as follows.
Section 2 provides a relevant background on finite mixture models and discusses the proposed modification.
Section 3 presents several examples demonstrating the effectiveness of the proposed method. Finally,
Section 4 offers concluding remarks.
2. Finite Mixture Models and Simulation Theorem
In this section, we define a finite mixture model and introduce a theorem for sampling this model via an adaptation of the composition method. The proof of this theorem is also included.
A finite mixture model is a statistical model that represents a probability distribution as a mixture of several component distributions. Mathematically, given
k component distributions
, each with associated
mixing probabilities (also known as
mixing weights)
, a
finite mixture model is defined as:
where
and
. Further insights into Equation (
1) can be found in studies by [
9,
10].
In the literature, simulating a variable from a finite
k-mixture distribution is typically carried out by the composition method [
1,
11]:
The following theorem introduces an algorithm for generating a sample from (
1). This theorem presents a modified version of the composition method, utilizing the uniform distribution. Aligning with well-established algorithms such as the inverse transform and acceptance–rejection method enhances accessibility for learners.
Theorem 1. Consider as defined in (1). The following algorithm generates a random variate from X with the cumulative distribution function : - 1.
Generate a random u from the uniform (0, 1) distribution;
- 2.
If , generate a random x from , where , with the convention that .
Proof. We show that the generated sample has the same distribution as
X. By the law of total probability, we have
□
The proof of Theorem 1 reveals that the approach is overly general, encompassing not only mixtures of continuous distributions but also extending to other scenarios. This includes mixtures involving continuous and discrete distributions, as well as mixtures comprising only discrete distributions. Additionally, the framework can be extended to sample mixtures of multivariate distributions. In the following section, we explore specific examples that illustrate these various cases.
3. Examples
In this section, we demonstrate the proposed algorithm outlined in Theorem 1 with six illustrative examples. The
R code is provided in the
Supplementary Materials.
Example 1. Mixture of three normal distributions [10]. Suppose
,
, and
are independent. Let
Using Theorem 1, we generated a sample of size
from
.
Figure 1 shows the histogram of the generated sample with the true density superimposed. It is evident from
Figure 1 that the proposed method performs exceptionally well in this example.
Example 2. Mixture of five gamma distributions: different shapes with same scale parameters [1]. Consider
where
amma
are independent and the mixing probabilities are
. Using Theorem 1, we generated a sample of size
from
.
Figure 2 displays the histogram plot of the generated sample with the true density superimposed. The proposed procedure also performs well in this example.
Example 3. Mixture of five gamma distributions: different scale with same shape parameters.
Let
be as described in Example 2, with
. Employing Theorem 1, we generated a sample of size
from
.
Figure 3 presents the histogram plot of the generated sample with the true density superimposed. The proposed procedure demonstrates effective performance in this example as well.
Example 4. Comparing empirical and true mixed distributions.
In this example, we compare
, the empirical cumulative distribution function (ECDF) of the simulated data, with the true mixed distribution
where
represents three cases:
Case 1: , , and . Here, represents the t distribution with degrees of freedom;
Case 2: , , and ;
Case 3: , , and . Here, is the Pareto distribution with as the minimum possible value (scale parameter) and as the shape parameter.
In all three cases, we let
and
. As a measure of proximity, we utilize the Cramér–von Mises distance defined as
We examine various sample sizes
. For each generated sample
, we estimate
D using
For each sample, we compute
values of
and report
and
, representing the mean and standard deviation of the
values of
. Additionally, for comparison, we include results obtained using samples generated from the composition method described in
Section 2. The results are reported in
Table 1. It is clear that both simulation algorithms work well as both
and
approach zero, especially as we increase the sample size.
Example 5. Mixture of four binomial distributions [12]. Consider
where
are independent, with
,
,
, and
. The mixing probabilities are
and
. Using Theorem 1, a sample of size
was generated from
. For comparison, we analyzed the theoretical mean and variance alongside the sample mean and variance. As stated by [
9], we have
and
. In this example,
and
. Thus,
and
. Additionally, the sample mean and variance are 16.2050 and 106.9789, respectively. This indicates a close correspondence between the theoretical and sample statistics.
Example 6. Mixture of normal and Poisson distributions.
Consider the mixture distribution given by
where
follows a normal distribution with mean 10 and variance 4 and
follows a Poisson distribution with mean 4.
and
are independent. Utilizing Theorem 1, a sample of size
was generated from
. As in Example 4, the exact mean and the exact variance of the mixture distribution are
and
. Additionally, the simulated mean and variance of the mixture distribution are 8.4963 and 9.5485, respectively. This demonstrates a close correspondence between the theoretical and sample statistics.
4. Conclusions
This paper introduces a modified version of the composition method for sampling finite mixture distributions. By incorporating sampling from the uniform distribution, our modification aligns with prevalent methods in computational statistics, such as the inverse transform and acceptance–rejection methods. This modification not only enhances the consistency and accuracy of sampling procedures but also simplifies the teaching of computational statistics courses, where sampling from the uniform distribution is a common step in various algorithms.
The effectiveness of the proposed modification is demonstrated through several illustrative examples, showcasing its robust performance across different scenarios. From mixtures of normal and gamma distributions to binomial and Poisson mixtures, the proposed algorithm consistently generates samples that closely match the theoretical distributions. Moreover, comparison metrics such as the Cramér–von Mises distance provide quantitative evidence of the algorithm’s efficiency and accuracy, especially as sample sizes increase.
Overall, the modified composition method presented in this paper offers a valuable addition to the toolkit of computational statisticians and educators alike. Its simplicity, consistency, and performance make it a practical choice for sampling finite mixture distributions in various applications.