| llnorMix {nor1mix} | R Documentation |
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.
llnorMix(p, x, m = (length(p) + 1)/3)
par2norMix(p, name = sprintf("{from %s}", deparse(substitute(p))[1]))
nM2par(obj)
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 |
name |
(for |
obj |
a |
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 R^m, m = 3k-1.
For a k-component mixture,
we map to and from a parameter vector θ (== p as R-vector)
of length 3k-1. For mixture density
sum[j=1..k] pi[j] phi((t - mu[j])/s[j]),
we logit-transform the pi[j] (for j >= 2) and log-transform the s[j], such that θ is partitioned into
p[ 1:(k-1)]: p[j]= logit(pi[j+1]) and
pi[1] is given implicitly as
pi[1] = 1 - sum[j=2..k] pi[j].
p[ k:(2k-1)]: p[k-1+ j]= μ_j, for j=1:k.
p[2k:(3k-1)]: p[2*k-1+ j]
= log(s[j]), i.e.,
σ_j^2 = exp(2*p[.+j]).
llnorMix() returns a number, namely the log-likelihood.
par2norMix() returns "norMix" object, see norMix.
nM2par() returns the parameter vector θ of length
3k-1.
Martin Maechler
norMix, logLik.
Note that the log likelihood of a "norMix" object
is directly given by sum(dnorMix(x, obj, log=TRUE)).
(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) )