



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Will Monroe CS 109
Lecture Notes # July 19, 2017
Based on a chapter by Chris Piech
The single most important random variable type is the normal (a.k.a. Gaussian) random variable , parametrized by a mean (μ) and variance (σ^2 ). If X is a normal variable, we write X ∼ N(μ, σ^2 ). The normal is important for many reasons: it is generated from the summation of independent random variables and as a result it occurs often in nature.
Many things in the world are not quite distributed normally, but data scientists and computer scientists model them as normal distributions anyways. Why? Essentially, the normal is what we use if we know mean and variance, but nothing else. In fact, it is the most conservative 1 modeling decision that we can make for a random variable while still matching a particular expectation (average value) and variance (spread).
The probability density function (PDF) for a normal X ∼ N(μ, σ^2 ) is:
f (^) X (x) =
σ
2 π
e−^
1 2 (^
x−μ σ )
2
Notice the x in the exponent of the PDF function. When x is equal to the mean (μ), then e is raised to the power of 0 and the PDF is maximized.
By design, a normal has E[X] = μ and Var(X ) = σ^2.
If X is a normal RV such that X ∼ N (μ, σ^2 ) and Y = aX + b (Y is a linear transform of X), then Y is also a normal RV where:
Y ∼ N (a μ + b, a^2 σ^2 )
For any normal RV X we can find a linear transform from X to the standard normal N ( 0 , 1 ). That is, if you subtract the mean (μ) of the normal and divide by the standard deviation (σ), the result is distributed according to the standard normal. We can prove this mathematically. Let W = Xσ− μ:
W =
X − μ σ
transform X: subtract μ and divide by σ
σ
μ σ
use algebra to rewrite the equation
= aX + b where a =
σ
, b = −
μ σ ∼ N (a μ + b, a^2 σ^2 ) the linear transform of a normal is another normal
∼ N (
μ σ
μ σ
σ^2 σ^2
) substituting values in for a and b
∼ N ( 0 , 1 ) the standard normal
1 Formally, it has the highest entropy H (X ) = −
∫ dx f (x) log f (x) of any distribution given the mean and variance.
An extremely common use of this transform is to express FX (x), the CDF of X, in terms of the CDF of Z, FZ (x). Since the CDF of Z is so common it gets its own Greek symbol: Φ(x)
FX (x) = P(X ≤ x)
= P
X − μ σ
x − μ σ
x − μ σ
( (^) x − μ
σ
Why is this useful? Well, in the days when we couldn’t call scipy.stats.norm.cdf (or on exams, when one doesn’t have a calculator), people would look up values of the CDF in a table (see the last page of these notes). Using the standard normal means you only need to build a table of one distribution, rather than an indefinite number of tables for all the different values of μ and σ!
We also have an online calculator on the CS 109 website. You should learn how to use the normal table for the exams, however!
What is the PDF of the standard normal Z? Let’s plug it in:
f (^) Z (z) =
σ
2 π
e−^
1 2 (^
z−μ σ )
2 π
e−^
2 π
e−^
1 2 z^2
This gets even better if we realize that √^12 π is just a constant to make the whole thing integrate to 1.
Call that constant C: f (^) Z (z) = Ce−^
(^12) z 2
Not so scary anymore, is it? In fact, this equation can be a rather helpful mnemonic: the normal distribution PDF is just the exponential of a parabola. What does that look like?
f (z) = −^12 z^2 f (z) = e−^
1 2 z^2
As it turns out, the exponential of a (downward) parabola is a familiar shape: the “bell curve”. Now bring back the fact that Z = Xσ− μ, and you can see that μ determines where the “peak” of the bell curve will be, while σ tells you how wide it is. (Don’t forget that C changes too!)
Lets say our binomial is a random variable X ∼ Bin( 100 , 0. 5 ) and we want to calculate P(X ≥ 55 ). We could cheat by using the closest fit normal (in this case Y ∼ N ( 50 , 25 )). How did we chose that particular Normal? I simply selected one with a mean and variance that matches the Binomial expectation and variance. The binomial expectation is np = 100 · 0. 5 = 50. The Binomial variance is np( 1 − p) = 100 · 0. 5 · 0. 5 = 25.
Since Y ≈ X then P(X ≥ 55 ) seems like it should be ≈ P(Y ≥ 55 ). That is almost true. It turns out that there is a formal mathematical reason why the normal is a good approximation of the binomial as long as the Binomial parameter p is reasonable (eg in the range [0. 3 to 0 .7]) and n is large enough. However! There was an oversight in our logic. Let’s look a bit closer at the binomial we are approximating.
Since we want to approximate P(X ≥ 55 ), our goal is to calculate the sum of all of the columns in the Binomial PMF from 55 and up (all those dark columns). If we calculate the probability that the approximating Normal random variable takes on a value greater than 55 P(Y ≥ 55 ) we will get the integral starting at the vertical dashed line. Hey! That’s not where the columns start. Really
we want the area under the curve starting half way between 54 and 55. The correct approximation would be to calculate P(X ≥ 54. 5 ).
Yep, that adds an annoying layer of complexity. The simple idea is that when you approximate a discrete distribution with a continuous one, if you are not careful your approximating integral will only include half of one of your boundary values. In this case we were only adding half of the column for P(X = 55 )). The correction is called the continuity correction.
You can use a Normal distribution to approximate a Binomial X ∼ Bin(n, p). To do so define a normal Y ∼ (E[X], V ar (X )). Using the Binomial formulas for expectation and variance, Y ∼ (np, np( 1 − p)). This approximation holds for large n and moderate p. Since a Normal is continuous and Binomial is discrete we have to use a continuity correction to discretize the Normal.
P(X = k) ∼ P
k −
< Y < k +
k − np + 0. 5 √ np( 1 − p)
k − np − 0. 5 √ np( 1 − p)
You should get comfortable deciding what continuity correction to use. Here are a few examples of discrete probability questions and the continuity correction:
Discrete (Binomial) probability question Equivalent continuous probability question P(X = 6 ) P( 5. 5 < X < 6. 5 ) P(X ≥ 6 ) P(X > 5. 5 ) P(X > 6 ) P(X > 6. 5 ) P(X < 6 ) P(X < 5. 5 ) P(X ≤ 6 ) P(X < 6. 5 )
100 visitors to your website are given a new design. Let X = # of people who were given the new design and spend more time on your website. Your CEO will endorse the new design if X ≥ 65. What is P(CEO endorses change|it has no effect)?
E[X] = np = 50. V ar (X ) = np( 1 − p) = 25. σ =
(V ar (X )) = 5. We can thus use a Normal approximation: Y ∼ N ( 50 , 25 ).
P(X ≥ 65 ) ≈ P(Y > 64. 5 ) = P
Stanford accepts 2480 students and each student has a 68% chance of attending. Let X = # students who will attend. X ∼ Bin( 2480 , 0. 68 ). What is P(X > 1745 )?
E[X] = np = 1686. 4. V ar (X ) = np( 1 − p) = 539. 7. σ =
(V ar (X )) = 23. 23. We can thus use a Normal approximation: Y ∼ N ( 1686. 4 , 539. 7 ).
P(X > 1745 ) ≈ P(Y > 1745. 5 ) = P