EM: EM algorithm for a univariate Gaussian mixture
Description
Fits a univariate Gaussian mixture model using the Expectation-Maximization (EM)
algorithm. The function is intended as a lightweight fallback implementation
(e.g., when mixtools is unavailable or fails).
Usage
EM(X, K = 2, max_iter = 100, tol = 1e-05)
Value
A list with the following components:
mu
Numeric vector of estimated component means (length K).
sigma
Numeric vector of estimated component standard deviations (length K).
pi
Numeric vector of estimated mixing proportions (length K).
num_iteraciones
Number of iterations performed.
posterior
Matrix of posterior probabilities (responsibilities) with
dimension length(X) by K.
Arguments
X
Numeric vector of observations.
K
Integer. Number of mixture components.
max_iter
Integer. Maximum number of EM iterations.
tol
Positive numeric. Convergence tolerance for the absolute change in
the log-likelihood.
Details
The algorithm is initialized using the k-means clustering procedure
and then alternates between:
E-step: computing the expectation of the complete log-likelihood function.
M-step: maximizing the expectation of the complete log-likelihood function.