correlation(
data,
variables=None,
year=None,
*,
method='pearson',
digits=2,
title=None,
ref=None,
)
Correlations between the variables of a panel in one year.
Parameters
| data |
|
A dataset id, or a panel with geo_id (and year), e.g. from load |
required |
| variables |
|
The numeric columns to correlate (default: every numeric variable; ids and the year are left out) |
None |
| year |
|
The year to use (default: the last with data for the first variable), or "all" to pool every year |
None |
| method |
str |
"pearson" (linear), "spearman" (ranks) or "kendall": the coefficient of the matrix and the heatmap |
'pearson' |
| digits |
int |
Decimals written in the heatmap and the table |
2 |
| title |
str | None |
The figure and table title |
None |
Notes
Only the observations with data for every variable are used, so that all the coefficients refer to the same units.
Returns
|
CorrelationResult |
A result with .df (the correlation matrix), .pairs (one row per pair, from the strongest positive to the strongest negative), .fig (a heatmap centred at zero with the coefficients in the cells), .gt (a table with Pearson above the diagonal and Spearman below), .n (observations), .variables, .year, .notes and .interpret(). |
Example
!pip install -q geo4bolivia
import geo4bolivia as geo
res = geo.correlation("sdg01", year=2024)
print(res.interpret())
res.fig
Pearson correlations between 5 variables in 2024, on the 343 observations with data for all of them.
The strongest positive correlation is between Multidimensional poverty index (0-1) and Unsatisfied basic needs (% of population) (r = 0.82): a strong association, in which units with more of one tend to have more of the other.
The strongest negative correlation is between No poverty index (0-100) and Unsatisfied basic needs (% of population) (r = -0.94): a strong association, in which units with more of one tend to have less of the other.
The weakest correlation, in either direction, is between Energy poverty (% of dwellings) and Access to the 3 basic services (% of households) (r = -0.46).
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.