What is Analytics?
• The science of using data to build models that lead to
better decisions that add value to individuals, to companies, to
institutions
• Descriptive analytics: identify patterns in the data
• Summary statistics
• Hypothesis Test
• Visualizations
• Clustering
• Predictive analytics: predict different outcomes
• Linear Regression
• Logistic Regression, CART, Random Forests
• Prescriptive analytics: give advice on actions to take
2
Objectives
1. RV, Discrete random variable; Define and calculate the expected value, standard
deviation, and variance for discrete probability distributions.
2. Define continuous random variables & articulate the similarities and differences
between continuous and discrete random variables.
3. Normal Distribution
3
Random Variables: The Motivation
Now, we want to
We now know how to
focus on the
find probabilities of
distribution of
random outcomes.
outcomes.
Distributions tell us useful information…
1. The spread of possible outcomes.
2. The shape of the possible outcomes (centered around the average, or
skewed).
3. Upper and lower bounds of outcomes.
4
Random Variables: The Motivation
Rolling One Dice: Probability Distribution Function
P(x)
5
Random Variable
Random Variable (represented with a capital letter)
▪ A numerical description of the outcome of an experiment
– assigns a real number to every possible outcome or event in a statistical
experiment such that the numbers represent mutually exclusive and collectively
exhaustive events.
▪ A discrete RV can only assume a finite or limited set of values.
▪ X = the number of newspapers sold during the day.
▪ A continuous RV has an infinite or an unlimited set of possible values.
▪ X = the average temperature tomorrow
▪ Y = the lifetime of a lightbulb.
▪ Z = the time it takes to finish a project.
6
Probability Distribution
▪ Probability distribution assigns the probability to each numerical value
of a random variable.
▪ Discrete and continuous probability distribution
▪ Popular distributions
▪ Binomial distribution
▪ Poisson distribution
▪ Exponential distribution
▪ Normal distribution
▪ …
7
Probability Distribution: Discrete RV
▪ The probability distribution of a random variable describes how
probabilities are distributed over the values of the random variable.
▪ For each possible outcome 𝑥𝑖 (mutually exclusive and collectively
exhaustive), there is a probability value 𝑃 𝑥𝑖 or 𝑃 𝑋 = 𝑥𝑖 .
▪ These values must be between 0 and 1: 0 ≤ 𝑃 𝑥𝑖 ≤ 1.
▪ They must sum up to 1: σ𝑛
𝑖=1 𝑃 𝑥𝑖 = 1.
8
Probability Distribution: Discrete RV
The probability distribution of a random variable describes how probabilities
are distributed over the values of the random variable.
Number of customers in Probability
a day (x) P(X = x)
The discrete The probability
0 P(X = 0) = 0.1
random variable X “X equals to”
1 P (X = 1) = 0.4 different values
2 P (X = 2) = 0.25 (0,1,2,3, or 4).
Possible values of
the discrete 3 P (X = 3) = 0.15
random variable X 4 P (X = 4) = 0.1
For a discrete random variable, the distribution is also called probability
mass function (pmf).
Quick Check: What is P(X < 3)? P(X < 3) = P(X = 0) + P(X = 1) + P(X = 2) = 0.75
9
Cumulative Distribution: The cdf
The cumulative distribution of a random variable X describes the probability that
the outcome of X will be a value less than or equal to x. It is usually denoted with
𝐹 𝑥 = 𝑃 𝑋 ≤ 𝑥 and is abbreviated as cdf (cumulative distribution function).
Number of Probability Cumulative
customers in a day P(X = x) F(x)
(x)
0 P(X = 0) = 0.1 P (X ≤ 0) = 0.1
1 P(X = 1) = 0.4 P (X ≤ 1) = 0.5
2 P(X = 2) = 0.25 P (X ≤ 2) = 0.75
3 P(X = 3) = 0.15 P (X ≤ 3) = 0.9
4 P(X = 4) = 0.1 P (X ≤ 4) = 1
Quick Check: What is F(2)? F(2) = P(X≤ 2) = 0.75
10
PMF VS CDF
Probability Distribution P(X = x) Cumulative Distribution F(x)
0.4
1
0.9
0.75
0.25
P(X = x)
F(x)
0.5
0.15
0.1 0.1
0.1
0 1 2 3 4 0 1 2 3 4
Number of customers in a day (x) Number of customers in a day (x)
11
What is the expected value of X?
▪ The expected value is a measure of central tendency of a probability
distribution, and
– It is the probability-weighted average of all possible outcomes, i.e, it is defined
as
𝑛
𝜇 = 𝐸 𝑋 = 𝑋𝑖 ∙ 𝑃 𝑋𝑖 = 𝑋1 ∙ 𝑃 𝑋1 + 𝑋2 ∙ 𝑃 𝑋2 + ⋯ + 𝑋𝑛 ∙ 𝑃 𝑋𝑛
𝑖=1
▪ The expected value is NOT the most likely outcome. Also, it is NOT the
middle value. Instead, the expected value represents the long-term
average.
12
Expected Value of X: Example
Let 𝑋 ∈ 0,1,2,3,4 be a discrete random variable that gives the number of
customers that arrive in the restaurant between 6 am and 7 am. X has
probability mass function P(X = x) shown in the table below.
Number of customers Probability
between 6 and 7am (x) P(X = x)
0 0.1
1 0.4
2 0.25
3 0.15
4 0.1
What is the expected number of customers that will arrive in the store between
6 and 7am?
E[X] = (0)(0.1) + (1)(0.4) + (2)(0.25) + (3)(0.15) + (4)(0.1)
= 1.75 customers
13
What is the variance of X?
▪ The variance of a discrete random variable is a measure of spread in the data.
▪ It is the probability-weighted sum of its squared deviations from its mean:
X2 = Var[ X ] = E[( X − X )2 ] = [ x − E ( X )]2 P( x)
The gap Likelihood
between x and of gap
E[X].
x1 x2 x3 E[X] x4 x5
14
What is the variance of X?
The following discrete distributions have the same expected value,
E[X] = 2, but different variances: 1
0.9
0.8
Variance = 1.1
0.7
0.6
Variance = 0
0.5
1 0.4
0.9 0.3
0.8 0.2
0.7 0.1
0.6 0
0.5 0 1 2 3 4
0.4
1
0.3
0.2 0.9
0.1 0.8
Variance = 2
0 0.7
0 1 2 3 4 0.6
0.5
0.4
0.3
0.2
0.1
0
0 1 2 3 4
15
What is the standard deviation of X?
▪ The standard deviation of a discrete random variable X is ALSO a measure
of spread in the data.
▪ Mathematically, it is the square root of the variance
X = Stdev[ X ] = Var[ X ]
*We like standard deviation because it is in the same units as X, meaning it
gives a measure of spread/dispersion that makes sense to us!
16
Calculating Standard Deviation and Variance
E[X] = 1.75 customers 𝑉𝑎𝑟 𝑋 = (𝑥 − 𝐸[𝑋])2 ∗ 𝑃(𝑋 = 𝑥)
Number of
Probability (𝑥 − 𝐸[𝑋])2
customers in a x-E[x] (𝑥 − 𝐸[𝑋])2
P(X = x) ∗ 𝑃(𝑋 = 𝑥)
day (x)
0 0.1
1 0.4
2 0.25
3 0.15
4 0.1
17
Objectives
1. RV, Discrete random variable; Define and calculate the expected value, standard
deviation, and variance for discrete probability distributions.
2. Define continuous random variables & articulate the similarities and differences
between continuous and discrete random variables.
3. Normal Distribution
18
Discrete vs. Continuous Variables: Probability Distributions
Discrete or Continuous?
0.9
0.8
0.7
0.6
Probability
0.5
0.4
0.3
0.2
0.1
0
5' or shorter Over 5', but less than 6' 6' or taller
Height
19
Discrete vs. Continuous Variables: Probability Distributions
Discrete or Continuous?
0.12
0.1
0.08
Probability
0.06
0.04
0.02
5'11"
5'10"
5'0"
5'1"
5'2"
5'3"
5'4"
5'5"
5'6"
5'7"
5'8"
5'9"
6'0"
6'1"
6'2"
6'3"
6'4"
6'5"
6'6"
Height
20
Discrete vs. Continuous Variables: Probability Distributions
Discrete or Continuous?
0.016
0.014
0.012
0.01
Probability
0.008
0.006
0.004
0.002
0
5.11
5.16
5.21
5.41
5.46
5.66
5.71
5.91
5.96
6.16
6.21
6.41
6.46
5.01
5.06
5.26
5.31
5.36
5.51
5.56
5.61
5.76
5.81
5.86
6.01
6.06
6.11
6.26
6.31
6.36
Height
21
Discrete vs. Continuous Variables: Probability Distributions
Continuous Random Variables
– Instead of a pmf table or chart… we have a probability density
function (pdf), denoted as f(x), that tells us the height of the curve at
X = x.
❑ f(x) is NOT the same as P(X = x)
For all continuous random variables P(X = x) = 0
22
Discrete vs. Continuous Variables: Probability Distributions
Why does P(X = x) = 0 for any value of x when X is a continuous random variable?
Assume X is continuous.
– Let X = the length of a human hair. What is P(X = 6 cm)?
– Let X = the length of a human hair. What is P(X = 6.186574 cm)?
The implication is, when X is continuous (not discrete):
P(X < x) = P (X ≤ x)
P(X > x) = P (X ≥ x)
23
Discrete vs. Continuous Variables: Probability Distributions
Continuous Random Variables
– Instead of a pmf table or chart… we have a probability density
function (pdf), denoted as f(x), that tells us the height of the curve at
X = x.
❑ f(x) is NOT the same as P(X = x)
For all continuous random variables P(X = x) = 0
– Instead of a cdf table or chart… we have a cumulative distribution
function (cdf) F(x) = P(X≤ x).
❑ This is the same in theory as in the discrete case, but because X is
continuous, you cannot enumerate and add up all values like in
the discrete case.
❑ Instead, take the area under the curve of the pdf
(Not Required)
24
Probability Distribution: Continuous RV
▪ Example
▪ 𝑊 = the weight of a particular machined part
Density
f 𝑃 5.22 ≤ 𝑊 ≤ 5.26
= 𝐹 5.26 − 𝐹 5.22
5.26
=න 𝑓 𝑊 𝑑𝑊
5.22
25
Discrete vs. Continuous Variables: Probability Distributions
Properties of the pdf of a continuous random variable.
1. f(x) gives the height of the pdf curve at the value x
2. f(x) is always non-negative
3. The total area under the curve of f(x) is always 1 (because the sum of all probabilities of all possible outcomes
must sum to 1).
4. The probability of x being in the range between A and B is the area under the curve between A and B.
26
Discrete vs. Continuous Variables: Probability Distributions
Let X be the surface temperature of the moon (in oF)
1. What is f(50) ? The height of the curve at x = 50.
2. Find P(50<X<100) = Area under curve between 50 and 100.
3. Find P(X≤50)= Area under curve to the left of 50.
4. Find P(- ≤ X ≤ )= 1
Higher values of f(x) indicates greater
likelihood of taking value around here
PDF of X Total area “under the
curve” (shaded) is 1
50 100
X could belong to a finite or infinite range.
27
Continuous Distribution Function Example
Let X be the surface temperature of the moon (in oF)
1. Find P(X ≤ 100)= 0.6 and P(X < 190)= 0.95
2. Find P(100 < X < 190) = 0.95 – 0.60 = 0.35
3. Find P(X > 190)= 1 – 0.95 = 0.05
.95
.6
CDF of X
100 190
28
Expected Value and Variance of Continuous Random Variables (Not Required)
The Expected Value of a continuous random variable is
𝑏
𝐸[𝑋] = න 𝑥. 𝑓 𝑥 𝑑𝑥
𝑎
The Variance of a continuous random variable is
𝑏
Var[𝑋] = 𝑥( 𝑎 − 𝐸 𝑋 )2 𝑓 𝑥 𝑑𝑥
*here a is the minimum value of X, and b is the maximum value of X
29
Independent of RVs (Not Required)
Two random variables X and Y are independent if and only if, for every x
and y, the events {𝑋 ≤ 𝑥} and {𝑌 ≤ 𝑦} are independent events.
𝑃 𝑋 ≤ 𝑥, 𝑌 ≤ 𝑦 = 𝑃 𝑋 ≤ 𝑥 ⋅ 𝑃(𝑌 ≤ 𝑦)
30
Objectives
1. RV, Discrete random variable; Define and calculate the expected value, standard
deviation, and variance for discrete probability distributions.
2. Define continuous random variables & articulate the similarities and differences
between continuous and discrete random variables.
3. Normal Distribution
31
The Normal Distribution
Normal random variable X
• X = any continuous measure
• It can take on any continuous units (feet, test scores, etc.)
• Most commonly used to model symmetric quantities that have a
“central tendency” with concentration around the center.
Properties and Assumptions of the Normal Distribution
1. Infinite Range (between -∞ and +∞), so negative values allowed.
2. Symmetric around the mean.
32
Normal Distribution
▪ The normal distribution is the most popular and useful continuous
probability distribution.
▪ E.g., return of a stock portfolio, and test scores.
▪ The probability density function is (Not Required)
1 𝑥−𝜇 2
−
𝑓 𝑥 = ∙ 𝑒 2𝜎2
𝜎 2𝜋
▪ The normal distribution is specified completely when we know the
mean 𝐸(𝑋), 𝜇, and the standard deviation, 𝜎. We often use the
notation 𝑁 𝜇, 𝜎 2 .
34
Normal Distribution
▪ Normal distribution with different 𝜇. (shape unchanged)
| | |
40 = 50 60
Smaller , same
| | |
= 40 50 60
Larger , same
| | |
40 50 = 60
35
Normal Distribution
▪ Normal distribution with different 𝜎. (always symmetric)
Same , smaller
Same , larger
36
Normal Distribution
37
Standard Normal Distribution
Standard normal distribution: N(0, 1)
𝑋−𝜇
If 𝑿~𝑵 𝝁, 𝝈𝟐 , then 𝑍 = 𝜎
follows standard normal distribution.
𝑥−𝜇
z = 𝜎 represents the number of standard deviations from a number
x to the mean, 𝜇
38
Standard Normal Distribution: Example
▪ If 𝑋 follows normal distribution with mean 𝜇 = 100, 𝜎 = 15, and we are
interested in finding the probability that X is less than 130, then
𝑃 𝑋 ≤ 130 = 𝑃(𝑍 ≤ 𝑧), z=?
39
Standard Normal Distribution: Z Table
P(Z<0.57)?
If P(Z<z) = 0.65, z?
z = 2.00, the area is 0.97725, P(X<130)?
Areas under the normal curve
40
In-class Exercise
▪ If 𝑋 follows normal distribution with mean 𝜇 = 100 and s.d. 𝜎 = 22,
then 𝑃 𝑋 < 120 = ?
40
Finding the x value
▪ If 𝑋 follows normal distribution with mean 𝜇 = 100 and s.d. 𝜎 = 22 and
we want 𝑋 to be less than a certain value with probability 0.8, then how
to find this value? Or 𝑃 𝑋 < ? = 0.8.
▪ Step 1: Finding the z value corresponding to 𝑃 𝑋 < 𝑥 .
▪ If we need 𝑥 for 𝑃 𝑋 < 𝑥 , find 𝑧 corresponding to 𝑃 𝑋 < 𝑥 .
▪ If we need 𝑥 for 𝑃 𝑋 > 𝑥 , find 𝑧 corresponding to 1 − 𝑃 𝑋 > 𝑥 .
▪ 𝑧0.8 = 0.84
▪ Step 2: Setting 𝑥 to 𝑥𝑧 = 𝜇 + 𝑧 ∙ 𝜎.
𝑋−𝜇
▪ 𝑃 𝑋 < 𝑥𝑧 = 𝑃 𝑋 < 𝜇 + 𝑧 ∙ 𝜎 = 𝑃 <𝑧 =𝑃 𝑍<𝑧 =𝑃 𝑋<𝑥
𝜎
▪ 𝑃 𝑋 < 100 + 𝑧0.8 × 22 = 𝑃 𝑋 < 118.48 = 0.8
42
Haynes Construction Company
▪ Builds three- and four-unit apartment buildings
▪ Total construction time follows a normal distribution
▪ For triplexes, μ = 100 days and σ = 20 days
▪ Contract calls for completion in 125 days
▪ Late completion will incur a severe penalty fee
▪ Probability of completing in 125 days?
𝑃 𝑋 < 125 = 𝑃 𝑍 < 1.25 =
0.8944
= 100 days
= 20 days
x = 125 days
43
Haynes Construction Company
▪ If finished in 75 days or less, bonus = $5,000. Probability of bonus?
▪ 𝑃 𝑋 < 75 = 𝑃 𝑍 < −1.25
▪ = 𝑃 𝑍 > 1.25 = 1 − 𝑃 𝑍 < 1.25 = 1 - 0.8944 = 0.1056
▪ What is the probability of completing between 110 and 125 days?
▪ 𝑃 110 < 𝑋 < 125 = 𝑃 𝑋 < 125 − 𝑃 𝑋 < 110
= 0.8944 – P(Z<0.5)
= 0.8944 – 0.6915
= 0.2029
110 days 125 days
44
Haynes Construction Company
▪ Suppose Haynes can hire more workers to reduce the mean
construction time while keeping the standard deviation constant.
Hence, to ensure a penalty is avoided with probability 0.95, what should
be the new mean?
𝑋 ′ −𝜇 125−𝜇
▪ Objective: find 𝜇 such that 𝑃 𝑋′ < 125 = 𝑃 < = 0.95
20 20
▪ Step 1: 𝑧0.95 = 1.645
125−𝜇
▪ Step 2: find 𝜇 such that = 1.645; 𝜇 = 92.1
20
45