NOTE: In this notebook I use the stats
sub-module of scipy
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 stats
sub-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.
import numpy as np
from scipy import stats
counts = np.array([1,3,4,5,6,7,8,9,10,11,12,13])
occurences = np.array([1,2,3,6,9,11,8,8,6,2,1,1])
n_expts = np.sum(occurences) # check
print(n_expts)
total = occurences@counts # Dot product
print("total # of counts =", total)
This is the best estimate of the mean of the parent Poisson distribution.
mean = total/n_expts
print('mean counts/second =', mean)
Use the cumulative distribution function for the Poisson distribution
probability1 = stats.poisson.cdf(5, mean)
print("probability of getting 5 or fewer counts =", probability1)
n_expected1 = n_expts*probability1
print("expected number of trials with 5 or fewer counts =", n_expected1)
Use the cumulative distribution function to find the probability of 19 or fewer counts. The probability of 20 or more is (1 - the probability of 19 or fewer).
probability2 = 1 - stats.poisson.cdf(19, mean)
print("probability of getting 20 or more counts =", probability2)
n_expected2 = n_expts*probability2
print("expected number of trials with 20 or more counts =", n_expected2)
version_information
is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.
version_information
is installed on the linux network at Bucknell
%load_ext version_information
version_information scipy, matplotlib