Solved – Plot explicit cdf instead of ecdf in R

I have adjusted the parameters (lambda, mu, sigma) for a mixture of two normals fitted to my data. Now I would like to plot the cdf of this model using the explicit function instead of the ecdf. Is there any way to do this or I do I have to simulate data so then I can use again ecdf?

The explicit function is something like:

ipc_values_EM$lambda[1] * dnorm(x, ipc_values_EM$mu[1], ipc_values_EM$sigma[1])  + ipc_values_EM$lambda[2] * dnorm(x, ipc_values_EM$mu[2], ipc_values_EM$sigma[2])  

(as you can note, is the mixture of two normals different mus and different sigmas)

Like the title of the function ecdf() says, it is empirical and only runs on samples.

If you want the exact cdf of a Gaussian, the function you are looking for is pnorm(). Here is a demonstration.

x <- seq(from=-5, to=5, by=.1) y <- pnorm(x) plot(x, y, type='l') 

If you replace dnorm() by pnorm() in your code, and x by the range of values you want to take the cdf over you should get the result you are looking for.

Similar Posts:

Rate this post

Leave a Comment