# lmertest: interaction between a categorical and a continuous variable with random slope

Basically I have the following model with drink type (three drinks) and sugar content of the food as predictors of participants' willingness to pay. I have trouble interpreting the output of the summary (fit2) mainly because I have a continuous variable as a predictor. I pasted my output at the end and these are my interpretations for the fixed effects:

1) drink1 &drink 2: they are the comparisons to baseline drink;

2) sugarp: the regression from sugar to wtp for baseline water; 3) drink1:sugarp: the regression from sugar to wtp for drink1 (beta value) compared with baseline drink beta value;

1. Are those interpretations correct? Can someone explain the fixed effects output for me? Also why do I get different results between anova() and summary()?

2. How can I know which drink is set as a baseline and what can I do if I just want to compare all of the drinks without a baseline?

3. To visualize the interaction, should I draw different regression lines for 3 drinks? I used the emmeans R package to do the post hoc and interaction plots that can take the whole model structure into consideration, but I don't think it can deal with continuous predictors. Do you have any recommended packages for the post hoc and plots making?

4. when reporting the results, what parameters should be included?

5. After some research, I realized I can use contr.sum or contra.treatment in my analysis, I do have a water condition which can be a baseline. But I am interested in comparing all three drinks with each other and I think I only get the same p values as ANOVA when I use contra.sum. Any suggestion for this?

My model and the output:

   > anova(fit1)
Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF  DenDF F value  Pr(>F)
drink        1.7208 0.86038     2  40.69  1.6381 0.20690
sugarp       2.2398 2.23978     1 825.71  4.2645 0.03923 *
drink:sugarp 3.5459 1.77296     2 829.86  3.3757 0.03466 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> summary(fit1)
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: wtp ~ drink * sugarp + (drink | ID/food)
Data: data

REML criterion at convergence: 16300.4

Scaled residuals:
Min      1Q  Median      3Q     Max
-4.4593 -0.2890 -0.0406  0.2584  4.4765

Random effects:
Groups   Name           Variance Std.Dev. Corr
food:ID  (Intercept)    1.8874   1.3738
drinkGlucose   0.7650   0.8747   -0.41
drinkSucralose 0.8203   0.9057   -0.44  0.52
ID       (Intercept)    0.5507   0.7421
drinkGlucose   0.2593   0.5092   -0.36
drinkSucralose 0.4603   0.6785   -0.52  0.68
Residual                0.5252   0.7247
Number of obs: 5494, groups:  food:ID, 840; ID, 28

Fixed effects:
Estimate Std. Error         df t value Pr(>|t|)
(Intercept)             1.753803   0.163613  38.867724  10.719  3.6e-13 ***
drinkGlucose           -0.105242   0.116089  41.809531  -0.907  0.36983
drinkSucralose         -0.258070   0.144398  36.061829  -1.787  0.08231 .
sugarp                  0.004529   0.001670 824.021966   2.711  0.00685 **
drinkGlucose:sugarp    -0.003332   0.001288 836.809293  -2.586  0.00987 **
drinkSucralose:sugarp  -0.001466   0.001316 812.753050  -1.114  0.26573
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Correlation of Fixed Effects:
(Intr) drnkGl drnkSc sugarp drnkG:
drinkGlucos -0.390
drinkSucrls -0.508  0.632
sugarp      -0.412  0.203  0.175
drnkGlcs:sg  0.186 -0.447 -0.189 -0.453
drnkScrls:s  0.196 -0.230 -0.368 -0.476  0.513

• R uses the first factor level as baseline. If you don't set them manually, factor levels are in lexical order. Nov 12 '19 at 8:42
• You have to define more clearly what "compare all drinks" means to you. It's best if you write down the exact null hypotheses you want to test. Nov 12 '19 at 8:43
• I have a sugar preload manipulation (water vs sucralose vs glucose), and I guess my hypothesis will be there is willingness to pay difference (my DV) between three drink conditions. Nov 12 '19 at 9:15
• I was asking for formal hypotheses, i.e., expressed with mathematical notation. Nov 12 '19 at 9:36
• the willingness to pay after drinking water is more than the willingness to pay after taking glucose; also wtp (sucralose)> wtp(glucose); and after taking glucose, the willlingness to pay is less sensitive to the sugar content of the food than after taking water and sucralose. Nov 12 '19 at 17:32

Your questions in point (3) can be answered using the emmeans package. To visualize the fitted lines, use

library("emmeans")
emmip(fit1, drink ~ sugarp, cov.reduce = range)


To obtain the slopes of the fitted lines, use

emt <- emtrends(fit1, "drink", var = "sugarp")
emt


To compare those slopes, use

pairs(emt)