Hughes and Hase Problem 3.7

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.

In [1]:
import numpy as np
from scipy import stats

Data

In [2]:
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)
58

(i) Total number of counts

In [3]:
total = occurences@counts   # Dot product 
print("total # of counts =", total)
total # of counts = 423

(ii) Mean number of counts

This is the best estimate of the mean of the parent Poisson distribution.

In [4]:
mean = total/n_expts
print('mean counts/second =', mean)
mean counts/second = 7.293103448275862

(i) Expected # of trials with 5 or fewer counts¶

Use the cumulative distribution function for the Poisson distribution

In [5]:
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)
probability of getting 5 or fewer counts = 0.2648489299548199
expected number of trials with 5 or fewer counts = 15.361237937379554

(ii) Expected # of trials with 20 or more counts¶

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).

In [6]:
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)
probability of getting 20 or more counts = 7.674243593669416e-05
expected number of trials with 20 or more counts = 0.0044510612843282615

Version information

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

In [7]:
%load_ext version_information
In [8]:
version_information scipy, matplotlib
Out[8]:
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core
scipy1.5.2
matplotlib3.3.0
Fri Aug 07 09:57:51 2020 EDT
In [ ]: