# norMix: Mixtures of Univariate Normal Distributions In nor1mix: Normal (1-d) Mixture Models (S3 Classes and Methods)

## 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

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```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

`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

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22``` ```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" ```

### Example output

```'Normal Mixture' object 	 ``NM3.125_111''
mu sigma         w
[1,]  1     1 0.3333333
[2,]  2     1 0.3333333
[3,]  5     1 0.3333333
Warning message:
In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

[1] 3
[1] 0.75
[1] 0.6657407
Warning message:
In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

'Normal Mixture' object 	 ``#2 Skewed[2:3,]''
mu     sigma    w
[1,] 0.500000 0.6666667 0.25
[2,] 1.083333 0.5555556 0.75
Warning messages:
1: In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

2: In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

3: In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

4: In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.

Warning messages:
1: In mj - mu :
Recycling array of length 1 in vector-array arithmetic is deprecated.