Mix: Mixtures of Univariate Distributions

Description Usage Arguments Value See Also Examples

View source: R/0_Mix_utils.R

Description

Function constructing objects of class Mix that represent finite mixtures of any univariate distribution. Additionally methods for printing and plotting are provided.

Usage

1
2
3
4
5
6
Mix(dist, discrete, w = NULL, theta.list = NULL, name = NULL, ...)

is.Mix(x)

## S3 method for class 'Mix'
print(x, ...)

Arguments

dist

character string providing the (abbreviated) name of the component distribution, such that the function ddist evaluates its density function and rdist generates random numbers. The function sources functions for the density/mass estimation and random variate generation from distributions in distributions, so the abbreviations should be specified accordingly. Thus to create a gaussian mixture, set dist = "norm", for a poisson mixture, set dist = "pois". The Mix function will find the functions dnorm, rnorm and dpois, rpois respectively.

discrete

logical flag, should be set to TRUE if the mixture distribution is discrete and to FALSE if continuous.

w

numeric vector of length p, specifying the mixture weights w[i] of the components, i = 1,…,p. If the weights do not add up to 1, they will be scaled accordingly. Equal weights for all components are used by default.

theta.list

named list specifying the component parameters. The names of the list elements have to match the names of the formal arguments of the functions ddist and rdist exactly. For a gaussian mixture, the list elements would have to be named mean and sd, as these are the formal arguments used by rnorm and dnorm functions from distributions. Alternatively, the component parameters can be supplied directly as named vectors of length p via ...

name

optional name tag of the result (used for printing and plotting).

...
in Mix():

alternative way of supplying the component parameters (instead of using theta.list).

in print.Mix():

further arguments passed to the print method.

x
in is.Mix():

returns TRUE if the argument is a datMix object and FALSE otherwise.

in print.Mix():

object of class Mix.

Value

An object of class Mix (implemented as a matrix) with the following attributes:

dim

dimensions of the matrix.

dimnames

a dimnames attribute for the matrix.

name

optional name tag for the result passed on to printing and plotting methods.

dist

character string giving the abbreviated name of the component distribution, such that the function ddist evaluates its density/mass and rdist generates random variates.

discrete

logical flag indicating whether the mixture distribution is discrete.

theta.list

named list specifying component parameters.

See Also

dMix for the density, rMix for random numbers (and construction of an rMix object) and plot.Mix for the plot method.

Examples

1
2
3
4
5
6
7
8
# define 'Mix' object
normLocMix <- Mix("norm", discrete = FALSE, w = c(0.3, 0.4, 0.3), mean = c(10, 13, 17),
                  sd = c(1, 1, 1))
poisMix <- Mix("pois", discrete = TRUE, w = c(0.45, 0.45, 0.1), lambda = c(1, 5, 10))

# plot 'Mix' object
plot(normLocMix)
plot(poisMix)

mixComp documentation built on Feb. 25, 2021, 5:07 p.m.