## Please enable JavaScript to view this site.

 Navigation: REGRESSION WITH PRISM 8 > Plotting a function Plotting a binomial or Poisson distribution

## How to plot a binomial or Poisson distribution

To modify this file, change the value of lamda (for Poission) or the probability, n, and cutoff (Binomial) in the Info sheet. Enter new values there, and the graph updates. This is a good example of the usefulness of hooking an info constant to an analysis.

If you want to recreate graphs like these, keep in mind these points:

As its name suggests, the analysis 'Create a Family  of Theoretical Curves' is usually used to create curves, not bar graphs. When you choose the range of X values, specify the appropriate number of 'line segments' (points) so that the X interval equals 1.0. The binomial example on the left created 16 'line segments' starting at X=0 and ending at X=15. The Poisson on the right created 13 'segments' with X starting at 0 and ending at 13.

The analysis will create a set of line segments (an attempt to create a curve). Click the change type of graph button, or drop the Change menu and choose Graph Type. Then choose the Grouped tab, and then choose interleaved bars.

The binomial example on the right has two data sets. You don't want them plotted interleaved, as selected in the previous step. Double click to bring up Format Graph, then go to the middle tab, and choose to superimpose the second data set on the first (rather than interleave). And assign it a different color.

## Mathematical details

### Binomial distribution

The equation for the probability of exactly X successes in N trials, when each trial has probability P of success is:

R=INT(X+0.5)

ExactProb=(P^R)*(1-P)^(N-R)  ;exact probability of  successes in n trials

NRearrangments=exp(gammaln(N+1) - gammaln(R+1) - gammaln(N - R +1))

;gamma(J)=(J-1)factorial, or (J-1)! but factorial is not a function within Prism

;NRearrangments = N!/(R! (N-R)!)

H=ExactProb * NRearrangments

<A>Y=H

<B>Y=IF(X>cutoff, H, 0)

### Poisson distribution

Y=exp(-1*Lamda)*Lamda^X/gamma(X+1)

Note the definition of the gamma function:

gamma(i) = factorial(i-1)

gamma(x+1)= factorial(x) = X!