mixture {BayesMultiMode}R Documentation

Creating a S3 object of class mixture

Description

Creates an object of class mixture which can subsequently be used as argument in mix_mode() for mode estimation.

Usage

mixture(
  pars,
  dist = NA_character_,
  pdf_func = NULL,
  dist_type = NA_character_,
  range,
  loc = NA_character_
)

Arguments

pars

Named vector of mixture parameters.

dist

Distribution family of the mixture components supported by the package (i.e. "normal", "student", "skew_normal" or "shifted_poisson"). If left unspecified, pdf_func is required.

pdf_func

(function) Pdf or pmf of the mixture components; this input is used only if dist is left unspecified. pdf_func should have two arguments : (i) the observation where the pdf is evaluated; (ii) a named vector representing the function parameters. For instance a normal pdf would take the form: pdf_func <- function(x, par) dnorm(x, par['mu'], par['sigma']). The names of par should correspond to variables in pars, e.g. "mu1", "mu2" etc...

dist_type

Type of the distribution, either "continuous" or "discrete".

range

upper and lower limit of the range where the mixture should be evaluated.

loc

(for continuous mixtures other than Normal mixtures) String indicating the location parameter of the distribution; the latter is used to initialise the MEM algorithm.

Value

A list of class mixture containing:

pars

Same as argument.

pars_names

Names of the parameters of the components' distribution.

dist

Same as argument.

pdf_func

Pdf (or pmf) of the mixture components.

dist_type

Same as argument.

loc

Type of the distribution, either "continuous" or "discrete".

nb_var

Number of parameters in the mixture distribution.

K

Number of mixture components.

range

Same as argument.

Examples


# Example with the skew normal =============================================
xi = c(0,6)
omega = c(1,2)
alpha = c(0,0)
p = c(0.8,0.2)
params = c(eta = p, xi = xi, omega = omega, alpha = alpha)
dist = "skew_normal"

mix = mixture(params, dist = dist, range = c(-2,10))

# summary(mix)
# plot(mix)

# Example with an arbitrary distribution ===================================
mu = c(0,6)
omega = c(1,2)
xi = c(0,0)
nu = c(3,100)
p = c(0.8,0.2)
params = c(eta = p, mu = mu, sigma = omega, xi = xi, nu = nu)

pdf_func <- function(x, pars) {
  sn::dst(x, pars["mu"], pars["sigma"], pars["xi"], pars["nu"])
}


mix = mixture(params, pdf_func = pdf_func,
dist_type = "continuous", loc = "mu", range = c(-2,10))

# summary(mix)
# plot(mix, from = -4, to = 4)


[Package BayesMultiMode version 0.7.1 Index]