explore_scatter_plot_within_between

source

explore_scatter_plot_within_between(
    df,
    x=None,
    y=None,
    *,
    entity=None,
    time=None,
    show='overlay',
    alpha=None,
    title=None,
    subtitle=None,
)

Scatter that decomposes the x-y relationship into between and within parts.

Three views are drawn (switchable via a dropdown): the pooled cloud, the between cloud of unit means, and the within cloud of unit-demeaned deviations (recentered on the grand means). Their fitted slopes show how a pooled association blends a cross-unit and an over-time relationship.

Parameters

Name Type Description Default
df pd.DataFrame Panel data frame. required
x str | None Numeric column names for the axes. When omitted, they default to the declared roles (:func:expdpy.set_roles): x to the first covariate and y to the main outcome. None
y str | None Numeric column names for the axes. When omitted, they default to the declared roles (:func:expdpy.set_roles): x to the first covariate and y to the main outcome. None
entity str | None Cross-sectional (unit) identifier. Defaults to the panel entity. None
time str | None Time identifier (carried into the hover data). Defaults to the panel time. None
show Literal['overlay', 'pooled', 'between', 'within'] Which view is visible initially: "overlay" (all), "pooled", "between" or "within". 'overlay'
alpha float | None Marker opacity for the pooled/within clouds. Defaults to a sample-size-based value. None

Returns

Name Type Description
WithinBetweenScatterResult df (long plotted frame), fig and the three slopes slope_pooled / slope_between / slope_within.

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_scatter_plot_within_between(
    df, x="log_gdp_pc", y="gini_regional"
).fig