Homepage > MCMC

## Normal Mixture

Let be the normal density function with mean and standard deviation (SD) . Given parameters , , , , and , the normal mixture'' density is defined as

The mixture of two normal distribution will be a bimodal distribution, and the two peaks may be approximated by the respective mean and .
> source("nm.r")
> x = seq(0,1,by=0.01)
> plot(x, nm(x), type="l", xlab="x", ylab="PDF", main="Normal mixture")


Programming note. The function nm()'' is defined in the source file nm.r and written in the form

nm = function(x, p=c(0.3, 0.2, 0.8, 0.1, 0.4)){
p[5] * dnorm(x, p[1], p[2]) + (1-p[5]) * dnorm(x, p[3], p[4])
}

It is executed by
> y = mn(0.2)

The argument p'' is optional, and given c(0.3, 0.2, 0.8, 0.1, 0.4) when omitted. The function returns the value
  p[5] * dnorm(x, p[1], p[2]) + (1-p[5]) * dnorm(x, p[3], p[4])

in which dnorm() returns the normal density value.