Learn R Programming

oeli (version 0.7.8)

dmixnorm_cpp: Mixture of normal distributions

Description

The function dmixnorm() computes the density of a mixture of multivariate normal distribution.

The function pmixnorm() computes the cumulative distribution function of a mixture of multivariate normal distribution.

The function rmixnorm() samples from a mixture of multivariate normal distribution.

The functions with suffix _cpp perform no input checks, hence are faster.

The univariate normal mixture is available as the special case p = 1.

Usage

dmixnorm_cpp(x, mean, Sigma, proportions, log = FALSE)

pmixnorm_cpp( x, mean, Sigma, proportions, abseps = 0.001, lower = NULL, method = "genz", draws = 500L )

rmixnorm_cpp(mean, Sigma, proportions, log = FALSE)

dmixnorm(x, mean, Sigma, proportions, log = FALSE)

pmixnorm( x, mean, Sigma, proportions, abseps = 0.001, lower = NULL, method = "genz", draws = 500 )

rmixnorm(n = 1, mean, Sigma, proportions, log = FALSE)

Value

For dmixnorm(): The density value.

For pmixnorm(): The value of the distribution function or the rectangle probability.

For rmixnorm(): If n = 1 a vector of length p (note that it is a column vector for rmixnorm_cpp()), else a matrix of dimension n times p with samples as rows.

Arguments

x

[numeric(p)]
A quantile vector of length p, where p is the dimension.

mean

[matrix(nrow = p, ncol = c)]
The mean vectors for each component in columns.

Sigma

[matrix(nrow = p^2, ncol = c)]
The vectorized covariance matrices for each component in columns.

proportions

[numeric(c)]
The non-negative mixing proportions for each components.

If proportions do not sum to unity, they are rescaled to do so.

log

[logical(1)]
For dmixnorm(), return the logarithm of the density value?

For rmixnorm(), return the exponential of the draw, which is a draw from the mixture of log-normal distributions?

abseps

[numeric(1)]
The absolute error tolerance for method = "genz".

lower

[numeric() | NULL]
Optionally lower limits of length p, where NULL corresponds to -Inf.

For the functions without suffix _cpp, it can also be of length 1 for convenience, then rep(lower, p) is considered.

method

[character(1)]
Either "genz" or "ghk", see the details.

draws

[integer(1)]
The number of Halton points for method = "ghk".

n

[integer(1)]
The number of requested samples.

Details

pmixnorm() is based on pmvnorm(), which is exact for p <= 3 and approximates the probability by the method selected in method otherwise.

See Also

Other simulation helpers: Simulator, correlated_regressors(), ddirichlet_cpp(), dmvnorm_cpp(), dtnorm_cpp(), dwishart_cpp(), gaussian_tv(), simulate_markov_chain()

Examples

Run this code
x <- c(0, 0)
mean <- matrix(c(-1, -1, 0, 0), ncol = 2)
Sigma <- matrix(c(diag(2), diag(2)), ncol = 2)
proportions <- c(0.7, 0.3)

# compute density
dmixnorm(x = x, mean = mean, Sigma = Sigma, proportions = proportions)
dmixnorm(
  x = x, mean = mean, Sigma = Sigma, proportions = proportions, log = TRUE
)

# compute CDF
pmixnorm(x = x, mean = mean, Sigma = Sigma, proportions = proportions)

# compute rectangle probability
pmixnorm(
  x = x, mean = mean, Sigma = Sigma, proportions = proportions, lower = -1
)

# sample
rmixnorm(n = 3, mean = mean, Sigma = Sigma, proportions = proportions)

Run the code above in your browser using DataLab