By the end of this lesson, you will be able to calculate and interpret key descriptive statistics—mean, median, mode, standard deviation, and range—to summarize a dataset’s central tendency and spread.
What it is
Descriptive statistics are numerical measures that summarize the main features of a collection of data. Unlike inferential statistics, which make predictions about a larger population, descriptive statistics simply describe what is present in the sample at hand. The mental model involves two primary dimensions: central tendency (where the "middle" of the data lies) and dispersion (how spread out the data is). Key terms include mean (average), median (middle value), mode (most frequent value), variance, and standard deviation.Why it matters
- Data Cleaning: Identifying outliers or errors by spotting values far from the mean or median.
- Baseline Comparison: Establishing a benchmark for performance metrics before applying complex models.
- Communication: Providing concise summaries to stakeholders who do not need raw data details.
- Distribution Insight: Understanding if data is skewed (mean differs significantly from median) helps choose appropriate statistical tests later.
Syntax or steps
To compute descriptive statistics manually or via code, follow these logical steps: 1. Sort the data to find the median and quartiles easily. 2. Calculate the sum of all values divided by the count for themean.
3. Identify the most frequently occurring value for the mode.
4. Compute the average squared difference from the mean for variance, then take the square root for standard deviation.
5. Subtract the minimum value from the maximum value for the range.
Example
The following Python example uses thestatistics module to calculate common descriptive stats for a small dataset representing daily sales figures.
import statistics
# Sample data: Daily sales units
sales_data = [10, 12, 12, 15, 18, 20, 25]
# Central Tendency
mean_val = statistics.mean(sales_data)
median_val = statistics.median(sales_data)
mode_val = statistics.mode(sales_data)
# Dispersion
stdev_val = statistics.stdev(sales_data) # Sample standard deviation
min_val = min(sales_data)
max_val = max(sales_data)
range_val = max_val - min_val
print(f"Mean: {mean_val}")
print(f"Median: {median_val}")
print(f"Mode: {mode_val}")
print(f"Std Dev: {stdev_val:.2f}")
print(f"Range: {range_val}")
Explanation:
statistics.mean() calculates the arithmetic average. statistics.median() finds the middle number (15) when sorted. statistics.mode() identifies 12 as the most frequent value. statistics.stdev() computes the sample standard deviation, indicating how much individual sales vary from the average. Finally, the range shows the total span of sales activity.
Common mistakes
- Ignoring Outliers: Using the mean on heavily skewed data can be misleading. Always check the median alongside the mean.
- Confusing Population vs. Sample: Using population standard deviation formulas on sample data underestimates variability. Use sample formulas (dividing by n-1) unless you have the entire population.
- Reporting Mode for Continuous Data: In continuous datasets with unique values, the mode may not exist or be meaningless. Bin the data first if necessary.
- Overlooking Units: Standard deviation is in the same units as the data, while variance is in squared units. Ensure labels match the metric used.
When to use it
Use descriptive statistics for initial exploration and reporting. Compare them with inferential statistics below.| Feature | Descriptive Statistics | Inferential Statistics |
|---|---|---|
| Purpose | Summarize existing data | Make predictions/generalizations |
| Scope | Sample only | Population based on sample |
| Complexity | Low | High |
Practice
Guided Exercise: Given the dataset[5, 5, 8, 10, 12], calculate the mean and median. Notice how they differ slightly due to the distribution shape.
Challenge: Add an outlier
100 to the previous dataset. Recalculate the mean and median. Observe which measure is more resistant to the extreme value.
Hint: The median should remain stable, while the mean will increase significantly.
Quick check
Question: If your data has a few extremely high values, why might the median be a better summary than the mean?Answer: The median is robust against outliers because it depends only on the position of the middle value, whereas the mean incorporates every value, pulling the average toward the extremes.