rMix: Generate a Random Sample from a Mixture Distribution

Description Usage Arguments Details Value See Also Examples

View source: R/0_Mix_utils.R

Description

Generate a random sample of size n, distributed according to a mixture specified as Mix object. Returns an object of class rMix.

Usage

1
2
3
4
5
6
rMix(n, obj)

is.rMix(x)

## S3 method for class 'rMix'
print(x, ...)  

Arguments

n

integer specifying the number of observations.

obj

object of class Mix.

x
in is.rMix():

R object.

in print.rMix():

object of class rMix.

...

further arguments passed to the print method.

Details

For a mixture of p components, generate the number of observations in each component as multinomial, and then use an implemented random variate generation function for each component. The integer (multinomial) numbers are generated via sample.

Value

An object of class rMix with the following attributes (for further explanations see Mix):

name

name of the Mix object that was given as input.

dist

character string stating the (abbreviated) name of the component distribution, such that the function ddist evaluates its density function and rdist generates random numbers.

discrete

logical indicating whether the underlying mixture distribution is discrete.

theta.list

named list specifying the parameter values of the p components.

w

numeric vector of length p, specifying the mixture weights w[i] of the components, i = 1,…,p.

indices

numeric vector of length n containing integers between 1 and p specifying which mixture component each observation belongs to.

See Also

dMix for the density, Mix for the construction of Mix objects and plot.rMix for the plot method.

Examples

1
2
3
4
5
6
7
# define 'Mix' object
normLocMix <- Mix("norm", w = c(0.3, 0.4, 0.3), mean = c(10, 13, 17), sd = c(1, 1, 1))

# generate n random samples
set.seed(1)
x <- rMix(1000, normLocMix)
hist(x)

anjaweigel/mixComp_package documentation built on Sept. 2, 2020, 3:55 p.m.