2
$\begingroup$

I have a logistic mixed-effects model with multiple predictors:

y ~ (x1 + x2 + x3)*x4 + x5 + (x1 + x2 + x3 | id), family = "binomial"

I would like to know whether the interaction between, let's say, x1 and x4 (both continuous variables), is statistically significantly different from the interaction between x2 (also continuous) and x4. Is it possible to do so? What methods should I use?

Notes based on EdM's comment: x1 and x2 represent differences between two options based on a certain aspect of each option. To make this more concrete, let's say (as a toy example) that you are choosing between apples and oranges. y is whether you choose apples (0) or oranges (1). x1 could be the difference (oranges-apples) in calories between apples and oranges. x2 could be the difference in tastiness between oranges and apples. Your choice of what to eat will depend on both x1 and x2. However, the two may interact with x4 - let's say that x4 is time of the year. The later in the year, the stronger/weaker the effects of x1 and x2 may be. I want to know whether the interaction between x1 and x4 is different than that between x2 and x4. x1 and x2 are roughly on the scale, because they are both divided by their own standard deviation. However, the values are not exactly z-scored because the 0-value is meaningful, so I did not center them.

Thanks!

$\endgroup$
7
  • 1
    $\begingroup$ check out "contrasts". $\endgroup$ Commented Nov 5, 2022 at 20:38
  • 1
    $\begingroup$ Please look at the second paragraph of this answer. This comparison might make sense if x1 and x2 are effectively on the same scale, but otherwise such comparison is tricky. It would help if you could edit the question to provide more details about the model, the variables involved, and what you hope to gain from comparing the interactions. Please provide such extra information by editing the question, as comments are easy to overlook and can be deleted. $\endgroup$
    – EdM
    Commented Nov 6, 2022 at 7:03
  • $\begingroup$ @EdM please let me know if this helps $\endgroup$
    – gimi
    Commented Nov 6, 2022 at 15:34
  • $\begingroup$ @JohnMadden could you expand? $\endgroup$
    – gimi
    Commented Nov 6, 2022 at 15:34
  • 2
    $\begingroup$ @gimi You sure are ;) no need for categorical variables for contrasts to work; see Ed's answer. $\endgroup$ Commented Nov 6, 2022 at 18:18

1 Answer 1

2
$\begingroup$

If the predictors x1 and x2 are on the same scale, one approach would be to examine whether the interaction-coefficient estimates $\beta_{x_1 :x_4}$ and $\beta_{x_2 :x_4}$ can be distinguished statistically. The null hypothesis would be that $\beta_{x_1 :x_4}-\beta_{x_2 :x_4}=0$. A linear combination of variables that equals 0 is called a contrast in statistics.

To test that hypothesis you need to estimate the standard error of that difference. For that you need to use the formula for the variance of a weighted sum of correlated variables. In this case:

$$\text{Var}(\beta_{x_1 :x_4}-\beta_{x_2 :x_4})= \text{Var}(\beta_{x_1 :x_4}) + \text{Var}(\beta_{x_2 :x_4})-2\text{Cov}(\beta_{x_1 :x_4},\beta_{x_2 :x_4})$$

The variances and covariance on the right side of the equation are found in the coefficient variance-covariance matrix provided by the model. Take the square root of the result for the standard error, SE. With a generalized linear model the coefficient estimates have an asymptotic multivariate normal distribution, so you use a z-statistic $(\beta_{x_1 :x_4}-\beta_{x_2 :x_4})/\text{SE}$ to evaluate whether the difference in coefficients is statistically different from 0.

There are software tools that can make this easier and less error-prone, particularly for more complicated comparisons. This page illustrates the linearHypothesis() function of the R car package.

You should be very careful in the case of your model, however. The above will only evaluate the fixed-effect interactions, while you have random slopes involving those variables. It also assumes that x3 is constant. The usefulness of the comparison also depends on having both x1 and x2 on the same scale.

It might be more informative to illustrate predictions from the model under specific scenarios. See the help page for predict.merMod() in the lme4 package. If you are going to include random effects in your predictions, also see the bootMer() help page.

$\endgroup$
4
  • 1
    $\begingroup$ Thanks! Could you explain why the assumption that x3 is constant is necessary, and what you mean by that? $\endgroup$
    – gimi
    Commented Nov 6, 2022 at 18:14
  • $\begingroup$ @gimi x3 is also in an interaction with x4. You say in part: "let's say that x4 is time of the year. The later in the year, the stronger/weaker the effects of x1 and x2 may be." If you are comparing multiple scenarios (e.g., a range values of x1 against a range of values of x2 at a set of x4 values), then the value of x3 must be the same in all comparisons for the $\beta_{x_1 :x_4}$ and $\beta_{x_2 :x_4}$ coefficients to capture the role of x4 totally. If $x_3$ varies, you have to add in the contribution from $\beta_{x_3 :x_4} x_3 x_4$ for valid prediction. $\endgroup$
    – EdM
    Commented Nov 6, 2022 at 18:35
  • $\begingroup$ thanks again! How do you do that in r with car::linearHypothesis? So far I have car::linearHypothesis(model, c("x1:x4 = x2:x4")) but I'm not sure how to account for x3 $\endgroup$
    – gimi
    Commented Nov 6, 2022 at 19:14
  • $\begingroup$ @gimi if x3 is constant then you don't have to account for it and you are done. If you want to compare scenarios with different values of the predictors, see the functions in the last paragraph of the answer. $\endgroup$
    – EdM
    Commented Nov 6, 2022 at 20:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.