{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Hughes and Hase Problem 3.7\n", "\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Data" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "58\n" ] } ], "source": [ "counts = np.array([1,3,4,5,6,7,8,9,10,11,12,13])\n", "occurences = np.array([1,2,3,6,9,11,8,8,6,2,1,1])\n", "\n", "n_expts = np.sum(occurences) # check \n", "print(n_expts)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (i) Total number of counts" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total # of counts = 423\n" ] } ], "source": [ "total = occurences@counts # Dot product \n", "print(\"total # of counts =\", total)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (ii) Mean number of counts\n", "\n", "This is the best estimate of the mean of the parent Poisson distribution." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mean counts/second = 7.293103448275862\n" ] } ], "source": [ "mean = total/n_expts\n", "print('mean counts/second =', mean)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (i) Expected # of trials with 5 or fewer countsĀ¶\n", "\n", "Use the cumulative distribution function for the Poisson distribution" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability of getting 5 or fewer counts = 0.2648489299548199\n", "expected number of trials with 5 or fewer counts = 15.361237937379554\n" ] } ], "source": [ "probability1 = stats.poisson.cdf(5, mean)\n", "print(\"probability of getting 5 or fewer counts =\", probability1)\n", "n_expected1 = n_expts*probability1\n", "print(\"expected number of trials with 5 or fewer counts =\", n_expected1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### (ii) Expected # of trials with 20 or more countsĀ¶\n", "Use the cumulative distribution function to find the probability of 19 or fewer counts. \n", "The probability of 20 or more is (1 - the probability of 19 or fewer)." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability of getting 20 or more counts = 7.674243593669416e-05\n", "expected number of trials with 20 or more counts = 0.0044510612843282615\n" ] } ], "source": [ "probability2 = 1 - stats.poisson.cdf(19, mean)\n", "print(\"probability of getting 20 or more counts =\", probability2)\n", "n_expected2 = n_expts*probability2\n", "print(\"expected number of trials with 20 or more counts =\", n_expected2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Version information\n", "`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.\n", "\n", "`version_information` is installed on the linux network at Bucknell" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.7 64bit [GCC 7.3.0]" }, { "module": "IPython", "version": "7.16.1" }, { "module": "OS", "version": "Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core" }, { "module": "scipy", "version": "1.5.2" }, { "module": "matplotlib", "version": "3.3.0" } ] }, "text/html": [ "
Software | Version |
---|---|
Python | 3.7.7 64bit [GCC 7.3.0] |
IPython | 7.16.1 |
OS | Linux 3.10.0 1062.9.1.el7.x86_64 x86_64 with centos 7.7.1908 Core |
scipy | 1.5.2 |
matplotlib | 3.3.0 |
Fri Aug 07 09:57:51 2020 EDT |