mixed normal distriburtion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

mixed normal distriburtion

mahdiyeh
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: mixed normal distriburtion

Richard Cotton
> 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!)

The code is fine - the reason you can't see two peaks is that the two
distributions overlap a lot.  Set
means <- c(.4, 10)
to see double peaks more clearly.

Regards,
Richie.

Mathematical Sciences Unit
HSL



------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:22}}

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: mixed normal distriburtion

Giovanni Petris

With n = 100 I can see the two modes well separated in a density
plot.

However, I don't see why you cannot plot the density function, if
that's what you need:

curve(0.6 * dnorm(x, 0.4, 0.1) + 0.4 * dnorm(x, 0.8, 0.1), 0, 1.2)

Best,
Giovanni

> Date: Tue, 25 Aug 2009 13:55:26 +0100
> From: [hidden email]
> Sender: [hidden email]
> Cc: [hidden email], [hidden email]
> Precedence: list
>
> > 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!)
>
> The code is fine - the reason you can't see two peaks is that the two
> distributions overlap a lot.  Set
> means <- c(.4, 10)
> to see double peaks more clearly.
>
> Regards,
> Richie.
>
> Mathematical Sciences Unit
> HSL
>
>
>
> ------------------------------------------------------------------------
> ATTENTION:
>
> This message contains privileged and confidential inform...{{dropped:22}}
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.