Skip to content

ENH: interaction effect, two-way, generic definition #9482

Open

Description

@josef-pkt

I'm trying to find a usable definition of interaction effect that is independent of a specific functional form and encoding of categorical variables
related issues for interaction, two way anova posthoc
#9480 ...
#6799 tukey-hsd for two-way

marginal effects of x1 are independent of x2

df / dx1 is the same for all values of x2, i.e. second derivative is zero
d (df / dx1) / dx2 = 0 at all values of x1 and x2
which defines interaction effect as second cross derivatives d^2 f / (dx1 dx2)

in continuous those are just derivatives, in discrete, categorical case, we need discrete differences
Delta f, delta x_i
discrete change at starting point (x1, x2)_0 = (a, b) moving to some (x1, x2)
marginal effect of x1 : f(x1, b) - f(a, b) should not vary with x2 (i.e. b) i.e.
f(x1, b) - f(a, b) = f(x1, x2) - f(a, x2), if equality does not hold, then we have interaction effect
(similar to diff in diff, in 2x2 case)

additivity and additive changes

e.g. second or higher order taylor series expansion
f(a + dx1, f(b + dx2) - f(a, b) = sum of marginal effects changing only one variable at a time
all cross derivatives are zero
If f(a + dx1, f(b + dx2) - f(a, b) - sum of marginal effects changing only one variable at a time is not zero, then it is an interaction effect.
example f(x1, x2) = f1(x1) + f2(x2) + g(x1, x2)
marginal effect of x1: df_1 = f1'(x1) dx1 + dg/dx1 * dx1 which depends on value of x2 through g.

cases by data type

If x1, x2 are continuous, counts (integers) or ordinal, then from any x_i we can only go "up", dx has only one direction to go.
If and xi is categorical/factor (or network node), then we can go to several directions from starting x_i. In the categorical case those changes are given by all pairwise comparisons.
In two-way, two factor case, k1xk2 we have ki * (ki - 1) / 2 pairwise comparisons (ignoring going the opposite direction).
So, we have ki * (k1 - 1) / 2 * k2 * (k2 - 1) / 2 pairs of pairwise comparisons.
(simple interaction contrasts in Hancock, McNeish 2017)

Based on this we can construct multiple testing hypothesis and, e.g.

  • individual interaction effect is zero
  • two or more interaction effects are the same
  • arbitrary contrasts/restrictions defined through linear transformations

Specific details in the two-way, two factor literature. (maybe also diff in diff literature)

continuous categorical interaction
suppose x1 is continuous (assumed to be linear) and x2 is categorical,
model: y = 1 + x1 + x2 + x1 : x2, i.e. linear in x1 where slope depends on level of x2
joint hypothesis: all slopes of x1 are the same, i.e. no interaction
multiple testing: pairwise comparison in x2 of slopes of x1, we have k2 * (k2 - 1) / 2 slope coefficient comparisons similar to one factor pairwise comparison.
related: marginal effects with interactions. we could also do pairwise comparison there if a categorical variable is involved, e.g. #5387

Note:
This refers to direct effect, e.g. linear model or linear predictor in single-index models, GLM, Poisson, ....
Single index models always have the additional indirect cross-effect through changes in the value of the linear predictor because of the nonlinearity in the inverse link function.

Implementation for two-way interaction, two-factors:
We need to get a standardized representation out of the formula and params, e.g. (partial, i.e. ignoring other exog) cell means in the 2dim table of k1xk2 possible pairs of exog values.
Currently we only have it for one-way factors.

Activity

  1. josef-pkt commented on Jan 20, 2025

    @josef-pkt
    MemberAuthor

    I found R package phia that looks at interaction effects

    https://cran.r-project.org/web/packages/phia/vignettes/phia.pdf
    (Based on the examples in the vignette, they use Holm for multiple p-value correction. This would be also our default for generic multiple testing corrections, outside specific oneway cases Tukey-hsd, Games-Howell and similar)

    found though literature that cites
    Marascuilo, Leonard A., and Joel R. Levin. 1970. “Appropriate Post Hoc Comparisons for Interaction and Nested Hypotheses in Analysis of Variance Designs: The Elimination of Type IV Errors.” American Educational Research Journal 7 (3): 397–421. https://doi.org/10.3102/00028312007003397.

    which in turn is cited by
    Kitsche, A., and F. Schaarschmidt. 2015. “Analysis of Statistical Interactions in Factorial Experiments.” Journal of Agronomy and Crop Science 201 (1): 69–79. https://doi.org/10.1111/jac.12076.
    they include examples with 3-way interactions
    they also have a github repo that includes their data, e.g. https://github.com/AKitsche/statint/blob/master/data/beans.txt

    another article cited for some theory (also appendix)
    Boik, Robert J. 1993. “The Analysis of Two-Factor Interactions in Fixed Effects Linear Models.” Journal of Educational Statistics 18 (1): 1–40. https://doi.org/10.3102/10769986018001001.

    and many more articles on interactions in two-way or multi-way anova.
    (It's not clear yet which articles are useful to go through in detail)

  2. added this to the 0.16 milestone on Jan 20, 2025
  3. josef-pkt commented on Jan 20, 2025

    @josef-pkt
    MemberAuthor

    another possible implementation issue

    if we compute predicted cell means and base inference on those, then we need the covariance of the mean estimates.
    #8890

    AFAIR:
    The current test like t_test_pairwise compute this internally but there is not support for getting multivariate prediction with the corresponding cov/cov_params. t_test is vectorized and only returns standard errors and inference (tvalues, pvalues) for each test.
    get_prediction is single return or vectorized return.

  4. josef-pkt commented on Jan 20, 2025

    @josef-pkt
    MemberAuthor

    (I have not looked at the nonlinear, GLM/Logit/..., cases)

    for example: this article works with odds-ratio in the Logit case

    VanderWeele, Tyler J., and Mirjam J. Knol. 2014. “A Tutorial on Interaction.” Epidemiologic Methods 3 (1): 33–72. https://doi.org/10.1515/em-2013-0005.

    another one, I did not look explicitly for: continuous-binary interaction:

    Brambor, Thomas, William Roberts Clark, and Matt Golder. 2006. “Understanding Interaction Models: Improving Empirical Analyses.” Political Analysis 14 (1): 63–82. https://doi.org/10.1093/pan/mpi014

    over 7400 citations
    looks like a good starting point for interaction in a field not focused on just factorial interactions
    for example functional form of interaction (multiplicative x1*x2 implies linear marginal effect)

    Hainmueller, Jens, Jonathan Mummolo, and Yiqing Xu. 2019. “How Much Should We Trust Estimates from Multiplicative Interaction Models? Simple Tools to Improve Empirical Practice.” Political Analysis 27 (2): 163–92. https://doi.org/10.1017/pan.2018.46.

  5. josef-pkt commented on Feb 11, 2025

    @josef-pkt
    MemberAuthor

    2 Stata-tip articles on which scale to use for nonlinear interactions, odds-ratio, risk-difference, ...
    (only brief skimming)

    Buis, Maarten L. 2010. “Stata Tip 87: Interpretation of Interactions in Nonlinear Models.” The Stata Journal 10 (2): 305–8. https://doi.org/10.1177/1536867X1001000211.

    Dow, William H., Edward C. Norton, and J. Travis Donahoe. 2019. “Stata Tip 134: Multiplicative and Marginal Interaction Effects in Nonlinear Models.” The Stata Journal 19 (4): 1015–20. https://doi.org/10.1177/1536867X19893644.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions