Homework 5

CHE 116: Numerical Methods and Statistics

2/15/2019


1 Standard Probility Distributions (7 Points)

Choose below the probability distribution that best fits the described process. Choose only from Bernoulli, Geometric, Binomial, Poisson, Exponential, and Normal. 1 Points each.

  1. Whether or not it snows on a given day.
  2. How much snow accumulates in one day .
  3. How many times you plow snow within one week.
  4. Plowing the snow only once in a week .
  5. The time between snowstorms in Rochester in June?
  6. How often does it snow in Sahara?
  7. How many road tests one takes before gets the driver's license.

1.1

Bernoulli

1.2

Normal

1.3

Binomial

1.4

Geometeric

1.5

Exponential

1.6

Poisson

1.7

Geomertic

2 Plotting Probability Distributions (20 Points)

Plot the probablities using Python. Accurately label x and y axis. State which distribution the plot is decribing. Make distinction in the use of discrete or continuous variables in the plots. Use for loops to compute probabilities.

  1. [6 points] Probablity of a rain in a given day is 0.2. A month contains 31 days. We are interested in probabilities of the first rain happening in any of the day of the month. Plot the probabilities of raining on a given day for the first time for every day of the month. Which day has the highest probability?
  2. [8 points] The probability of rain is 0.3 in a given day. Plot the number days it will rain and their corresponding probilities in a given month of 31 days. Show the expected value of the distribution as a red vertical line in the plot.

  3. [6 points]Probability of death cancer is 5%. Compute the probability of any number of people dying from cancer in group of 100 people

2.1

Geometric Distribution. According to the plot below the first day has the highest probability


In [2]:
import matplotlib.pyplot as plt
import numpy as np
#set parameter
p = 0.2
x=[]   #days
y=[]  #probanilities
#init sum for expetation
#for loop over sample space
for i in range(1, 32):
    # P(i) * i
    x.append(i)
    y.append((1 - p)**(i - 1) * p) 
print(x,y)
plt.plot(x,y, 'o')
plt.xlabel('Days')
plt.ylabel('Probability of the first snow')
plt.show()


[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31] [0.2, 0.16000000000000003, 0.12800000000000003, 0.10240000000000003, 0.08192000000000002, 0.06553600000000002, 0.052428800000000025, 0.041943040000000015, 0.033554432000000016, 0.026843545600000015, 0.021474836480000013, 0.01717986918400001, 0.013743895347200009, 0.010995116277760009, 0.008796093022208008, 0.007036874417766407, 0.005629499534213125, 0.004503599627370501, 0.0036028797018964006, 0.0028823037615171208, 0.0023058430092136968, 0.0018446744073709574, 0.001475739525896766, 0.001180591620717413, 0.0009444732965739304, 0.0007555786372591443, 0.0006044629098073155, 0.0004835703278458524, 0.00038685626227668196, 0.0003094850098213456, 0.00024758800785707646]
<Figure size 640x480 with 1 Axes>

2.2

Binomial Distribution.Probablity is printed below


In [3]:
from scipy.special import comb

# set parametrs
p = 0.3
N = 31
n=5
#binomial dist equation
days=[]
prob=[]



for i in range(1,N+1):
    days.append(i)
    prob.append(comb(N, i) * (1 - p)**(N - i) * p**(i))

print('The probability that is will rain 5 days out 31 is:',prob[4], N*p)
plt.plot(days,prob, 'o')
plt.plot(N*p*(np.ones((10))),np.linspace(0,0.16, 10), 'r')


The probability that is will rain 5 days out 31 is: 0.03875937897109657 9.299999999999999
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:15: DeprecationWarning: `comb` is deprecated!
Importing `comb` from scipy.misc is deprecated in scipy 1.0.0. Use `scipy.special.comb` instead.
  from ipykernel import kernelapp as app
Out[3]:
[<matplotlib.lines.Line2D at 0x1159fb438>]

2.3

Poisson Distribution


In [4]:
#set parameters
import math
N=100

mu = 1/20*N
x =[]
prob=[]
#equation for Poisson
for person in range(1, N+1):
    x.append(person)
    prob.append(math.exp(-mu) * mu ** person/ (math.factorial(person)))
plt.plot(x,prob, 'o')
plt.show()


3 Working with Probability Distributions (19 Points)

For the following problems, choose and state an appropriate distribution, write out its parameters based on the problem statement and then compute the requested quantity. Write the distribution information in Markdown/LaTeX and compute answers in Python. Use for loops for computing expected value and prediction intervals. Do not use numpy or the formulas given in lecture notes. Assume in all these examples that multiple trials are independent.

  1. [2 points] Let's assume total solar eclipse happens in continental USA every 38 years. The Last total solar eclipse was in 2017 in USA. What is probability of total solar eclipse in continental USA in 2020? Remember to read the instruction above!!

  2. [2 points] Let's assume Lyft drivers pick up clients at probability of 3% at any given time. What is the probability of a Lyft driver taking only 10 people of out 400 clients.

  3. [2 points] You are teaching your son the alphabet, the probability of him saying the letter A correctly is 0.1. After 10 tries, what is probability he will say the letter A correctly once?
  1. [2 points] In January, you applied to 50 jobs. The probability of getting an interview is 0.3 for in January. What is the probablity that you get 7 interviews that month? What is the expected value of this distribution?

  2. [5 points] Bees disappearing at 23% according the USDA from 2013 to 2014. What is the probability of butterflies dying off in 50 years?

  3. [4 points] On average you run with probability of 0.4 per day. What is the expected value of the days during which you run.

3.1

Exponential Distribution


In [5]:
#set parameter
lamda = 1/38 # units of inverse years
time=2020-2017  #years
print('Probability of the total solar eclipse is ',lamda*np.exp(-lamda*time))


Probability of the total solar eclipse is  0.02431811998434676

3.2

Poisson distribution


In [37]:
N=400
p=0.03
mu=N*p
x=10
print('The probablity of picking up 10 clients is: ', (np.exp(-mu)*mu**x)/math.factorial(x))


The probablity of picking up 10 clients is:  0.10483725588365932

3.3

Geometric distribution


In [7]:
p=0.1
N=10
print('The probability of saying the letter correctly once within 10 tries is:',(1 - p)**(N- 1) * p)


The probability of saying the letter correctly once within 10 tries is: 0.03874204890000001

3.4

Binomial distribution


In [8]:
p=0.3
n=7
N=50
print('The probability of getting 7 interviews out of 50 jobs applications is:',comb(N, n) * (1 - p)**(N - n) * p**(n))


The probability of getting 7 interviews out of 50 jobs applications is: 0.004770480981935465
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:4: DeprecationWarning: `comb` is deprecated!
Importing `comb` from scipy.misc is deprecated in scipy 1.0.0. Use `scipy.special.comb` instead.
  after removing the cwd from sys.path.

3.5

Binomial


In [9]:
p=0.4   #per year
N=7
print('The expected value of days during which you run is:', N*p)


The expected value of days during which you run is: 2.8000000000000003