# Gaussian mixture in R [closed]

dnorm2.p <- function(x,p)   p[1]*dnorm(x,p[2],p[3]) + (1-p[1])*dnorm(x,p[4],p[5])
f.neglog <- function(p)   -sum(log(dnorm2.p(x,p)))
start.params <- c(0.7,-400,100,600,50)
n2.fit <- optim(start.params,f.neglog)

π = 0.8512394  # weight
μ1 = -229.1567182
σ1 = 174.326821
μ2 = 646.6475601
σ2 = 214.1101274

How can I plot a mixture distribution and compare it to a kernel density. I already know how to plot the kernel density like:

hist(x,freq=F)
lines(density(x),col="purple")
-
Please, define your notations a little bit (although I guess weight is the mixing parameter, and the rest stand for mean and SD of the distributions). If the question is purely about R plotting functionalities, it belongs on Stack Overflow. If you are interested in comparing mixture and kernel distributions by any statistical means, you may want to define precisely what you have in mind. – chl Nov 1 '12 at 17:39
You may also want to have a look at the VGAM package, see my answer here: stackoverflow.com/questions/13499969/… – nico Mar 2 at 6:51

## closed as off topic by whuber♦May 1 at 16:33

Questions on Cross Validated are expected to relate to statistics within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.