[R] mixed normal distriburtion

mahdiyeh mahdiyeh at zworg.com
Tue Aug 25 11:17:59 CEST 2009


I'm trying to draw the density function of a mixed normal distribution
in the form of:
.6*N(.4,.1)+ .4*N(.8,.1)
At first I generate a random sample with size 200 by the below code:
means = c(.4,.8)
sds = sqrt(c(.1,.1))
ind = sample(1:2, n, replace=TRUE, prob=c(.6,.4))
x=rnorm(n,mean=means[ind],sd=sds[ind])

Then I use the below code for drawing the graph:
plot(density(x))

The plot doesn't seem to be belonging to the desired distribution,
because there is just one mode in it (I've seen the real graph of this
mixed normal in a paper, it has two clear distinct modes). Even the
hist() doesn't draw a plot similar to the real graph. I think the
generation code isn't correct. Is it? (I've asked the generation code
here!)

--
Free e-mail accounts at http://zworg.com




More information about the R-help mailing list