rgmix {spagmix} | R Documentation |
Random bivariate Gaussian mixture density generation
Description
Generates a pixel image of a bivariate normal mixture density observed on a bounded window using a specified number of contributing densities with randomly selected means and variance-covariance matrices.
Usage
rgmix(N, window, v = 4, S = NULL, extras = FALSE, ...)
Arguments
N |
The number of Gaussian components to generate for the mixture. |
window |
An object of class |
v |
The degrees of freedom for the inverse-Wishart distribution of the variance-covariance matrices (must be at least 4). The default value of 4 ensures the generated covariance matrices are centered on |
S |
A symmetric, positive-definite |
extras |
A logical value indicating whether, in addition to returning the pixel |
... |
Additional arguments to be passed to |
Details
This function creates and returns a bivariate Gaussian mixture density on a bounded window
based on N
randomly generated mean locations and corresponding randomly generated variance-covariance matrices. First, the N
mean locations are generated based on a uniform distribution over the spatial window
. Each location is then associated with a covariance matrix generated from an inverse-Wishart distribution with v
degrees of freedom and scale matrix S
.
Once the above steps are completed, the function calls sgmix
with the chosen mean and covariance matrices, thereby creating the Gaussian mixture. Resolution and other aspects of this call can be controlled by using ...
, passing the contents internally to sgmix
. By default, all generated Gaussian components have equal weight in contributing to the final mixture density. The user can alter this by passing p0
and p
to the ...
, though should take care that the length of p
is N
, and that p0
and p
sum to 1, as outlined in the documentation for sgmix
.
Value
If extras = FALSE
(default), then a pixel im
age of the final mixture density. If extras = TRUE
, a list is returned with members f
(the pixel im
age of the final mixture density); mn
(a 2 \times
N
matrix with each column giving the mean location of each of the N
Gaussian bumps); and vcv
(a 2 \times 2 \times
N
array with layers giving the covariance matrices associated with the means in the columns of mn
).
Author(s)
A.K. Redmond and T.M. Davies
Examples
set.seed(321)
dens1 <- rgmix(7,window=toywin)
plot(dens1)
set.seed(456)
dens2 <- rgmix(7,window=toywin)
plot(dens2)
# Explicitly return details of generated means and covariances
set.seed(321)
dens1.detailed <- rgmix(7,window=toywin,extras=TRUE)
dens1.detailed$f
dens1.detailed$mn
dens1.detailed$vcv
# Set underlying uniform proportion and compare with dens2 from above
set.seed(456)
dens2.wunif <- rgmix(7,window=toywin,p0=0.3)
plot(rpoint(500,dens2))
plot(rpoint(500,dens2.wunif))
# Explicitly setting scale matrix for inverse-wishart generation of covariances
dens3 <- rgmix(3,window=toywin,S=matrix(c(0.025,-0.004,-0.004,0.02),2))
plot(dens3)