Lecture 21 – Spread, The Normal Distribution
DSC 10, Fall 2022
Announcements
Homework 6 is due tomorrow at 11:59pm.
Lab 7 is due Saturday 11/19 at 11:59pm.
The Final Project is released, and has two deadlines:
The checkpoint is due Thursday 11/17 at 11:59pm. No slip days!
The final submission is due Tuesday 11/29 at 11:59pm. Slip days allowed.
Tomorrow from 10-11am in the SDSC Auditorium, come talk to Janine, Suraj, and other HDSI faculty at the HDSI faculty/student mixer!
Agenda
Recap: Mean and median.
Standard deviation.
Standardization.
The normal distribution.
Recap: Mean and median
Example: Flight delays ✈️
Question: Which is larger – the mean or the median?
Comparing the mean and median
Mean: Balance point of the histogram.
Numerically: the sum of the differences between all data points and the mean is 0.
Physically: Think of a see-saw.
Median: Half-way point of the data.
Half of the area of a histogram is to the left of the median, and half is to the right.
If the distribution is symmetric about a value, then that value is both the mean and the median.
If the distribution is skewed, then the mean is pulled away from the median in the direction of the tail.
Key property: The median is more robust (less sensitive) to outliers.
Standard deviation
Question: How "wide" is a distribution?
One idea:
The range quantifes how far the extreme values are from one another (max - min).
Issue: this doesn’t tell us much about the shape of the distribution.
Another idea:
The mean is at the center.
The standard deviation quantifies how far the data points typically are from the center.
Deviations from the mean
Each entry in deviations describes how far the corresponding element in data is from 4.25.
What is the average deviation?
This is true of any dataset – the average deviation from the mean is always 0.
This implies that the average deviation itself is not useful in measuring the spread of data.
Average squared deviation
This quantity, the average squared deviation from the mean, is called the variance.
Standard deviation
Our data usually has units, e.g. dollars.
The variance is in "squared" units, e.g. .
To account for this, we can take the square root of the variance, and the result is called the standard deviation.
Standard deviation
The standard deviation (SD) measures something about how far the data values are from their average.
It is not directly interpretable because of the squaring and square rooting.
But generally, larger SD = more spread out.
The standard deviation has the same units as the original data.
numpyhas a function,np.std, that calculates the standard deviation for us.
Variance and standard deviation
To summarize:
where is the number of observations.
What can we do with the standard deviation?
It turns out, in any numerical distribution, the bulk of the data are in the range “mean ± a few SDs”.
Let's make this more precise.
Chebyshev’s inequality
Fact: In any numerical distribution, the proportion of values in the range “mean ± SDs” is at least
| Range | Proportion |
|---|---|
| mean ± 2 SDs | at least (75%) |
| mean ± 3 SDs | at least (88.88..%) |
| mean ± 4 SDs | at least (93.75%) |
| mean ± 5 SDs | at least (96%) |
Flight delays, revisited
Mean and standard deviation
Chebyshev's inequality tells us that
At least 75% of delays are in the following interval:
At least 88.88% of delays are in the following interval:
Let's visualize these intervals!
Chebyshev's inequality provides lower bounds!
Remember, Chebyshev's inequality states that at least of values are within SDs from the mean, for any numerical distribution.
For instance, it tells us that at least 75% of delays are in the following interval:
However, in this case, a much larger fraction of delays are in that interval.
If we know more about the shape of the distribution, we can provide better guarantees for the proportion of values within SDs of the mean.
Activity
For a particular set of data points, Chebyshev's inequality states that at least of the data points are between -20 and 40. What is the standard deviation of the data?
Click here to see the answer after you've tried it yourself.
Chebyshev's inequality states that at least of values are within standard deviations of the mean.
When , .
So, -20 is 3 standard deviations below the mean, and 40 is 3 standard deviations above the mean.
10 is in the middle of -20 and 40, so the mean is 10.
3 standard deviations are between 10 and 40, so 1 standard deviation is .
Standardization
Heights and weights 📏
We'll work with a data set containing the heights and weights of 5000 adult males.
Distributions of height and weight
Let's look at the distributions of both numerical variables.
Observation: The two distributions look like shifted and stretched versions of the same basic shape, called a bell curve 🔔.
Standard units
Suppose is a numerical variable, and is one value of that variable. The function $$z(x_i) = \frac{x_i - \text{mean of $xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}{\text{SD of xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}$
converts to standard units, which represents the number of standard deviations is above the mean.
Example: Suppose someone weighs 225 pounds. What is their weight in standard units?
Interpretation: 225 is 1.92 standard deviations above the mean weight.
225 becomes 1.92 in standard units.
Standardization
The process of converting all values of a variable (i.e. a column) to standard units is known as standardization, and the resulting values are considered to be standardized.
The effect of standardization
Standardized variables have:
A mean of 0.
An SD of 1.
We often standardize variables to bring them to the same scale.
Aside: To quickly see summary statistics for a numerical Series, use the .describe() Series method.
Let's look at how the process of standardization works visually.
Standardized histograms
Now that we've standardized the distributions of height and weight, let's see how they look on the same set of axes.
These both look pretty similar!
The standard normal distribution
The standard normal distribution
The distributions we've seen look essentially the same once standardized.
This distribution is called the standard normal distribution. The shape is called the standard normal curve.
You don't need to know the formula – just the shape!
We'll just use the formula today to make plots.
The standard normal curve
Heights/weights are roughly normal
If a distribution follows this shape, we say it is roughly normal.
The standard normal distribution
Think of the normal distribution as a "continuous histogram".
Its mean and median are both 0 – it is symmetric.
It has inflection points at .
More on this later.
Like a histogram:
The area between and is the proportion of values between and .
The total area underneath the normal curve is is 1.
Cumulative density functions
The cumulative density function (CDF) of a distribution is a function that takes in a value and returns the proportion of values in the distribution that are less than or equal to , i.e. the area under the curve to the left of .
To find areas under curves, we typically use integration (calculus). However, the standard normal curve has no closed-form integral.
Often, people refer to tables that contain approximations of the CDF of the standard normal distribution.
We'll use an approximation built into the
scipymodule in Python. The functionscipy.stats.norm.cdf(z)computes the area under the standard normal curve to the left ofz.
Areas under the standard normal curve
What does scipy.stats.norm.cdf(0) evaluate to? Why?
Areas under the standard normal curve
Suppose we want to find the area to the right of 2 under the standard normal curve.
The following expression gives us the area to the left of 2.
However, since the total area under the standard normal curve is 1:
$$\text{area right of } = 1 - (\text{area left of })$$
Areas under the standard normal curve
How might we use stats.norm.cdf to compute the area between -1 and 0?
Strategy:
$$\text{area from $-1$ to } = (\text{area left of }) - (\text{area left of })$$
General strategy for finding area
The area under a standard normal curve in the interval is
What can we do with this? We're about to see!
Using the normal distribution
Let's return to our data set of heights and weights.
As we saw before, both variables are roughly normal. What benefit is there to knowing that the two distributions are roughly normal?
Standard units and the normal distribution
Key idea: The -axis in a plot of the standard normal distribution is in standard units.
For instance, the area between -1 and 1 is the proportion of values within 1 standard deviation of the mean.
Suppose a distribution is (roughly) normal. Then, these are two are approximately equal:
The proportion of values in the distribution between and .
The area between and under the standard normal curve. (Recall, ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: … \text{mean of xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}{\text{SD of xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}.)
Example: Proportion of weights between 200 and 225 pounds
Let's suppose, as is often the case, that we don't have access to the entire distribution of weights, just the mean and SD.
Using just this information, we can estimate the proportion of weights between 200 and 225 pounds:
Convert 200 to standard units.
Convert 225 to standard units.
Use
stats.norm.cdfto find the area between (1) and (2).
Checking the approximation
Since we have access to the entire set of weights, we can compute the true proportion of weights between 200 and 225 pounds.
Pretty good for an approximation! 🤩
Warning: Standardization doesn't make a distribution normal!
Consider the distribution of delays from earlier in the lecture.
The distribution above does not look normal. It won't look normal even if we standardize it. By standardizing a distribution, all we do is move it horizontally and stretch it vertically – the shape itself doesn't change.
Summary, next time
Summary: Spread and Chebyshev's inequality
Variance and standard deviation (SD) quantify how spread out data points are.
Standard deviation is the square root of variance.
Roughly speaking, the standard deviation describes how far values in a dataset typically are from the mean.
Chebyshev's inequality states that, in any numerical distribution, the proportion of values within SDs of the mean is at least .
The true proportion of values within SDs of the mean may be larger than , depending on the distribution, but it cannot be smaller.
Summary: Standard units and the normal distribution
To convert a value from a column to standard units, use the function ParseError: KaTeX parse error: Unexpected end of input in a macro argument, expected '}' at end of input: … \text{mean of xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}{\text{SD of xParseError: KaTeX parse error: Expected 'EOF', got '}' at position 1: }̲}.
A value in standard units measures the number of SDs the value is above the mean.
The normal distribution is bell-shaped, and arises often in nature.
The -axis of the standard normal distribution is in standard units.
If we know a distribution is roughly normal, and we know its mean and SD, then we can use the standard normal distribution's curve to approximate the proportion of values within a given range without needing access to all of the data.
Next time
More properties of the normal distribution, and how they relate to Chebyshev's inequality.
The Central Limit Theorem.
Confidence intervals, revisited.