Skip to contents

Fit an Erlang mixture using an ECME-Algorithm

Usage

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

Arguments

dist

An ErlangMixtureDistribution. It is assumed, that both probs and scale are to be estimated.

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.

parallel

Enable experimental parallel evaluation of expected log-likelihood?

...

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). Otherwise an empty list.

  • iter the number of outer EM-iterations

  • logLik the final log-likelihood

See also

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

Examples

dist <- dist_erlangmix(list(NULL, NULL, NULL))
params <- list(
  shapes = list(1L, 4L, 12L),
  scale = 2.0,
  probs = list(0.5, 0.3, 0.2)
)
x <- dist$sample(100L, with_params = params)
fit_erlang_mixture(dist, x, init = "kmeans")
#> $params
#> $params$probs
#> $params$probs[[1]]
#> [1] 0.31
#> 
#> $params$probs[[2]]
#> [1] 0.43
#> 
#> $params$probs[[3]]
#> [1] 0.26
#> 
#> 
#> $params$shapes
#> $params$shapes[[1]]
#> [1] 1
#> 
#> $params$shapes[[2]]
#> [1] 4
#> 
#> $params$shapes[[3]]
#> [1] 13
#> 
#> 
#> $params$scale
#> [1] 1.686607
#> 
#> 
#> $params_hist
#> list()
#> 
#> $iter
#> [1] 1
#> 
#> $logLik
#> 'log Lik.' -310.162 (df=6)
#>