Plot the marginal effect of focal across moderator for an interaction model.
Fits dv ~ focal * moderator (+ controls) (| fixed effects) via pyfixest, then traces the marginal effect of focal — b_focal + b_interaction * moderator — across the moderator’s observed range, with a delta-method confidence band. Also reports the average marginal effect (evaluated at the sample-mean moderator).
df (the grid: <moderator>, me, se, ci_lower, ci_upper), fig (the Plotly figure), focal / moderator, and ame / ame_se (the average marginal effect and its standard error).
If no interaction term between focal and moderator is estimated.
Examples
Does the gradient of inequality in income depend on trade openness? Trace the marginal effect of log GDP per capita across the range of the trade share:
The marginal association of **log_gdp_pc** with the outcome is not constant — it depends on **trade_share** (their interaction).
Across the observed range it moves from 0.0254 at trade_share = 0.198 to -0.0765 at trade_share = 1.42.
The association switches sign near trade_share = 0.502: log_gdp_pc relates to the outcome in opposite directions below and above that point.
Averaged over the sample, the marginal association is -0.00904 (statistically significant at the 1% level).
_These are associations, not causal effects. A causal reading needs a research design — see `explain('correlation_vs_causation')`._