explore_transition_matrix

source

explore_transition_matrix(
    df,
    var,
    *,
    entity=None,
    time=None,
    n_bins=5,
    bin_method='quantile',
    bin_labels=None,
    lag=1,
    normalize='row',
    caption='Transition Matrix',
    title=None,
    subtitle=None,
)

Period-to-period transition matrix of a discrete (or binned) state within units.

Parameters

Name Type Description Default
df pd.DataFrame Panel data frame. required
var str State variable. Categorical/object variables use their categories; numeric variables are binned into n_bins states. required
entity str | None Panel identifiers (default to those declared via :func:expdpy.set_panel). None
time str | None Panel identifiers (default to those declared via :func:expdpy.set_panel). None
n_bins int Number of bins for a numeric var. 5
bin_method Literal['quantile', 'equal_width'] "quantile" (equal-mass, default) or "equal_width". 'quantile'
bin_labels Sequence[str] | None Optional labels for the bins (length must match the resulting number of bins). None
lag int Number of periods ahead for the transition (default 1). Only consecutive observed periods that are exactly lag apart are counted; gaps are skipped. 1
normalize Literal['row', 'none'] "row" (default) gives conditional transition probabilities; "none" gives raw counts. 'row'
caption str Great Tables header. 'Transition Matrix'

Returns

Name Type Description
TransitionMatrixResult df (K-by-K matrix), counts, fig, gt and states.

Examples

import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def

df = ex.set_labels(load_kuznets(), load_kuznets_data_def(), set_panel=True)
ex.explore_transition_matrix(df, var="gini_regional", n_bins=4).fig