!pip install -q geo4boliviaExplore
Before any model, look at the data. This page takes one indicator, the Sustainable Development Index (IDS, from 0 to 100) of Bolivia’s 343 municipalities, through every exploration function of the package, in the order you would use them on a variable you have never seen: summarise it, look at its distribution, find its extremes, see what it goes with, follow it over time, and put it on a map.
Each function returns a result object. Displayed, it shows its figure and a reading of the numbers; .fig, .df, .gt and .interpret() give the parts one by one (Get started explains them).
The data
The dataset sdg holds the index (index_sdg), its national ranking, the census population and the urbanization rate, in two periods stored as the years 2012 and 2024. groups=["department"] adds the name of each municipality’s department, which several steps below use.
import geo4bolivia as geo
sdg = geo.load("sdg", groups=["department"])
sdg.head(4)| geo_id | name | year | department | mun_id | index_sdg | rank_sdg | population | urbanization | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | BO-01-01-01 | Azurduy | 2012 | Chuquisaca | 10201 | 40.8 | 332 | 10652 | NaN |
| 1 | BO-01-01-01 | Azurduy | 2024 | Chuquisaca | 10201 | 54.5 | 297 | 7903 | 0.0 |
| 2 | BO-01-01-02 | Tarvita | 2012 | Chuquisaca | 10202 | 44.5 | 287 | 14261 | NaN |
| 3 | BO-01-01-02 | Tarvita | 2024 | Chuquisaca | 10202 | 53.9 | 306 | 16812 | 0.0 |
1. Summarise
geo.describe() gives the usual summary statistics of each variable in each year, with the variable’s label and unit taken from the metadata.
cols = ["variable", "unit", "year", "count", "mean", "std", "min", "median", "max"]
geo.describe(sdg, variables=["index_sdg", "population", "urbanization"])[cols]| variable | unit | year | count | mean | std | min | median | max | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | index_sdg | index (0-100) | 2012 | 343 | 50.123032 | 5.819148 | 37.2 | 49.6 | 70.5 |
| 1 | index_sdg | index (0-100) | 2024 | 343 | 60.081341 | 5.263740 | 47.3 | 59.8 | 77.3 |
| 2 | population | people | 2012 | 343 | 29329.026239 | 107270.841863 | 509.0 | 10647.0 | 1444425.0 |
| 3 | population | people | 2024 | 343 | 33133.915452 | 116499.083621 | 875.0 | 12296.0 | 1610982.0 |
| 4 | urbanization | % of population | 2012 | 0 | NaN | NaN | NaN | NaN | NaN |
| 5 | urbanization | % of population | 2024 | 343 | 26.580175 | 31.333405 | 0.0 | 14.0 | 100.0 |
Three things to take from this table before going on:
- The index rose: its mean went from 50.1 to 60.1, and its range from 37.2–70.5 to 47.3–77.3.
urbanizationhas acountof 0 in 2012: it exists only for 2024. A summary table is the fastest way to find gaps like this one.populationis very skewed (a few very large values): its mean in 2024 (33,134) is more than two and a half times its median (12,296), because a handful of cities are far larger than the typical municipality.
2. The distribution
A mean hides the shape. geo.distribution() draws a histogram, and with two periods it overlays them on common bins.
geo.distribution(sdg, "index_sdg")Between 2012 and 2024, the mean of Sustainable Development Index, IDS (0-100) rose from 50.1 to 60.1, and the median went from 49.6 to 59.8.
The spread across units narrowed: the standard deviation went from 5.82 to 5.26, and the interquartile range (the middle half of the units) from 7.4 to 7.3.
Sustainable Development Index, IDS (0-100) in 2024 averages 60.1 across 343 units (median 59.8, standard deviation 5.26). Half of the units lie between 56.4 and 63.7, and the full range runs from 47.3 to 77.3. The distribution is roughly symmetric (skewness 0.31).
These are associations, not causal effects. A causal reading needs a research design.
The whole distribution moved to the right by about ten points, and its shape hardly changed: the standard deviation went from 5.82 to 5.26 and the interquartile range (the width of the middle half of the municipalities) from 7.4 to 7.3. The skewness (zero for a symmetric distribution, positive when the long tail is on the high side) is small in both periods, 0.51 and 0.31: a short tail of high-scoring municipalities.
by= compares groups instead of years. A box plot (kind="box") shows each department’s median, its middle half and its unusual municipalities:
geo.distribution(sdg, "index_sdg", by="department", kind="box")By Department in 2024 (9 groups), the median of Sustainable Development Index, IDS (0-100) is highest in Tarija (66.8) and lowest in Potosí (57).
Units differ most within Potosí (standard deviation 6.09) and least within Tarija (3.05). Where the groups’ distributions barely overlap, the differences between groups are large compared with those within them.
In each box, the line is the median and the box holds the middle half of the units; points beyond the whiskers are unusually high or low units.
These are associations, not causal effects. A causal reading needs a research design.
In 2024 the median municipality of Tarija scores 66.8 and that of Potosí 57.0. The departments overlap a great deal, though. The standard deviation within Potosí (6.09) or Cochabamba (6.00) is larger than most of the gaps between department medians, so the department a municipality lies in says only a little about its index. With by, the function uses one year, the last with data; year=2012 gives the other.
3. The extremes
Which municipalities sit at the two ends? geo.extremes() ranks one year (the last, by default) and returns the n highest and lowest.
geo.extremes(sdg, "index_sdg", n=5)Sustainable Development Index, IDS (0-100) in 2024 ranges from 47.3 (TIOC-Raqaypampa) to 77.3 (Nuestra Señora de La Paz) across the 343 units with data; the median unit has 59.8.
The 5 highest: Nuestra Señora de La Paz (77.3), Tarija (74.5), Sucre (74.4), Cochabamba (73.5), El Alto (72.6).
The 5 lowest: TIOC-Raqaypampa (47.3), Tinguipaya (48.4), Ocurí (49.2), TIOC-Territorio Indígena Multiétnico (49.7), Caripuyo (49.8).
The gap between the two ends is 30. Extreme values deserve a second look before any analysis: they may be the most interesting units, very small units whose rates are noisy, or errors in the data.
These are associations, not causal effects. A causal reading needs a research design.
The five highest are large cities: Nuestra Señora de La Paz (77.3), Tarija, Sucre, Cochabamba and El Alto. The five lowest have no urban population: three are in Potosí, and the other two are indigenous territories created since 2015 (TIOC-Raqaypampa, 47.3, and TIOC-Territorio Indígena Multiétnico, 49.7). Thirty points separate the two ends. The table behind the figure is .df, and .gt formats it.
4. What goes with it
geo.correlation() computes the correlation between every pair of variables in one year. It uses only the municipalities with data for all the variables (complete cases), so that every coefficient refers to the same units.
geo.correlation(sdg, ["index_sdg", "urbanization", "population"])Pearson correlations between 3 variables in 2024, on the 343 observations with data for all of them.
The strongest positive correlation is between Sustainable Development Index, IDS (0-100) and Urbanization rate (% of population) (r = 0.56): a moderate association, in which units with more of one tend to have more of the other.
No pair is negatively correlated: the lowest correlation is between Sustainable Development Index, IDS (0-100) and Population (census) (r = 0.37).
The weakest correlation, in either direction, is between Sustainable Development Index, IDS (0-100) and Population (census) (r = 0.37).
A coefficient near +1 or -1 means two variables move together closely, in the same or in opposite directions; near 0, that knowing one says little about the other. The table (.gt) sets Pearson correlations (above the diagonal) against Spearman rank correlations (below): a large gap between the two points to a non-linear relation or to outliers.
These are associations, not causal effects. A causal reading needs a research design.
The index is moderately correlated with urbanization (r = 0.56) and more weakly with population (r = 0.37). The year is 2024 because that is the last year with data, and the only one in which urbanization exists. Pearson’s coefficient measures linear association, and population is far from linear: method="spearman" uses ranks instead, and .gt shows both coefficients in one table.
5. One relationship, closely
A coefficient summarises a cloud of points; geo.scatter() shows the cloud. Here each point is a municipality, coloured by department and sized by population. Hover over a point to see its name.
geo.scatter(sdg, "urbanization", "index_sdg", color="department", size="population")Across 343 units in 2024, Sustainable Development Index, IDS (0-100) and Urbanization rate (% of population) are positively correlated (r = 0.56, a moderate association): units with higher Urbanization rate (% of population) tend to have higher Sustainable Development Index, IDS (0-100).
The least-squares line has a slope of 0.094: one more unit of Urbanization rate (% of population) goes with 0.094 higher Sustainable Development Index, IDS (0-100), on average. The line accounts for 31% of the variation in Sustainable Development Index, IDS (0-100) across units (R² = 0.31); the slope is statistically significant at the 1% level, by a test that treats the units as independent of each other.
These are associations, not causal effects. A causal reading needs a research design.
The least-squares line has a slope of 0.094: ten more percentage points of urban population go with an index about 0.9 points higher, on average. The line accounts for 31% of the variation of the index (R² = 0.31), so most of it is left unexplained. The figure also shows what the coefficient cannot: 158 of the 343 municipalities have no urban population at all and pile up at zero, with indices from 47.3 to 68.7. This is an association between two variables in one year, and many other things differ between urban and rural municipalities.
For a skewed variable such as population, log_x=True puts the axis in logarithms; fit="lowess" replaces the straight line with a local smooth.
6. Over time
geo.trend() follows a variable over time: the mean across units with a band of one standard error, and each unit’s own path as a thin grey line. by= draws one line per group.
geo.trend(sdg, "index_sdg", by="department")Between 2012 and 2024, the mean of Sustainable Development Index, IDS (0-100) across 343 units rose from 50.1 to 60.1 (a change of +9.96).
99.7% of the units with data in both years ended higher than they started: the summary line describes the typical unit, not every unit.
By Department: Pando grew most (+11.5, from 48.5 to 60) and Santa Cruz grew least (+7.79). The gap between the highest and the lowest group narrowed from 11.9 to 10.5.
The band is one standard error on each side of the mean: how precisely the average is known, not how much units differ.
These are associations, not causal effects. A causal reading needs a research design.
The mean rose from 50.1 to 60.1, and 342 of the 343 municipalities ended higher than they started. Every department’s mean rose: Pando’s the most (+11.5) and Santa Cruz’s the least (+7.8), and the gap between the highest and the lowest department mean narrowed from 11.9 to 10.5 points.
With two periods a trend is only two points joined by a line. The same function is more telling on datasets with many years, such as night-time lights (geo.trend("ntl", "ln_NTLpc"), 2012 to 2020).
7. On the map
None of the steps above used the location of the municipalities. geo.map() does. By default it draws the last year on a continuous colour scale:
geo.map(sdg, "index_sdg")A continuous scale shows every difference, and the eye is poor at comparing shades. A classification scheme groups the values into a few classes, one colour each, with the limits in the legend. "fisher_jenks" (natural breaks) puts similar values in the same class; "quantiles" puts the same number of units in each; "equal_interval" makes classes of the same width.
geo.map(sdg, "index_sdg", scheme="fisher_jenks", k=5)The top class (above 68) holds 24 municipalities, 8 of them in the department of Cochabamba; it includes the largest cities (Santa Cruz de la Sierra, El Alto, La Paz, Cochabamba). The bottom class (below 54.9) holds 58. Click a class in the legend to hide or show it.
With a list of years, the maps are drawn side by side in the same classes, computed over both years, so a colour means the same on both maps:
geo.map(sdg, "index_sdg", year=[2012, 2024], scheme="fisher_jenks")In 2012, 108 municipalities were in the lowest class (below 46.9) and 4 in the highest (above 64.3). In 2024 the lowest class is empty and the highest has 72.
To see where the index rose most, map the change itself. change=True computes the last year minus the first for each municipality (as geo.change() does) and uses a diverging scale centred at zero; with a scheme, the classes are split at zero.
geo.map(sdg, "index_sdg", change=True, scheme="fisher_jenks")The only municipality below zero is San José de Chiquitos (Santa Cruz), whose index fell by 2.7 points. The largest gains, above 13.7 points, are in 29 municipalities, most of them in Cochabamba (8), La Paz (6) and Oruro (5). Municipalities that started lower tended to gain more: the correlation between the 2012 level and the change is −0.43.
What the exploration leaves open
The maps suggest that high and low values are not scattered at random, and the last number suggests that the municipalities that started lower caught up. Neither is established by looking. Is the clustering stronger than chance would produce? Did the gaps between municipalities really narrow? What remains of the link with urbanization once neighbours are taken into account?
Where next
- Analyze answers those questions with the same panel: spatial dependence, convergence, transitions, inequality and regression.
- Exploring the data uses the functions of this page to answer questions about multidimensional poverty, and lists the pitfalls of these data.
- Function reference: every option of
describe,distribution,extremes,correlation,scatter,trendandmap.