Code covered by the BSD License

### Highlights from Sum of probability distributions

5.0
5.0 | 1 rating Rate this file 2 Downloads (last 30 days) File Size: 2.6 KB File ID: #34082 Version: 1.3

# Sum of probability distributions

### Mike Sheppard (view profile)

05 Dec 2011 (Updated )

SUMPDF Probability distribution of the sum of distributions

File Information
Description

SUMPDF Probability distribution of the sum of distributions
[S,P,C]=SUMPDF(X1,P1,N1,X2,P2,N2,...) will return the distribution of the sum of distribution P1, at values at X1, N1 times plus the distribution P2, at values in X2, N2 times...

The output vectors, S, P, and C, are respectively the list of unique outcomes, probability of yielding that outcome, and the total number of ways of obtaining that outcome among all combinations.

EXAMPLE (Discrete)
Distribution of the total value when choosing 10 values from distribution (A) and 7 values from distribution (B).

X1=[-1 0 2]; P1=[.1 .2 .7]; N1=10; %(A)
X2=[ 0 1 2]; P2=[.3 .5 .2]; N2=7; %(B)
[S,P,C]=sumpdf(X1,P1,N1,X2,P2,N2);

subplot(2,1,1), plot(S,P), grid on
title('Probability distribution of total value')
subplot(2,1,2), plot(S,C), grid on
title('Number of combinations possible to obtain each outcome')

This illustrates that while an outcome of 10 has the most combinations of ways to happen, it is actually a total of 20 which is the most likely to happen due to the given probabilities of values.

EXAMPLE (Continuous)
Note: Program assumes discrete distribution. If using continuous distributions, and using densities as inputs, a normalization must be made afterwards. Also, as only a finite number of points are used the results are an approximation to the actual value on a valid domain.

The sum of gamma distributions with the same scale parameter is another gamma distribution with the overall shape parameter being the sum of the individual shape parameters. Verify for a specific case. (This example requires the statistics toolbox)
X1=linspace(0,10); Y1=gampdf(X1,2,1/2); N1=2; %(A)
X2=linspace(0,10); Y2=gampdf(X2,3,1/2); N2=3; %(B)
[XT,YT,CT]=sumpdf(X1,Y1,N1,X2,Y2,N2);
YT=YT./trapz(XT,YT); %Convert to density
plot(XT,YT,XT,gampdf(XT,N1*2+N2*3,1/2));
axis([0 10 0 1/4])

Acknowledgements

All Sums inspired this file.

This file inspired Apply A Function To A Set Of Probability Distributions.

MATLAB release MATLAB 7.13 (R2011b)
08 Dec 2011 Mike Sheppard

### Mike Sheppard (view profile)

Good idea. Expanded the code the uploaded a new file to handle more general cases. See "Apply a function to a set of probability distributions" #34108

Comment only
06 Dec 2011 Jonathan Sullivan

### Jonathan Sullivan (view profile)

Very nice. Exactly what I needed! Now, if only this could be expanded to additional operators (i.e. times, max, min, mean, etc)

07 Dec 2011 1.1

Updated help and included continuous

09 Dec 2011 1.2

Exclude values with zero probabilities

04 Apr 2012 1.3

Updated help section