This function implements the Expectation-Maximization (EM) algorithm, which iteratively optimizes model parameters by alternating between an E-step (Expectation step) and an M-step (Maximization step). The algorithm is used for parameter estimation in latent variable models, with different model types like "M0", "M1", "M2", and "M3".
Usage
EM(
data,
par0,
types,
tol1 = 0.001,
max_iter,
t_list,
u_list,
model,
n_points = n_points,
n_samples = 100,
n_intervals = NULL,
approx.method,
period = c(0, 1),
show_progress = TRUE
)Arguments
- data
Numeric matrix of size `m x n`, where `m` is the number of samples and `n` is the number of variables.
- par0
Numeric vector of initial model parameters.
- types
Character vector specifying the model types for each variable.
- tol1
Numeric value, the tolerance for convergence. The algorithm stops if the parameter change is below this threshold.
- max_iter
Integer, the maximum number of iterations for the EM algorithm.
- t_list
List, contains the `t` values for each variable (used in Lambda calculations).
- u_list
List, contains the `u` values for each variable (used in Lambda calculations).
- model
Character, the model type ("M0", "M1", "M2", "M3", etc.) to be used in the estimation.
- n_points
Integer, the number of points for Gaussian-Legendre integration.
- n_samples
Integer, the number of random samples for Monte Carlo integration.
- n_intervals
Integer, the number of intervals for Trapezoidal integration.
- approx.method
Character, specifies the numerical method for approximating the expectation ("gl" for Gaussian-Legendre, "mc" for Monte Carlo, or "ti" for Trapezoidal).
- period
Numeric vector of length 2, defining the integration limits (e.g., `c(0,1)`).
- show_progress
Logical, if TRUE, shows a progress bar during iterations.
