Learn R Programming

ICV (version 1.0)

mixnorm: Generating a random sample from the specified mixture of normal distributions.

Description

Generating a random sample of size $n$ from the normal mixture defined by expression (2.3) of Marron and Wand (1992).

Usage

mixnorm(n, w, mu, sdev)

Arguments

n
desired sample size,
w
vector of weighs (positive numbers between 0 and 1 that add up to one),
mu
vector of means,
sdev
vector of standard deviations.

Value

A random sample of size $n$ from the specified mixture of normals.

Details

Producing a random sample of size $n$ from the normal mixture defined by the vector of weights $w$, the vector of means $\mu$, and the vector of standard deviations $\sigma$. See Marron and Wand (1992). It is assumed that the normals are defined as parsimonious as possible. The normal distributions in the mixture should be ordered such that the means in $\mu$ are arranged in a nondecreasing order.

References

Marron, J.S., Wand, M.P. (1992). Exact Mean Integrated Squared Error. The Annals of Statistics, 20(2), 712-736.

See Also

ISE_mixnorm, h_isemixnorm, MISE_mixnorm.

Examples

Run this code
## Not run: 
# # Generating a sample of size n=300 from the separated bimodal density of Marron and Wand (1992).
# w=c(0.5,0.5)
# mu=c(-3/2,3/2)
# sdev=c(1/2,1/2)
# dat=mixnorm(300,w,mu,sdev) # generated data vector
# arg=seq(-4,4,len=1000)  # argument
# f=w[1]*dnorm(arg,mu[1],sd=sdev[1])+w[2]*dnorm(arg,mu[2],sd=sdev[2])     # true density
# dev.new()
# hist(dat,freq=F,ylab="",main="",cex.lab=1.7,cex.axis=1.7,xlim=c(-4,4),lwd=2,ylim=c(0,0.45),
# col='grey')
# title(main="Separated bimodal density",cex.main=1.7)
# legend(-5,0.4,legend="n=300",cex=2,bty="n")
# lines(arg,f,lwd=3,'l')
# ## End(Not run)

Run the code above in your browser using DataLab