norMix | R Documentation |
Objects of class norMix
represent finite mixtures of
(univariate) normal (aka Gaussian) distributions. Methods for
construction, printing, plotting, and basic computations are provided.
norMix(mu, sig2 = rep(1,m), sigma = rep(1,m),
w = NULL, name = NULL, long.name = FALSE)
is.norMix(obj)
m.norMix(obj)
var.norMix(x, ...)
## S3 method for class 'norMix'
mean(x, ...)
## S3 method for class 'norMix'
print(x, ...)
## S3 method for class 'norMix'
x[i,j, drop=TRUE]
mu |
numeric vector of length |
sig2 |
deprecated! numeric vector of length |
sigma |
numeric vector of length |
w |
numeric vector of length |
name |
optional name tag of the result (used for printing). |
long.name |
logical indicating if the |
obj , x |
an object of class |
i , j , drop |
for indexing, see the generic |
... |
further arguments passed to methods. |
The (one dimensional) normal mixtures, R objects of class
"norMix"
, are constructed by norMix
and tested for by
is.norMix
. m.norMix()
returns the number of mixture
components; the mean()
method for class "norMix"
returns the (theoretical / true) mean E[X]
and
var.norMix()
the true variance E[(X- E[X])^2]
where
X \sim \langle\mathit{norm.mixt}\rangle
.
The subsetting aka “extract” method (x[i,j]
; for generic
[
)—when called as x[i,]
—will typically return a
"norMix"
object unless matrix indexing selects only one row in
which case x[i, , drop=FALSE]
will return the normal mixture
(of one component only).
For further methods (density, random number generation, fitting, ...), see below.
norMix
returns objects of class "norMix"
which are
currently implemented as 3-column matrix with column names mu
,
sigma
, and w
, and further attributes.
The user should rarely need to access the underlying structure
directly.
For estimation of the parameters of such a normal mixture,
we provide a smart parametrization and an efficient implementation of
the direct MLE or also the EM algorithm, see
norMixMLE()
which includes norMixEM()
.
Martin Maechler
dnorMix
for the density,
pnorMix
for the cumulative distribution
and the quantile function (qnorMix
), and
rnorMix
for random numbers and
plot.norMix
, the plot method.
MarronWand
has the Marron-Wand densities as normal mixtures.
norMixMLE()
and norMixEM()
provide fitting
of univariate normal mixtures to data.
ex <- norMix(mu = c(1,2,5))# defaults: sigma = 1, equal proportions ('w')
ex
plot(ex, p.comp = TRUE)# looks like a mixture of only 2; 'p.comp' plots components
## The 2nd Marron-Wand example, see also ?MW.nm2
ex2 <- norMix(name = "#2 Skewed",
mu = c(0, .5, 13/12),
sigma = c(1, 2/3, 5/9),
w = c(.2, .2, .6))
m.norMix (ex2)
mean (ex2)
var.norMix(ex2)
(e23 <- ex2[2:3,]) # (with re-normalized weights)
stopifnot(is.norMix(e23),
all.equal(var.norMix(ex2), 719/1080, tol=1e-14),
all.equal(var.norMix(ex ), 35/9, tol=1e-14),
all.equal(var.norMix(ex[2:3,]), 13/4, tol=1e-14),
all.equal(var.norMix(e23), 53^2/(12^3*4),tol=1e-14)
)
plot(ex2, log = "y")# maybe "revealing"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.