Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.7: Statistics functions in sheets, SQL and code

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

Nobody works out 50,000 squares by hand

You have learned to find a mean, a spread and a quartile with a few numbers. Real data has thousands of rows.

Every tool has ready-made formulas for these measures. The skill is to know the name, what it does, and when to use it.

Key words

WordWhat it means
Functiona ready-made calculation with a name
Formulaa calculation typed into a cell, starting with =
Aggregatea function that turns many rows into one value, such as an average
Central tendencya single value for the typical value of the data
Dispersionhow spread out the values are
Positionwhere a value sits when the data is put in order
Interpolatework out a value between two known values
Databasean organised store of tables that you can ask questions
SQLthe language used to ask a database for data

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can name the function for each measure in a spreadsheet, in SQL and in Python, and say when each is used.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

One measure, three tools

MeasureSpreadsheet formulaSQL or DuckDBPython statistics
Mean`=AVERAGE(A1:A8)``avg(score)``mean(data)`
Median`=MEDIAN(A1:A8)``median(score)``median(data)`
Mode`=MODE(A1:A8)``mode(score)``mode(data)`
Minimum and maximum`=MIN(A1:A8)`, `=MAX(A1:A8)``min(score)`, `max(score)``min(data)`, `max(data)`
Standard deviation`=STDEV.P(A1:A8)``stddev_pop(score)``pstdev(data)`
Quartile`=QUARTILE(A1:A8,1)``quantile_cont(score, 0.25)``quantiles(data, method="inclusive")`
Percentile`=PERCENTILE(A1:A8,0.9)``quantile_cont(score, 0.9)``quantiles(data, n=10, method="inclusive")`

The cells students fill in are left blank in this preview.

No spreadsheet here

Important

This platform has no spreadsheet program, so the formulas above are shown as text. DuckDB and Python run the same measures here. On site you use a real spreadsheet program.

Try it: all the measures in DuckDB

Code: duckdb
SELECT count(*) AS n,
       min(score) AS lowest,
       max(score) AS highest,
       avg(score) AS mean,
       median(score) AS median,
       stddev_pop(score) AS sd,
       quantile_cont(score, 0.25) AS q1,
       quantile_cont(score, 0.75) AS q3
FROM scores;

Why the quartiles differ from yours

By hand you found Q1 as 4 and Q3 as 6 for these eight scores. The tool says Q3 is 5.5.

It interpolates: it works out a value between two scores. Both ways are used. What matters is that you know the method and say which you used.

Try it: Python's statistics module

Code: python
from statistics import mean, median, mode, pstdev

data = [2, 4, 4, 4, 5, 5, 7, 9]
print("mean", mean(data))
print("median", median(data))
print("mode", mode(data))
print("pstdev", pstdev(data))

# pstdev is the population form, the one divided by how many.
# statistics.stdev is the sample form. Try it.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.