from edumath.statistics import describe, five_number_summary, outlier_fences
values = [2, 3, 4, 5, 100]
describe(values)DescriptiveStats(mean=22.8, median=4.0, variance=1863.7, standard_deviation=43.17059184213253, minimum=2.0, maximum=100.0)
Descriptive statistics help you understand a dataset before making conclusions. They answer questions such as: Where is the center? How spread out are the values? Is the distribution symmetric or skewed? Are there unusual values?
After this lesson you should be able to:
1.5 * IQR rule;edumath, Python, and SymPy to verify descriptive calculations.A variable is a characteristic that can vary from individual to individual. Examples include height, exam score, commute time, favorite color, or whether a machine part passed inspection.
Variables can be:
This lesson focuses mostly on quantitative variables.
A measure of center gives one number that represents a typical value.
The mean is the arithmetic average:
mean = sum of values / number of values
The mean is useful when the data are roughly symmetric and do not have extreme outliers. It is sensitive to very large or very small values.
The median is the middle value after sorting the data. If there are two middle values, average them.
The median is more resistant to outliers than the mean.
The mode is the most common value or category. A dataset may have one mode, several modes, or no repeated values.
Spread describes how much the data vary.
range = maximum - minimum
Range is easy to compute but depends only on two values.
Variance averages squared deviations from the mean. Standard deviation is the square root of variance, so it is measured in the original units.
For a sample:
sample variance = sum((value - mean)^2) / (n - 1)
sample standard deviation = sqrt(sample variance)
The n - 1 denominator is used because a sample is estimating a population spread.
Quartiles split sorted data into four parts:
Q1: about 25% of data are at or below this value;median: about 50% are at or below;Q3: about 75% are at or below.The interquartile range is:
IQR = Q3 - Q1
IQR describes the spread of the middle half of the data.
A common rule flags possible outliers below or above these fences:
lower fence = Q1 - 1.5 * IQR
upper fence = Q3 + 1.5 * IQR
Outliers are not automatically mistakes. They are values that deserve attention. They may represent errors, rare events, or important discoveries.
Shape words:
Data:
2, 3, 4, 5, 100
Step 1: Compute the mean.
mean = (2 + 3 + 4 + 5 + 100) / 5
mean = 114 / 5
mean = 22.8
Step 2: Compute the median.
The values are already sorted. The middle value is 4.
Step 3: Interpret.
The mean 22.8 is much larger than most values because 100 is an outlier. The median 4 better represents a typical value in this small dataset.
Data:
4, 6, 8
Step 1: Find the mean.
mean = (4 + 6 + 8) / 3 = 6
Step 2: Find deviations from the mean.
4 - 6 = -2
6 - 6 = 0
8 - 6 = 2
Step 3: Square the deviations.
(-2)^2 = 4
0^2 = 0
2^2 = 4
Step 4: Average with n - 1 for sample variance.
sample variance = (4 + 0 + 4) / (3 - 1) = 8 / 2 = 4
Step 5: Take the square root.
sample standard deviation = sqrt(4) = 2
A neighborhood income dataset is right-skewed because a few households have very large incomes.
Question: Should you report mean, median, or both?
Reasoning:
A careful sentence:
The median income describes the typical household better than the mean because
income is right-skewed, but the mean helps reveal the influence of high incomes.
1, 2, 3, 4, 10.1, 2, 3, 4, 10.Q1=10 and Q3=18, find the IQR and upper outlier fence.(1+2+3+4+10)/5 = 20/5 = 4.3.IQR=18-10=8; upper fence =18+1.5(8)=30.Guess first. For 3, 3, 4, 10, will the mean be larger or smaller than the median?
Guided exercise.
mean = (3+3+4+10)/4 = 5
median = (3+4)/2 = 3.5
The mean is larger because 10 pulls it upward.
Checkpoint. Find the mean and median of 5, 5, 6, 20.
Guess first. If two classes have the same mean but one has a larger standard deviation, what differs?
Guided exercise.
The class with larger standard deviation has scores more spread out around the mean.
Checkpoint. Which dataset has more spread: 9,10,11 or 1,10,19?
Guess first. If Q1=4 and Q3=8, is 20 a possible outlier?
Guided exercise.
IQR = 8 - 4 = 4
upper fence = 8 + 1.5(4) = 14
Since 20 > 14, it is a possible outlier.
Checkpoint. If Q1=12 and Q3=20, find the lower fence.
Guess first. Why should summaries be paired with plots?
Guided exercise.
Two datasets can share the same mean and standard deviation but have different shapes, clusters, or outliers. A histogram or boxplot reveals structure that a few numbers can hide.
Checkpoint. Name one feature a plot can reveal that the mean cannot.
=9; median =5.5.1,10,19 has more spread.=12 - 1.5(8) = 0.Use edumath to compute descriptive summaries.
DescriptiveStats(mean=22.8, median=4.0, variance=1863.7, standard_deviation=43.17059184213253, minimum=2.0, maximum=100.0)
FiveNumberSummary(minimum=2.0, q1=3.0, median=4.0, q3=5.0, maximum=100.0)
Use SymPy to show the algebra of a mean calculation.