distribution(
data,
variable,
year=None,
*,
by=None,
kind='histogram',
bins=30,
title=None,
ref=None,
)
The distribution of a variable across units, per year or per group.
Parameters
| data |
|
A dataset id, or a panel with geo_id (and year), e.g. from load |
required |
| variable |
str |
The numeric column to describe |
required |
| year |
|
A year, a list of years or "all". By default (None) every year is shown next to the others, with one exception: a histogram overlays the years only when the panel has up to four of them, and otherwise shows the last year with data. With by, one year is used: the last with data by default, or every year pooled with "all" |
None |
| by |
str | None |
Compare groups instead of years: a column of the table, or a coarser scale of its units (e.g. the first-level administrative scale), whose names are added |
None |
| kind |
str |
"histogram" (overlaid, on common bins), "box" or "violin" (one per year or group) or "ridgeline" (one density per year or group, stacked) |
'histogram' |
| bins |
int |
Number of bins of the histogram |
30 |
| title |
str | None |
The figure title |
None |
Returns
|
DistributionResult |
A result with .df (one row per year, or per group of by: n, mean, sd, min, p25, median, p75, max and skewness, the sample-adjusted coefficient that is zero for a symmetric distribution), .fig, .kind, .year (when a single year is shown), .notes and .interpret(). |
Example
!pip install -q geo4bolivia
import geo4bolivia as geo
res = geo.distribution("sdg01", "sdg1_2_mpi", by="department", kind="box")
print(res.interpret())
res.fig
By Department in 2024 (9 groups), the median of Multidimensional poverty index (0-1) is highest in Potosí (0.0775) and lowest in Tarija (0.023).
Units differ most within Cochabamba (standard deviation 0.0565) and least within Tarija (0.0125). 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.