Comparing places
Last updated
Which barangay has the most loyal customers? Rank them, and the top and bottom of the list fill up with the smallest places, because small groups swing about by chance. In this lesson you'll see why league tables mislead, draw a funnel plot that shows how much chance alone can move a rate at each size, and match places by their official codes, not their names.
By the end of this lesson you can
- Explain why small groups land at both ends of a ranking
- Read and draw a funnel plot with 95% and 99.8% limits
- Join place data on PSGC codes rather than names
Wrong way: the league table
The owners want to know where the suki card works best, so they can copy what works there. They rank the barangays by the share of card holders still buying in December. Run the cells.
At the top: Sabang, 100%. At the bottom, Malinis at 7.0% and Lumbang at 16.7%. Look at the members column. Sabang has 2 card holders: both still buy, so 100%. Lumbang has 6, and one still buys. One more customer in Lumbang would move it from 16.7% to 33.3%.
This happens in every league table of places, schools or hospitals: the smallest groups land at both ends, because a share from a few people swings a long way by chance. A ranking hides how big each group is, so luck looks like success or failure.
The funnel plot
How much can chance move a share? If the true share is everywhere, a group of people gives a share that varies with the standard error:
It shrinks as grows. Draw lines at and for every size, and they make a funnel: wide on the left for small groups, narrow on the right for big ones. About 95% of places should fall inside the inner lines by chance alone, and 99.8% inside the outer ones. Place each barangay by its size and its share:
card holders in the barangay (square-root scale) →
Hover over or choose a barangay. The dashed lines are the 95% band; the dotted ones, 99.8%.
- Sabang (2 members, 100%) is just above the 95% line, and that line is so wide there that it means little. With 2 people, almost anything can happen.
- Lumbang (6, 16.7%) is well inside: ordinary chance.
- San Jose (29, 48.3%) is just outside the 95% line: worth a look, not yet a finding. With 18 barangays, about one is expected outside the 95% lines by chance.
- Malinis (43, 7.0%) is below even the 99.8% line. Only 3 of 43 still buy. That's very unlikely to be chance.
Drawing one
Run the cells: the funnel in matplotlib, then the places outside the 95% lines, with each one's : how many standard errors it is from the overall rate.
p0: the overall share, 28.3%, from every card holder together.n = np.arange(1, 181): every size from 1 to 180, to draw the lines across the chart.z: Malinis is at −3.10, Sabang +2.25, San Jose +2.39.
So what happened in Malinis? Before anyone visits, check what Malinis means. Its 43 card holders are spread over all four stores: 16 at Batangas, 12 at Tanauan, 8 at Lipa and 7 at Rosario. Is that one barangay, or several with the same name? Step 4 shows why that matters. The funnel points to where to look; finding out why takes a closer look and some questions.
Which Poblacion?
Poblacion is the town centre, and most towns in the Philippines have one or more barangays with that name. Names like San Isidro and Santo Niño repeat across the country. Join two files on the barangay name and the rows of different places get mixed together without any error.
The Philippine Statistics Authority gives every region, province, city or municipality, and barangay a Philippine Standard Geographic Code (PSGC), as 5.8 showed. The code is unique, and its digits nest: the first ones give the region and province, then the town, then the barangay. Census populations, poverty estimates and school data are all published with PSGC codes.
The check: when you join place data, join on the code. If a file only has names, join on town and barangay together, then count the rows before and after (4.3) to catch places that matched twice or not at all. The Tindahan's cards.csv only has the barangay name, so each row of the funnel in step 3 may mix several places. Grouping by store and barangay together is the quick fix; asking for the PSGC code on the card form is the lasting one.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Spiegelhalter, Funnel plots for comparing institutional performance (Statistics in Medicine, 2005): the funnel plot, and the 95% and 99.8% limits
- Philippine Statistics Authority: Philippine Standard Geographic Code: the official codes for every region, province, city, municipality and barangay
- Diez, Çetinkaya-Rundel and Barr, OpenIntro Statistics, 4th ed., section 5.1: the standard error of a proportion