title: negative coefficient of predictor in mixed-effects model produces positive slope in ggplot2
body: <p>I've fitted a mixed-effect regression model to experimental data using the <code>lmer()</code> function in the <code>lme4</code> package in <code>R</code>.</p>
  
  <pre><code>require(lme4)
  
  mod = lmer(y ~ x1 + x2 + x3 + (x1|re1) + (x1|re2), data = dat, REML = FALSE)
  
  summary(mod)
  
  Fixed effects:
                     Estimate   Std. Error     df     t value  Pr(&gt;|t|)    
  (Intercept)       7.008e+00   3.318e-02  4.850e+01  211.166  &lt; 2e-16 ***
  x1                -6.686e-02  2.028e-02  3.400e+01  -3.297   0.00229 ** 
  x2                -4.357e-02  1.313e-02  4.870e+01  -3.318   0.00172 ** 
  x3                -5.302e-03  1.373e-02  7.110e+01  -0.386   0.70054    
  </code></pre>
  
  <p>Notice that the predictor of interest, <code>x1</code>, has a negative coefficient, so I expect the dependent variable to decrease when the predictor of interest increases.</p>
  
  <p>In order to visualize model predictions, I generated model predictions using the <code>predict()</code> function.</p>
  
  <p><code>dat$preds = predict(mod, dat, type = "response")</code></p>
  
  <p>Then I plotted these predictions against the predictor of interest using the <code>ggplot2</code> package.</p>
  
  <pre><code>require(ggplot2)
  
  ggplot(dat, aes(x=x1, y=preds)) +
    geom_point(shape=16, cex=1) +
    geom_smooth(method=lm) +
    xlab("x1") + ylab("predicted y") +
    theme(axis.title=element_text(size=26), axis.text=element_text(size=16))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/wbYBV.png" alt="plot of model predictions y&#39; as a function of variable of interest x1"></p>
  
  <p>I was surprised to see that the slope of the function is positive. But how is that possible, given that the coefficient of that predictor in the model is negative? Is there some error in my code or am I wrong in interpreting the estimate of x1 as a negative slope?</p>