NOTE: In this notebook I use the module scipy.stats for all statistics
functions, including generation of random numbers. There are other modules with some overlapping functionality, e.g., the regular python random module, and the scipy.random module, but I do not use them here. The scipy.stats module includes tools for a large number of distributions, it includes a large and growing set of statistical functions, and there is a unified class structure. (And namespace issues are minimized.) See https://docs.scipy.org/doc/scipy/reference/stats.html.

In [1]:

importscipyasspfromscipyimportstatsimportmatplotlibasmpl# As of July 2017 Bucknell computers use v. 2.x importmatplotlib.pyplotasplt# Following is an Ipython magic command that puts figures in the notebook.# For figures in separate windows, comment out following line and uncomment# the next line# Must come before defaults are changed.%matplotlib notebook
#%matplotlib# As of Aug. 2017 reverting to 1.x defaults.# In 2.x text.ustex requires dvipng, texlive-latex-extra, and texlive-fonts-recommended, # which don't seem to be universal# See https://stackoverflow.com/questions/38906356/error-running-matplotlib-in-latex-type1cm?mpl.style.use('classic')# M.L. modifications of matplotlib defaults using syntax of v.2.0 # More info at http://matplotlib.org/2.0.0/users/deflt_style_changes.html# Changes can also be put in matplotlibrc file, or effected using mpl.rcParams[]plt.rc('figure',figsize=(6,4.5))# Reduces overall size of figuresplt.rc('axes',labelsize=16,titlesize=14)plt.rc('figure',autolayout=True)# Adjusts supblot parameters for new size

Sample $n$ random numbers from the Poisson distribution with average count $\overline{N}$, and probability distibution given by Eq.(3.1) of Hughes & Hase:
\begin{equation}
p(N;\overline{N}) = \frac{\exp\left(-\overline{N}\right)\overline{N}^N}{N!}
\end{equation}
The standard deviation of the Poisson distribution is given by
$$ \sigma = \sqrt{\overline{N}}. $$

The probablity of getting $x$ successes is given by the probability mass function (pmf). This is analogous to the continous pdf (and it's called the PDF in Mathematica). As an example, the probability of 2 successes in 3 trials with a probability of success in each trial of 0.4 is
29%:

# Generate some random data from a normal distribution.n=100mean=10.sigma=2.data=sp.stats.norm.rvs(mean,sigma,size=n)

In [19]:

# Select number of bins between low and high values.# plt.hist outputs the binned data and plots the histogram.nbins=6low=mean-3*sigmahigh=mean+3*sigmaplt.figure(7)plt.xlabel("value")plt.ylabel("occurences")plt.title("Histogram; equal sized bins")out=plt.hist(data,nbins,[low,high])out[0],out[1]# occurrences and bin boundaries

If version_information has been installed system wide (as it has been on Bucknell linux computers with shared file systems), continue with next cell as written. If not, comment out top line in next cell and uncomment the second line.