title: Estimate marginal effect in triple interaction
body: <p>I have a model with a triple interaction, similar to this:</p>
  <pre><code>m1 &lt;- lm(mpg ~ am*cyl*hp, mtcars)
  </code></pre>
  <p>I am trying to show how the effect of <code>am</code> changes based on the conditions of <code>cyl</code> and <code>hp</code>. Using the <code>Effect()</code> function from the <code>effects</code> library, I can show the predicted values of <code>mpg</code>. This works well and fairly quickly with my dataset. However, I want to show the size of the gap between the points in each case.</p>
  <pre><code>library(effects)
  p1 &lt;- as.data.frame(Effect(m1, focal.predictors = c(&quot;am&quot;, &quot;cyl&quot;, &quot;hp&quot;), xlevels = list(am=c(0, 1), cyl=c(4,8), hp = c(100, 200))))
  
  library(ggplot2)
  ggplot(p1, aes(cyl, fit, color = as.factor(am))) +
    geom_point(position = position_dodge(0.5)) +
    geom_errorbar(aes(ymin=lower, ymax=upper), width = 0, position = position_dodge(0.5)) +
    facet_grid(~hp)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/TlPyi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TlPyi.png" alt="enter image description here" /></a></p>
  <p>I have tried using the <code>margins()</code> function from the <code>margins</code> library. As shown below. This shows the average marginal effect (AME), which I suppose is what I am trying to show. However, it takes an exorbitant amount of time with my dataset because I control for country fixed effects interacted with year and one of the independent variables.</p>
  <pre><code>p2 &lt;- margins(m1, at=list(cyl = c(4, 8), hp = c(100, 200)), variables = &quot;am&quot;)
  p2 &lt;- summary(p2)
  
  ggplot(p2, aes(cyl, AME, color = as.factor(hp))) +
    geom_point(position = position_dodge(0.5)) +
    geom_errorbar(aes(ymin=lower, ymax=upper), width = 0, position = position_dodge(0.5))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/QiW3A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QiW3A.png" alt="enter image description here" /></a></p>
  <p>Is there a way I can use <code>Effect()</code> to show the estimated gap between predicted values?</p>