Section 1 of 8

1 Before you start

Before you begin, take a few minutes to check what you already know and how confident you feel. You will see the same questions again at the end of the module — this helps both you and us measure what you have learned. Click an option for every question and confidence rating, then click Next to continue.

Pre-test

You want the single most common value in a numeric vector, so you call mode(c(2, 2, 5, 7)). What does R actually return?

Pre-test

A data-entry slip records one patient's age as 999. Which measure of location is barely affected by that single extreme value?

Pre-test

Which function returns the middle value of a sorted numeric vector, so that half the patients fall below it and half above?

Pre-test

Which measure of spread should you report alongside the mean?

Pre-test

What does IQR(hba1c) measure?

Pre-test

You summarise a skewed lab by its median. Which measure of spread belongs with it?

Pre-test

A lab variable is strongly right-skewed: the mean sits well above the median. How should you summarise it?

Pre-test

For a roughly symmetric variable such as adult height, what do the mean and median do?

Pre-confidence

I can choose the right measure of location - mean, median, or mode - for a clinical variable, and explain why the median barely moves when one value is extreme.

Not at all confident
Fully confident
Pre-confidence

I can pick the right measure of spread and pair it with its centre, reporting mean (SD) or median (IQR) and never mixing a resistant centre with a non-resistant spread.

Not at all confident
Fully confident
Pre-confidence

I can recognise a right-skewed lab from the gap between the mean and median (or a quick histogram) and switch from mean (SD) to reporting the median (IQR).

Not at all confident
Fully confident
Section 2 of 8

2 Introduction

In Module 2 you learned to reshape and filter a dataset with dplyr verbs. Now you have a clean column of patient values — ages, BMIs, CRP results — and your reader wants the headline. Descriptive statistics is how you turn a column of numbers into the one or two figures that go in a table or the first line of a results paragraph.

This part of the module covers three foundations for summarising a numeric variable:

  • Location — the mean, median, and mode, and choosing which one represents the typical patient.
  • Spread — the standard deviation, variance, IQR, and range, and which spread number pairs with which centre.
  • Shape and skew — spotting when a right-tailed lab pulls the mean away from the median, and switching to median (IQR).

By the end of this part you will be able to summarise a numeric variable with the right centre-and-spread pair, explain why the median and IQR resist a single extreme value while the mean and SD are dragged by it, and recognise a right-skewed lab from the mean-versus-median gap and report median (IQR) instead of mean (SD).

Try every snippet in the R Scratchpad on the right. The dataset patients.csv is already loaded for the centre-and-spread examples, and you will build a small right-skewed CRP cohort with set.seed() so your numbers match the lesson exactly.

Section 3 of 8

3 Measures of location: where the values centre

A measure of location is a single number that stands in for a whole column — the value a typical patient sits near. The three you will use are the mean, the median, and the mode.

The mean is the arithmetic average: add every value, divide by how many there are. You compute it with mean(). For five ages c(10, 12, 14, 16, 18), the mean is 14.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
ages <- c(54, 61, 47, 73, 58)
mean(ages)

The median is the middle value once the numbers are sorted: half the patients fall below it, half above. You compute it with median(). The median barely moves when one value is extreme, which is why it is the safer centre for lab results.

A few extreme values pull the mean toward the tail while the median holds its position, so right-skewed labs should be summarised with the median and IQR rather than the mean and SD.
A few extreme values pull the mean toward the tail while the median holds its position, so right-skewed labs should be summarised with the median and IQR rather than the mean and SD.

Watch what one extreme value does. The median of c(2, 4, 9, 100) is the average of the two middle numbers, 4 and 9 — so 6.5. That single 100 leaves the median almost untouched, but it would drag the mean up past 28.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
median(c(2, 4, 9, 100))

The mode is the most frequent value. It is the only centre that makes sense for a category — the most common treatment arm, the commonest diagnosis. R has no built-in mode() for this (that name means something else), so for a category you read the mode off a count table, which you will build later in this part.

Here is the classic trap. R has a function called mode(), but it returns the storage type of an object, not the most common value. Calling mode(c(1, 1, 2)) gives "numeric", not 1. R does not have a standard built-in function to calculate the statistical mode

Section 4 of 8

4 Measures of spread: how scattered the values are

A centre alone is never enough. Two wards can share a mean HbA1c of 7.5 yet look completely different — one tightly clustered, one swinging from 5 to 11. A measure of spread tells you how scattered the values are around that centre.

The standard deviation (SD) is the typical distance of a value from the mean, in the original units. You compute it with sd(). A small SD means patients cluster near the mean; a large SD means they are spread wide.

The variance is simply the SD squared, computed with var(). It lives in squared units, which is hard to interpret, so you report the SD in a table and keep the variance for the maths underneath.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
hba1c <- c(7.2, 8.1, 6.5, 9.4, 7.8)
mean(hba1c)
sd(hba1c)
Two groups can share the same mean yet differ wildly in spread, and the standard deviation captures that spread as the typical distance of a value from the mean (in the original units), with variance being that quantity squared.
Two groups can share the same mean yet differ wildly in spread, and the standard deviation captures that spread as the typical distance of a value from the mean (in the original units), with variance being that quantity squared.

For the simple ages c(10, 20, 30), the variance is 100 and the SD is its square root, 10.

The range is the lowest and highest value. R's range() returns both as a pair, smallest first — so range(c(3, 9, 1)) gives 1 9. It flags outliers and data-entry errors fast, but a single typo of 999 for 99 blows it wide open, so never report the range as your only measure of spread.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
hba1c <- c(7.2, 8.1, 6.5, 9.4, 7.8)
range(hba1c)

The interquartile range (IQR) is the spread of the middle half of the data: the distance from the 25th percentile up to the 75th. You compute it with IQR(). Like the median, it shrugs off extreme values, so it is the spread you pair with a median. For c(1, 2, 3, 4, 5) the IQR is 2.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
hba1c <- c(7.2, 8.1, 6.5, 9.4, 7.8)
IQR(hba1c)
The range measures spread as the gap from the smallest value to the largest, so one extreme data-entry error can dominate it, whereas the IQR measures only the spread of the middle half from Q1 to Q3 and stays stable under outliers, which is why the IQR is the measure of spread you report alongside the median.
The range measures spread as the gap from the smallest value to the largest, so one extreme data-entry error can dominate it, whereas the IQR measures only the spread of the middle half from Q1 to Q3 and stays stable under outliers, which is why the IQR is the measure of spread you report alongside the median.
Section 4.1 of 8

4.1 Pairing the centre with the right spread

Centre and spread come as matched pairs. Report the mean with the SD — written mean (SD) — because both are pulled the same way by extreme values. Report the median with the IQR — written median (IQR) — because both resist extreme values.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
library(readr)
patients <- read_csv("patients.csv")
mean(patients$bmi)
sd(patients$bmi)
median(patients$bmi)
IQR(patients$bmi)

The mismatched trap is to report the median with the SD, or the mean with the IQR. Mixing a resistant centre with a non-resistant spread tells your reader two contradictory stories about the same column. Keep the pairs together: mean (SD), or median (IQR).

Centre and spread should be reported as matched pairs, mean (SD) or median (IQR), because the mean and SD are both pulled by extreme values while the median and IQR both resist them, so pairing a resistant centre with a non-resistant spread describes the same data in two contradictory ways.
Centre and spread should be reported as matched pairs, mean (SD) or median (IQR), because the mean and SD are both pulled by extreme values while the median and IQR both resist them, so pairing a resistant centre with a non-resistant spread describes the same data in two contradictory ways.
Section 5 of 8

5 Shape and skew: when the mean misleads

The pairing rule has a deeper reason behind it: the shape of the data. When values are roughly symmetric around the centre — like adult height — the mean and median nearly agree, and mean (SD) is honest.

Many clinical labs are not symmetric. They are right-skewed: most patients sit low, but a long tail of high values stretches to the right. C-reactive protein (CRP), triglycerides, and hospital length-of-stay all behave this way — a few very sick patients sit far out in the tail.

When a distribution is symmetric the mean and median coincide and mean (SD) is honest, but a long right tail pulls the mean above the median, so skewed clinical labs are better summarised by the median (IQR).
When a distribution is symmetric the mean and median coincide and mean (SD) is honest, but a long right tail pulls the mean above the median, so skewed clinical labs are better summarised by the median (IQR).

In a right-skewed variable, that tail drags the mean upward but leaves the median in place. So the mean lands above the median, and reporting the mean would overstate the typical patient. The rule of thumb: when the mean and median diverge noticeably, report the median (IQR).

Build a right-skewed CRP cohort and see the gap for yourself. The set.seed() line fixes the random draw so your numbers match this lesson exactly.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
set.seed(42)
crp <- round(rexp(200, rate = 0.2), 1)
mean(crp)
median(crp)
In a right-skewed distribution the long tail pulls the mean above the median, so the median (with IQR) is the honest summary of the typical value.
In a right-skewed distribution the long tail pulls the mean above the median, so the median (with IQR) is the honest summary of the typical value.

The mean comes out clearly above the median — the signature of right skew. A histogram makes the long right tail obvious; a ggplot must be printed at the top level to render, so just name the plot object or call it directly.

Try it out

Try this snippet in the R Scratchpad on the right.

Try this snippet
set.seed(42)
crp <- round(rexp(200, rate = 0.2), 1)
library(ggplot2)
ggplot(data.frame(crp = crp), aes(x = crp)) +
  geom_histogram(bins = 30) +
  labs(x = "CRP (mg/L)", y = "Patients")
In a right-skewed distribution the mean is dragged above the median because the long right tail of high values pulls the balance point rightward, while the median only marks the point where half the patients fall on each side.
In a right-skewed distribution the mean is dragged above the median because the long right tail of high values pulls the balance point rightward, while the median only marks the point where half the patients fall on each side.

The novice trap is to report mean (SD) for an obviously skewed value — an average CRP of, say, 5.1 mg/L when most patients sit near 3. The right way: glance at the mean-versus-median gap (or a quick histogram), and if the variable is skewed, switch to median (IQR).

When a variable is right-skewed, a few high values drag the mean away from the median, so the mean-median gap signals skew and you should report median (IQR) instead of mean (SD).
When a variable is right-skewed, a few high values drag the mean away from the median, so the mean-median gap signals skew and you should report median (IQR) instead of mean (SD).
Section 6 of 8

6 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

You want the single most common value in a numeric vector, so you call mode(c(2, 2, 5, 7)). What does R actually return?

Post-test

A data-entry slip records one patient's age as 999. Which measure of location is barely affected by that single extreme value?

Post-test

Which function returns the middle value of a sorted numeric vector, so that half the patients fall below it and half above?

Post-test

Which measure of spread should you report alongside the mean?

Post-test

What does IQR(hba1c) measure?

Post-test

You summarise a skewed lab by its median. Which measure of spread belongs with it?

Post-test

A lab variable is strongly right-skewed: the mean sits well above the median. How should you summarise it?

Post-test

For a roughly symmetric variable such as adult height, what do the mean and median do?

Post-confidence

I can choose the right measure of location - mean, median, or mode - for a clinical variable, and explain why the median barely moves when one value is extreme.

Not at all confident
Fully confident
Post-confidence

I can pick the right measure of spread and pair it with its centre, reporting mean (SD) or median (IQR) and never mixing a resistant centre with a non-resistant spread.

Not at all confident
Fully confident
Post-confidence

I can recognise a right-skewed lab from the gap between the mean and median (or a quick histogram) and switch from mean (SD) to reporting the median (IQR).

Not at all confident
Fully confident
Section 7 of 8

7 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)