Courses / Computer Science XI (HSSC-I) – FBISE Complete SLO-Based Course
4.3 Summary Statistics and Data Visuals
Unit 4 – Data and Analysis · 85 min read · 12 MCQs to check yourself
Central tendency and variance – mean, median, mode, IQR, box plot
1. Data and data products
Data are raw facts (numbers, text, images). Information is processed data with meaning. Data products are outputs made from data: tables, summary statistics, charts, dashboards and predictive models.
| Data type | Example |
|---|---|
| Quantitative – discrete | Number of siblings, goals scored |
| Quantitative – continuous | Height, temperature, time |
| Qualitative – categorical (nominal) | Blood group, city, favourite subject |
| Qualitative – ordinal | Grade A/B/C, rating 1–5 stars |
2. Measures of centre
Data: marks of 7 students: 4, 7, 7, 8, 9, 10, 25
- Mean x = (Σ x)/n = 70/7 = 10
- Median = middle value of the sorted data = 8 (for an even count, the average of the two middle values)
- Mode = most frequent value = 7 The outlier 25 pulls the mean up to 10, while the median (8) better represents a typical student.
3. Measures of spread
- Range = max − min = 25 − 4 = 21
- Quartiles: Q1 (25%), Q2 = median (50%), Q3 (75%); IQR = Q3 − Q1
- Variance σ² = (Σ (x - x)²)/n and standard deviation σ = √(σ²) – the typical distance of values from the mean. (For a sample, divide by n - 1 instead.)
Worked SD example: data 2, 4, 4, 4, 5, 5, 7, 9 → mean = 5
| x | x − 5 | (x − 5)² |
|---|---|---|
| 2 | −3 | 9 |
| 4 | −1 | 1 |
| 4 | −1 | 1 |
| 4 | −1 | 1 |
| 5 | 0 | 0 |
| 5 | 0 | 0 |
| 7 | 2 | 4 |
| 9 | 4 | 16 |
| Sum of squares = 32; variance = 32 / 8 = 4; SD = 2. |
import statistics as st
marks = [4, 7, 7, 8, 9, 10, 25]
print("Mean:", st.mean(marks), "Median:", st.median(marks), "Mode:", st.mode(marks))
print("Range:", max(marks) - min(marks))
print("Quartiles:", st.quantiles(marks, n=4, method="inclusive"))
print("SD:", st.pstdev([2, 4, 4, 4, 5, 5, 7, 9]))
Output:
Mean: 10 Median: 8 Mode: 7
Range: 21
Quartiles: [7.0, 8.0, 9.5]
SD: 2.0
In Excel/Sheets: =AVERAGE(A2:A8), =MEDIAN(), =MODE(), =MAX()-MIN(), =QUARTILE(A2:A8, 1), =STDEV.P(), =COUNTIF() for frequency.
4. Box plot (box-and-whisker plot)
A box plot shows the five-number summary: minimum, Q1, median, Q3, maximum. The box covers the middle 50% (the IQR); whiskers reach the smallest and largest values that are not outliers. Outliers are values below Q1 - 1.5 × IQR or above Q3 + 1.5 × IQR, drawn as dots.
5. Choosing the right chart
| Chart | Best for | Axes / reading tips |
|---|---|---|
| Bar chart | Comparing categories (marks per subject, sales per city) | Categories on one axis, values on the other; bars separated |
| Pie chart | Parts of a whole (share of devices used) – percentages add up to 100% | Use for few categories (≤ 6) |
| Line graph | Trends over time (monthly temperature, website visitors) | Time on the x-axis |
| Histogram | Distribution of continuous data in ranges (marks 0–10, 10–20 …) | Bars touch; area shows frequency |
| Scatter plot | Relationship/correlation between two numeric variables | Look for direction and strength of the pattern |
| Box plot | Centre, spread and outliers; comparing groups | Read the median line and the box width |
Reading a plot: (1) identify the type and title; (2) read axis labels and units; (3) look for the overall trend or pattern; (4) note outliers; (5) consider confounding factors and how the data was collected – could the creator's bias or the axis scale (e.g. y-axis not starting at 0) be exaggerating the story?
6. Making charts in Python (matplotlib)
import matplotlib.pyplot as plt
months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
visitors = [120, 150, 140, 200, 260, 310]
plt.plot(months, visitors, marker="o")
plt.title("Website visitors per month")
plt.xlabel("Month")
plt.ylabel("Visitors")
plt.show()
Change plt.plot to plt.bar, plt.pie(values, labels=…), plt.hist(data, bins=10), plt.scatter(x, y) or plt.boxplot(data) for other charts.
Frequency table in Python:
from collections import Counter
grades = ["A", "B", "A", "C", "B", "A", "D", "B", "A"]
for g, f in sorted(Counter(grades).items()):
print(g, f)
Output:
A 4
B 3
C 1
D 1
7. The data process: collect → clean → analyse → visualise → communicate
- Collect: surveys (Google Forms), sensors, existing open data sets (Pakistan Bureau of Statistics, Kaggle, World Bank).
- Clean: remove duplicates, fix spelling ("Lhr", "Lahore"), handle missing values, check impossible values (age 250), use consistent units.
- Analyse: summary statistics, sorting, filtering, pivot tables, correlation.
- Visualise and tell the story: choose the right chart, give a clear title, label axes, highlight the key message ("Visitors more than doubled from January to June").
- Databases and machine learning: organisations store large data in databases (tables of records queried with SQL). Clean, well-structured data from databases is the training data for machine-learning models – poor data gives poor models ("garbage in, garbage out").
Practical (PBA) tasks
- Enter the marks of 20 students in Google Sheets; calculate mean, median, mode, range, quartiles and SD with formulas; create a histogram and a box plot.
- Download a small open data set (e.g. monthly rainfall of your city) and make a line graph; write three sentences describing the trend.
- Write a Python program that reads a list of numbers and prints a frequency table and a bar chart.
Box plots – what they tell us and how to read them
Short and long questions
1. Find the mean, median, mode and range of 4, 7, 7, 8, 9, 10, 25. Which measure best represents the data and why?
Model answer
Mean = 70/7 = 10; median = 8 (middle value); mode = 7; range = 25 − 4 = 21. The median (8) best represents the data because the outlier 25 pulls the mean up.
2. Name the chart you would use for each and give a reason: (a) monthly rainfall for a year (b) share of students using different devices (c) marks of students in five subjects (d) relation between study hours and marks.
Model answer
(a) Line graph – trend over time. (b) Pie chart – parts of a whole. (c) Bar chart – comparison of categories. (d) Scatter plot – relationship between two numeric variables.
3. What is a box plot? What information can be read from it?
Model answer
A box plot (box-and-whisker plot) is a chart of the five-number summary: minimum, Q1, median, Q3 and maximum. From it we can read the centre (median), the spread (IQR = box length, range = whiskers), the skewness (position of the median in the box) and outliers (points beyond 1.5 × IQR); it is useful for comparing groups.
4. Calculate the standard deviation of 2, 4, 4, 4, 5, 5, 7, 9.
Model answer
Mean = 40/8 = 5. Squared deviations: 9, 1, 1, 1, 0, 0, 4, 16 → sum = 32. Variance = 32/8 = 4. SD = √4 = 2.
5. What is data cleaning? Give any four cleaning steps.
Model answer
Data cleaning is preparing raw data by detecting and correcting errors so that analysis is accurate. Steps: (1) remove duplicate records; (2) handle missing values (fill or remove); (3) correct inconsistent spellings/formats ("Lhr" → "Lahore", date formats); (4) remove or check impossible values and outliers (age 250); (5) use consistent units.
6. Differentiate between a bar chart and a histogram.
Model answer
A bar chart compares separate categories (subjects, cities); bars are separated by gaps and can be in any order. A histogram shows the distribution of continuous numerical data grouped into class intervals (marks 0–10, 10–20 …); bars touch each other and the x-axis is a number line.
7. Explain the steps of analysing a pre-existing data set to communicate findings: collecting, cleaning, summarising and visualising. Use the marks 42, 48, 51, 55, 58, 60, 62, 65, 68, 70, 74, 79, 95 to calculate the five-number summary and identify outliers.
Model answer
Steps: (1) Collect/obtain the data set (school records, Kaggle, Pakistan Bureau of Statistics) and understand its variables. (2) Clean – remove duplicates, fix errors, handle missing values, check units. (3) Summarise – mean, median, mode, range, quartiles, SD; frequency tables. (4) Visualise – choose suitable charts (histogram for distribution, box plot for spread/outliers). (5) Interpret and communicate – write the story the data tells and note limitations/bias. Five-number summary (13 values): minimum = 42; Q1 = 55; median = 62 (7th value); Q3 = 70; maximum = 95. IQR = 70 − 55 = 15. Fences: lower = 55 − 1.5 × 15 = 32.5; upper = 70 + 22.5 = 92.5. 95 > 92.5 → 95 is an outlier; no low outliers. In a box plot, the whisker ends at 79 and 95 is shown as a dot.
8. Describe six types of charts (bar, pie, line, histogram, scatter and box plot). For each, state what it is best used for and give an example.
Model answer
- Bar chart – compares values of different categories; e.g. average marks in CS, Maths, Physics.
- Pie chart – shows parts of a whole as percentages; e.g. share of students using mobile, laptop, tablet.
- Line graph – shows change/trend over time; e.g. monthly website visitors.
- Histogram – shows the distribution of continuous data in intervals; e.g. number of students in mark ranges 0–10, 10–20 …
- Scatter plot – shows the relationship and correlation between two numeric variables; e.g. study hours vs marks (with a trend line).
- Box plot – shows median, quartiles, spread and outliers; e.g. comparing marks of Section A and Section B. Good charts have a title, labelled axes with units, a suitable scale (starting at 0 for bar charts) and a clear message.
This lesson ends with a quiz of 12 MCQs. Open the lesson on PrepOasis to take it and save your progress.
Previous: 4.2 Experimental Design: Correlation vs Causation, Population and Sample · Next: Unit 4 Review, SLO Checklist and Unit Test
All lessons in Computer Science XI (HSSC-I) – FBISE Complete SLO-Based Course