Can you average percentages? Why the average of averages lies
Predict why the average of each site's rate isn't the clinic's rate, then fix a calculation that makes that mistake.
Free course. Your Maestro, an AI, .
In the week of September 21, each site had its own no-show rate: Centro 10.1%, Angelópolis 9.8% and Cholula 17.1%. Lucía needs one figure for the whole clinic. Before you see how it's calculated, predict what this program prints.
The first program uses the week's actual appointments. The second changes one thing. Predict both. The programs print their labels in Spanish; the comments in the code tell you what they mean.
Three sites of different sizes
Example 1 of 2
# Week of September 21: no-shows and active appointments for each site.sedes = { "Centro": {"inasistencias": 17, "en_pie": 169}, "Angelópolis": {"inasistencias": 12, "en_pie": 123}, "Cholula": {"inasistencias": 14, "en_pie": 82},}tasas = [s["inasistencias"] / s["en_pie"] for s in sedes.values()]promedio_de_tasas = sum(tasas) / len(tasas)inasistencias = sum(s["inasistencias"] for s in sedes.values())en_pie = sum(s["en_pie"] for s in sedes.values())tasa_clinica = inasistencias / en_pie# Labels in Spanish: "Promedio de las tres tasas" = average of the three rates;# "Tasa de la clínica" = the clinic's rate.print(f"Promedio de las tres tasas: {promedio_de_tasas:.1%}")print(f"Tasa de la clínica: {tasa_clinica:.1%}")A guess is fine. What you write stays in this browser and waits in your course.
Example 2 of 2, opens once you explain this one
The rule: add up the top, add up the bottom, then divide
When you want the rate or the average for a big group made of smaller groups, don't average the small groups' rates. Add up the numerators, add up the denominators, and divide at the end. That way each appointment counts once, no matter which site it happened at.
| No-shows | Active appointments | Rate | |
|---|---|---|---|
| Centro | 17 | 169 | 10.1% |
| Angelópolis | 12 | 123 | 9.8% |
| Cholula | 14 | 82 | 17.1% |
| Clinic | 43 | 374 | 11.5% |
The last row isn't the average of the rows above it: it's the sum of the count columns, divided at the end.
For mean wait time, add the accumulated wait minutes for all completed appointments and divide by the number of completed appointments (6,519 minutes over 331 appointments: 19.7 minutes), rather than giving every site equal weight. That's why the clinic's data has espera_total_min (total wait in minutes) and not a column of averages: with totals and a positive denominator, you can calculate the pooled mean. Group means also work if you keep the group sizes and weight them accordingly; without those sizes, they are not enough.
Where it hides at work
This mistake rarely looks like a mistake. It looks like a spreadsheet with a column of percentages and, at the bottom, a cell labeled Average. Or a pivot table where you ask for the average of a column that was already a rate. Or an AI that hands you "the clinic's rate" without telling you how it got there.
Whenever you see a percentage for a total, ask: what got added up on top, and what got added up on the bottom? If the answer is "someone averaged percentages," be suspicious. If you have a spreadsheet with a column of percentages and an average at the bottom, go over it with your Maestro.
There's one case where the simple average is the answer: when the question is about the groups, not the appointments. "How is the typical site doing?" is a different question from "what share of appointments did we lose?" If you ever need it, give it its own name on the definition sheet, so nobody mistakes it for the clinic's rate.
Try it
In the editor, someone calculated the clinic's rate for the latest week by averaging the nine rates, one per site and specialty. Run the code to see what it prints, then fix the tasa_clinica line so it follows the rule.
Your turn
The code calculates the clinic's no-show rate for the week of September 21 as the average of the nine rates (one per site and specialty), and gets 13.7%. Change only the tasa_clinica line so it adds up the no-shows, adds up the active appointments and divides at the end. You're done when it prints 11.5%, the rate on Lucía's definition sheet.
Data: citas-clinica, 117 rows
| Row | Remove | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | |||||||||||
| 2 | |||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | |||||||||||
| 6 | |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 |
Enter saves; Esc undoes; empty is a missing value
Tab indents; Esc then Tab leaves
If you got 11.5%, compare it with what was there before: the average of the nine rows said 13.7%, more than two points higher. In Cholula's Nutrition row, with 12 active appointments, 3 no-shows make 25%, and that 25% counted in the average as much as Centro's General Medicine row with 97 appointments.
Check yourself: That week, Nutrition at Cholula had 3 no-shows out of 12 active appointments (25%), and General Medicine at Centro had 8 out of 97 (8.2%). What is the rate for the two combined?