Skip to contents

Fit a generic mixture using an ECME-Algorithm

Usage

fit_mixture(
  dist,
  obs,
  start,
  min_iter = 0L,
  max_iter = 100L,
  skip_first_e = FALSE,
  tolerance = 1e-05,
  trace = FALSE,
  ...
)

Arguments

dist

A MixtureDistribution specifying the structure of the mixture. Free parameters are to be optimised. The dominating measure for likelihoods must be constant, so for example dist_dirac() may not have its point parameter free.

obs

Set of observations as produced by trunc_obs() or convertible via as_trunc_obs().

start

Initial values of all placeholder parameters. If missing, starting values are obtained from fit_dist_start().

min_iter

Minimum number of EM-Iterations

max_iter

Maximum number of EM-Iterations (weight updates)

skip_first_e

Skip the first E-Step (update Probability weights)? This can help if the initial values cause a mixture component to vanish in the first E-Step before the starting values can be improved.

tolerance

Numerical tolerance.

trace

Include tracing information in output? If TRUE, additional tracing information will be added to the result list.

...

Passed to fit_dist_start() if start is missing.

Value

A list with elements

  • params the fitted parameters in the same structure as init.

  • params_hist (if trace is TRUE) the history of parameters (after each e- and m- step)

  • iter the number of outer EM-iterations

  • logLik the final log-likelihood

See also

Other distribution fitting functions: fit_blended(), fit_dist(), fit_erlang_mixture()

Examples

dist <- dist_mixture(
  list(
    dist_dirac(0.0),
    dist_exponential()
  )
)

params <- list(
  probs = list(0.1, 0.9),
  dists = list(
    list(),
    list(rate = 1.0)
  )
)

x <- dist$sample(100L, with_params = params)

fit_mixture(dist, x)
#> $params
#> $params$dists
#> $params$dists[[1]]
#> list()
#> 
#> $params$dists[[2]]
#> $params$dists[[2]]$rate
#> [1] 0.8578941
#> 
#> 
#> 
#> $params$probs
#> $params$probs[[1]]
#> [1] 0.11
#> 
#> $params$probs[[2]]
#> [1] 0.89
#> 
#> 
#> 
#> $iter
#> [1] 1
#> 
#> $logLik
#> 'log Lik.' -137.293 (df=2)
#>