[2 points] A family may have up to 3 cars. On a street with 5 families, how many possibilities of car ownership among the 5 families can their be? Assume the families can be distinguished.
[2 points] You are playing starcraft matches against your friend. You have won 7 out of 10 matches. How many sequences of win/lose could arrive at such a score of 7 - 3 (7 wins, 3 losses). For example, one sequence is Win, Lose, Win, Win, Win, Win, Lose, Lose, Win, Win. Hint: Try thinking about this as a rearranging letters problem
[2 points] You have a sequences of 0s and 1s. Let $k$ represent the number of 1s and $n$ be the length of the sequence. For example, $01110$ has $k = 3$ and $n = 5$. How many sequences are there for a fixed $n$ and $k$?
[4 points] The equation from problem 1.3 has been seen in unit 2 in a different context. What was it used to calculate? What is different about its use there and the examples from problem 1.3 and 1.2?
[5 points] Using your information from 1.2 through 1.4 reason about the purpose of the binomial coefficient in the formula for the binomial probability distribution.
[2 points] You have 8 textbooks but you can only carry 3 at a time. How many possible combinations of textbooks can you carry?
Can assume families can own 0 cars or must own 1 car. $$ 3^{5} = 243\,, 4^5 = 1024 $$
Imagine the word 'WWWLLLLLLL'. Following our lecture examples, the number of ways to arrange these letters is:
$$ \frac{10!}{7!3!} = 120 $$It is the equation for the number of size $k$ combinations with repeats composed of $n$ objects. Here we are exploring permutations where we have a fixed number of one object (success) and a fixed size.
It is the number of permutations for a given number of success and failures. This accounts for the multiple ways to get 7 successes in 10 trials, for example.
Consider a probability distribution with a 5 element sample space: $Q = \{-3, 0, 2, 3, 6\}$ whose probabilities are $\{1 / 10,\, 4 / 10, \,1/ 10, \,2 / 10,\, 2 / 10\}$ respectively. For example, $P(3) = 2 / 10$. Answer the following questions below:
[5 points] Show that the probability distribution is normalized. Use a for loop and the +=
operator
[5 points] What is the distribution's expected value? Use a for loop and the +=
operator Hint: try iterating over the index of the array to visit elements in both arrayss using this syntax: for i in range(len(Q)):
, where Q
is a list containing the elements in the sample space. Try Python tutor if needed.
[5 points] What is the distribution's variance? Use numpy to evaluate this, but do not use the built in var
or std
functions. You can reuse value for $E[X]$ from 2.2. *Hint: convert your lists to np arrays using the np.array(Q)
syntax. You should only need the np.sum
and no other numpy
functions.
[5 points] Define the random variable $S(x) = x^2$. What is $\textrm{E}[S]$. Use a for loop
In [1]:
#2.1
#enter data
Q = [-3, 0, 2, 3, 6]
P = [1/10, 4/10, 1/10, 2/10, 2/10]
#initialize psum
psum = 0
#iterate over index i
for i in range(len(Q)):
#add up probabilities
psum += P[i]
#print result
print(psum)
In [2]:
#2.2
#initialize expectation value
ex = 0
#iterate over index i
for i in range(len(Q)):
#add up product of probability and element in sample space
ex += P[i] * Q[i]
#print result
print(ex)
In [3]:
#2.3
import numpy as np
#convert to numpy arrays
Parray = np.array(P)
Qarray = np.array(Q)
ex2 = np.sum(Parray * Qarray**2)
var = ex2 - ex**2
print(var)
In [4]:
#initialize expectation value
exS = 0
#iterate over index i
for i in range(len(Q)):
#add up product of probability and element in sample space
exS += P[i] * Q[i]**2
#print result
print(exS)
Choose below the probability distribution that best fits the described process. Choose only from Bernoulli, Geometric, Binomial, Poisson, Exponential, and Normal. 1 Points each.
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. For the geometric distribution or Poisson distribution, replace the $\infty$ with a large number like 500. Assume in all these examples that multiple trials are independent.
[2 points] You go from store to store trying to find a special toy for your dog. Stores have the toy with probability 0.3. What's the expected number of store you must visit before obtaining the toy? Remember to read the instruction above!!
[2 points] When you open the door for your dog, there is a 0.38 probability of him going outside. What is the probability of the dog not going outside?
[2 points] You are playing fetch with your dog. He retrieves the ball which you throw with probability 0.8. After 5 throws, what's the probability of him returning the ball only once?
[2 points] You give your dog 4 treats per day on average. What is the probability of your dog receives 10 treats?
[4 points] Your dog is running laps around the house where the time between the laps is 30 seconds. What's the probability of the dog completing a lap less than 10 seconds? *Hint: compute the integral analytically in LaTeX, then evaluate the upper/lower terms in Python.
[5 points] You are hunting for dog poop in the yard. You check the dog's 10 favorite places to poop. Each can hold 1 or 0 poops. If the probability of your dog pooping in a spot is 0.3, what is the probability of finding more than 6 poops?
[2 points] Your dog is "one in a million". Given that there are 73 million dogs in the US, what is the probability your dog is truly unique. In other words, what is the probability that there are 0 dogs like yours.
[Extra Credit 5 Points] Repeat problem 4.1 but find how many stores you need to visit to have a 90% chance of finding the toy.
In [5]:
#set parameter
p = 0.3
#init sum for expectation
ex = 0
#for loop over sample space
for i in range(1, 500):
# P(i) * i
ex += ((1 - p)**(i - 1) * p) * i
print(ex)
In [6]:
1 - 0.38
Out[6]:
In [7]:
from scipy.special import comb
# set parametrs
p = 0.8
N = 5
#binomial dist equation
prob = comb(N, 1) * (1 - p)**(N - 1) * p**(1)
print(prob)
In [8]:
import math
#set parameters
mu = 4
x = 10
#equation for Poisson
prob = math.exp(-mu) * mu ** x / (math.factorial(x))
print(prob)
In [9]:
1 - math.exp(-10 / 30)
Out[9]:
In [10]:
# set parametrs
p = 0.3
N = 10
#summing over possible numbers of poops
psum = 0
for i in range(7, N + 1):
#binomial dist equation
psum += comb(N, i) * (1 - p)**(N - i) * p**(i)
print(psum)
Poisson. $p = 1 / 10^6$, $N = 73 \times 10^6$, $\mu = 73$. Can choose $x = 0$ or $x = 1$, as "no other dogs like yours" or "your dog is one of a kind" are both valid interpretations.
In [11]:
#set parameters
mu = 73
x = 0
#equation for Poisson
prob = math.exp(-mu) * mu ** x / (math.factorial(x))
print(prob)
In [12]:
#set parameter
p = 0.3
#init sum for prob
psum = 0
#for loop over sample space
for i in range(1, 500):
# P(i)
psum += ((1 - p)**(i - 1) * p)
if psum >= 0.9:
break
print(i, 'stores')