R: Mixtures of Univariate Normal Distributions

norMix {nor1mix} | R Documentation

## Mixtures of Univariate Normal Distributions

### Description

Objects of class `norMix` represent finite mixtures of (univariate) normal (aka Gaussian) distributions. Methods for construction, printing, plotting, and basic computations are provided.

### Usage

    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]

### Arguments

`mu` | numeric vector of length K, say, specifying the means μ of the K normal components.
`sig2` | deprecated! numeric vector of length K, specifying the variances σ^2 of the K normal components. Do specify `sigma` instead!
`sigma` | numeric vector of length K, specifying the standard deviations σ of the K normal components.
`w` | numeric vector of length K, specifying the mixture proportions p[j] of the normal components, j = 1,…,K. Defaults to equal proportions
`name` | optional name tag of the result (used for printing).
`long.name` | logical indicating if the `name` attribute should use punctuation and hence be slightly larger than by default.
`obj,x` | an object of class `norMix`.
`i,j,drop` | for indexing, see the generic `[` extractor function.
`...` | further arguments passed to methods.

### Details

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 ~ <norm.mixt>.

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.

### Value

`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.

### Note

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()`.

### Author(s)

Martin Maechler

### See Also

`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.

### Examples

    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"

[Package nor1mix version 1.2-3 Index]