Learn R Programming

nor1mix (version 1.1-3)

llnorMix: Likelihood and Parametrization of 1D Normal Mixtures

Description

These functions work with an almost unconstrained parametrization of univariate normal mixtures.

llnorMix(p, *) computes the log likelihood, where as obj <- par2norMix(p) and p <- nM2par(obj) map to and from norMix objects obj and parameter vector p in our parametrization.

Usage

llnorMix(p, x, m = (length(p) + 1)/3)

par2norMix(p, name = sprintf("{from %s}", deparse(substitute(p))[1])) nM2par(obj)

Arguments

p
numeric vector: our parametrization of a univariate normal mixture, see details.
x
numeric: the data for which the likelihood is to be computed.
m
integer number of mixture components; this is not to be changed for a given p.
name
(for par2norMix():) a name for the "norMix" object that is returned.
obj
a "norMix" object, see norMix.

Value

  • llnorMix() returns a number, namely the log-likelihood.

    par2norMix() returns "norMix" object, see norMix.

    nM2par() returns the parameter vector $\theta$ of length $3k-1$.

Details

We use a parametrization of a (finite) univariate normal mixture which is particularly apt for likelihood maximization, namely, one whose parameter space is almost a full $\mathbf{I\hskip-0.22em R}^m$, $m = 3k-1$.

For a $k$-component mixture, we map to and from a parameter vector $\theta$ (== p as R-vector) of length $3k-1$. For mixture density $$\sum_{j=1}^k \pi_j \phi((t - \mu_j)/\sigma_j),$$ we logit-transform the $\pi_j$ (for $j \ge 2$) and log-transform the $\sigma_j$, such that $\theta$ is partitioned into [object Object],[object Object],[object Object]

See Also

norMix, logLik. Note that the log likelihood of a "norMix" object is directly given by sum(dnorMix(x, obj, log=TRUE)).

Examples

Run this code
(obj <- MW.nm10) # "the Claw" -- m = 6 components
length(pp <- nM2par(obj)) # 17 == (3*6) - 1
par2norMix(pp)
## really the same as the initial \code{obj} (see below)

## Log likelihood (of very artificial data):
llnorMix(pp, x = seq(-2, 2, length=1000))
## of more realistic data:
x <- rnorMix(1000, obj)
llnorMix(pp, x)

## Consistency check :
stopifnot(all.equal(pp, nM2par(par2norMix(pp)), tol= 1e-15),
          all.equal(obj, par2norMix(nM2par(obj)),
                    check.attributes=FALSE, tol=1e-15),
          ## Direct computation of log-likelihood:
          all.equal(sum(dnorMix(x, obj, log=TRUE)),
                    llnorMix(pp, x), tol= 1e-15)  )

Run the code above in your browser using DataLab