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")