'Draw cdf of mixture normal distribution

I am making the cdf graph of mixture normal distribution in R. I do not know how to derive the theoretical form of mixture normal, so I use rnorm to sample from mixture normal, and use ecdf to calculate its cdf. But the graph is not continuous at all. Does anyone know how to draw a continuous cdf of mixture normal?

The code is:

   x <- seq(-4, 4, .0001)
   components <- sample(1:2, prob=c(0.85, 0.15), size=10000, replace=TRUE)
   mus <- c(0, 0)
   sds <- sqrt(c(0.2, 20))
   z <- rnorm(n = 10000, mean=mus[components], sd=sds[components])
   p <- ecdf(z)
   plot(p, col = "gold")

And the figure looks like: image



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source