Thread Subject: convolve 2 probability distributions

Subject: convolve 2 probability distributions

From: Patrice Tscherrig

Date: 24 Jun, 2008 17:14:04

Message: 1 of 8

Hi - probably an easy one:

How do I nummerically convolve 2 probability distributions
and see the resulting distribution?

i.e.
P = [(0+eps):0.01:(1-eps)];
normint = norminv(P,0.05,0.005)
lognint = logninv(P,log(0.05),3);
X = lognpdf(lognint,log(0.05),3);
Y = normpdf(normint,0.05,0.005);
total = conv(X,Y);
figure,hist(total)

Leads not really to the result... Any help?

Patric

Subject: convolve 2 probability distributions

From: matt dash

Date: 24 Jun, 2008 19:59:02

Message: 2 of 8

"Patrice Tscherrig" <patrice.tscherrig@gmx.ch> wrote in
message <g3ra0s$g8k$1@fred.mathworks.com>...
> Hi - probably an easy one:
>
> How do I nummerically convolve 2 probability distributions
> and see the resulting distribution?
>
> i.e.
> P = [(0+eps):0.01:(1-eps)];
> normint = norminv(P,0.05,0.005)
> lognint = logninv(P,log(0.05),3);
> X = lognpdf(lognint,log(0.05),3);
> Y = normpdf(normint,0.05,0.005);
> total = conv(X,Y);
> figure,hist(total)
>
> Leads not really to the result... Any help?
>
> Patric


Wouldn't it be easier to just sample from X and Y and do
hist(x+y)?

Subject: convolve 2 probability distributions

From: Patrice Tscherrig

Date: 25 Jun, 2008 12:10:19

Message: 3 of 8

"matt dash" <n.a@mail.com> wrote in message <g3rjm6
$79h$1@fred.mathworks.com>...
> "Patrice Tscherrig" <patrice.tscherrig@gmx.ch> wrote in
> message <g3ra0s$g8k$1@fred.mathworks.com>...
> > Hi - probably an easy one:
> >
> > How do I nummerically convolve 2 probability
distributions
> > and see the resulting distribution?
> >
> > i.e.
> > P = [(0+eps):0.01:(1-eps)];
> > normint = norminv(P,0.05,0.005)
> > lognint = logninv(P,log(0.05),3);
> > X = lognpdf(lognint,log(0.05),3);
> > Y = normpdf(normint,0.05,0.005);
> > total = conv(X,Y);
> > figure,hist(total)
> >
> > Leads not really to the result... Any help?
> >
> > Patric
>
>
> Wouldn't it be easier to just sample from X and Y and do
> hist(x+y)?

Matt,

Well, Don't think that leads to what I want to achive.
Given an empirical pdf1 and pdf2 I want to get out the
empirical convolution of pdf1 and pdf2. With your
suggestion:
x=X(randint(1,1000,[1 100]));
y=Y(randint(1,1000,[1 100]));
figure,hist(x+y)

And looking at the empirial means and std's - not really
what I expect after convolving the above two distributions.

Any help?

Subject: convolve 2 probability distributions

From: pisz_na.mirek@dionizos.zind.ikem.pwr.wroc.pl

Date: 25 Jun, 2008 13:11:53

Message: 4 of 8

Patrice Tscherrig <patrice.tscherrig@gmx.ch> wrote:
> Hi - probably an easy one:
>
> How do I nummerically convolve 2 probability distributions
> and see the resulting distribution?
> P = [(0+eps):0.01:(1-eps)];
> normint = norminv(P,0.05,0.005)
> lognint = logninv(P,log(0.05),3);
> X = lognpdf(lognint,log(0.05),3);
> Y = normpdf(normint,0.05,0.005);
> total = conv(X,Y);
> figure,hist(total)

1) conv works on equidistant points
2) if you have pdf dont use hist but plot

You need do it like this:

x=(-1:.001:1);
l=lognpdf(x,log(0.05),3);
n=normpdf(x,0.05,0.005);
ln=conv(l,n)*(x(2)-x(1));
plot( x,n, x,l, x*2,ln(1:2:end) );
xlim([.0,.3]);ylim([0,100]);


Subject: convolve 2 probability distributions

From: Patrice Tscherrig

Date: 30 Jun, 2008 14:32:01

Message: 5 of 8

pisz_na.mirek@dionizos.zind.ikem.pwr.wroc.pl wrote in
message <g3tg6p$cdg$1@z-news.pwr.wroc.pl>...
> Patrice Tscherrig <patrice.tscherrig@gmx.ch> wrote:
> > Hi - probably an easy one:
> >
> > How do I nummerically convolve 2 probability
distributions
> > and see the resulting distribution?
> > P = [(0+eps):0.01:(1-eps)];
> > normint = norminv(P,0.05,0.005)
> > lognint = logninv(P,log(0.05),3);
> > X = lognpdf(lognint,log(0.05),3);
> > Y = normpdf(normint,0.05,0.005);
> > total = conv(X,Y);
> > figure,hist(total)
>
> 1) conv works on equidistant points
> 2) if you have pdf dont use hist but plot
>
> You need do it like this:
>
> x=(-1:.001:1);
> l=lognpdf(x,log(0.05),3);
> n=normpdf(x,0.05,0.005);
> ln=conv(l,n)*(x(2)-x(1));
> plot( x,n, x,l, x*2,ln(1:2:end) );
> xlim([.0,.3]);ylim([0,100]);
>
>
Hi

Thanks for the hint - very useful! could you however
elaborate on why to use:
 x*2
and
ln(1:2:end)
?

regards,

Patrice

Subject: convolve 2 probability distributions

From: Patrice Tscherrig

Date: 30 Jun, 2008 14:33:02

Message: 6 of 8

pisz_na.mirek@dionizos.zind.ikem.pwr.wroc.pl wrote in
message <g3tg6p$cdg$1@z-news.pwr.wroc.pl>...
> Patrice Tscherrig <patrice.tscherrig@gmx.ch> wrote:
> > Hi - probably an easy one:
> >
> > How do I nummerically convolve 2 probability
distributions
> > and see the resulting distribution?
> > P = [(0+eps):0.01:(1-eps)];
> > normint = norminv(P,0.05,0.005)
> > lognint = logninv(P,log(0.05),3);
> > X = lognpdf(lognint,log(0.05),3);
> > Y = normpdf(normint,0.05,0.005);
> > total = conv(X,Y);
> > figure,hist(total)
>
> 1) conv works on equidistant points
> 2) if you have pdf dont use hist but plot
>
> You need do it like this:
>
> x=(-1:.001:1);
> l=lognpdf(x,log(0.05),3);
> n=normpdf(x,0.05,0.005);
> ln=conv(l,n)*(x(2)-x(1));
> plot( x,n, x,l, x*2,ln(1:2:end) );
> xlim([.0,.3]);ylim([0,100]);
>
>
Hi

Thanks for the hint - very useful! could you however
elaborate on why to use:
 x*2
and
ln(1:2:end)
?

regards,

Patrice

Subject: convolve 2 probability distributions

From: Patrice Tscherrig

Date: 30 Jun, 2008 14:34:02

Message: 7 of 8

pisz_na.mirek@dionizos.zind.ikem.pwr.wroc.pl wrote in
message <g3tg6p$cdg$1@z-news.pwr.wroc.pl>...
> Patrice Tscherrig <patrice.tscherrig@gmx.ch> wrote:
> > Hi - probably an easy one:
> >
> > How do I nummerically convolve 2 probability
distributions
> > and see the resulting distribution?
> > P = [(0+eps):0.01:(1-eps)];
> > normint = norminv(P,0.05,0.005)
> > lognint = logninv(P,log(0.05),3);
> > X = lognpdf(lognint,log(0.05),3);
> > Y = normpdf(normint,0.05,0.005);
> > total = conv(X,Y);
> > figure,hist(total)
>
> 1) conv works on equidistant points
> 2) if you have pdf dont use hist but plot
>
> You need do it like this:
>
> x=(-1:.001:1);
> l=lognpdf(x,log(0.05),3);
> n=normpdf(x,0.05,0.005);
> ln=conv(l,n)*(x(2)-x(1));
> plot( x,n, x,l, x*2,ln(1:2:end) );
> xlim([.0,.3]);ylim([0,100]);
>
>
Hi

Thanks for the hint - very useful! could you however
elaborate on why to use:
 x*2
and
ln(1:2:end)
?

regards,

Patrice

Subject: convolve 2 probability distributions

From: Nancy Hammond

Date: 16 Jul, 2008 19:51:02

Message: 8 of 8

Thanks for posting this question.

I'm trying to use convolve to use probability generating
functions in a branching process. So my example is not
empirical.

I used

s = 1
p = [p2 p1 p0]

conv(p,p) ...

using this with varargout and varargin to iterate on conv
so result is like conv(p,p), conv(p,p,p) conv(p,p,...,p)

I replicated a result in demography text successfully.

But wheh I use a compound distribution like Poisson and
Bernoulli, I'm not getting a result that makes sense

When I figure this out, I'll email

Nancy Hammond
Chicago
"Patrice Tscherrig" <Patrice_Tscherrig@rcomext.com> wrote
in message <g4aqsq$gar$1@fred.mathworks.com>...
> pisz_na.mirek@dionizos.zind.ikem.pwr.wroc.pl wrote in
> message <g3tg6p$cdg$1@z-news.pwr.wroc.pl>...
> > Patrice Tscherrig <patrice.tscherrig@gmx.ch> wrote:
> > > Hi - probably an easy one:
> > >
> > > How do I nummerically convolve 2 probability
> distributions
> > > and see the resulting distribution?
> > > P = [(0+eps):0.01:(1-eps)];
> > > normint = norminv(P,0.05,0.005)
> > > lognint = logninv(P,log(0.05),3);
> > > X = lognpdf(lognint,log(0.05),3);
> > > Y = normpdf(normint,0.05,0.005);
> > > total = conv(X,Y);
> > > figure,hist(total)
> >
> > 1) conv works on equidistant points
> > 2) if you have pdf dont use hist but plot
> >
> > You need do it like this:
> >
> > x=(-1:.001:1);
> > l=lognpdf(x,log(0.05),3);
> > n=normpdf(x,0.05,0.005);
> > ln=conv(l,n)*(x(2)-x(1));
> > plot( x,n, x,l, x*2,ln(1:2:end) );
> > xlim([.0,.3]);ylim([0,100]);
> >
> >
> Hi
>
> Thanks for the hint - very useful! could you however
> elaborate on why to use:
> x*2
> and
> ln(1:2:end)
> ?
>
> regards,
>
> Patrice

Tags for this Thread

Everyone's Tags:

conv(2)

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
conv Patrice Tscherrig 30 Jun, 2008 10:35:07
conv Patrice Tscherrig 24 Jun, 2008 13:15:10
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com