Convergence Test for EM-Algorithm
em_converged(loglik, previous_loglik, tol = 1e-04, check.increased = FALSE)
numeric. Current value of the log-likelihood function.
numeric. Value of the log-likelihood function at the previous iteration.
numerical. The tolerance of the test. If |LL(t) - LL(t-1)| / avg < tol, where avg = (|LL(t)| + |LL(t-1)|)/2, then algorithm has converged.
logical. Check if likelihood has increased.
A logical statement indicating whether EM algorithm has converged. if check.increased = TRUE
, a vector with 2 elements indicating the convergence status and whether the likelihood has decreased.
em_converged(1001, 1000)
#> [1] FALSE
em_converged(10001, 10000)
#> [1] TRUE
em_converged(10001, 10000, check = TRUE)
#> converged decrease
#> TRUE FALSE
em_converged(10000, 10001, check = TRUE)
#> converged decrease
#> TRUE TRUE