# How to examine interactions between factor and covariate in a mixed effects model?

I have 2 factors A and B (5×3) and one covariate X in a within subject design. Here's how I specify my overall model:

lme.out = lme(y~ A*B*X, random=~1|Subject, data=mydata)


My interpretation is that I am looking at a graph y~x, where the slope changes due to the covariate, and the line shifts up or down based on the different levels of A and B (changes in intercepts).

What I want to find out is: if I were to fix factor A (take any of the levels), then looking at the lines (y~x), what is the effect of B? Does the levels of B shift the line up or down (intercepts) or does it alter the slope of the line (X).

Should I be running some sort of contrasts analysis? But I am not sure how contrasts work between factors and covariates.

One way I could think of is to take the subsets of data corresponding to different levels of A and create models such as: lme(y~ B+X, random=~1|Subject, data=mydata[which(mydata\$A = A1,]). This way I could compare the resulting intercepts and slopes across these models.

Can anyone tell me if what I am doing make sense? Suggestions of any kind would be greatly appreciated!

• Do you just want to make graphs to look at these relationships? I think that's a good idea. You can do it with lattice or ggplot or base graphics in R depending on what you are most comfortable with. – Peter Flom - Reinstate Monica Oct 4 '12 at 21:48
• Thanks Peter. I did look at the graphs. Since I have hypotheses regarding how they would behave I am hoping to be able to formally analyse them. – Wynn Oct 4 '12 at 23:05
• Be aware that "My interpretation is that I am looking at a graph y~x, where the slope changes due to the covariate, and the line shifts up or down based on the different levels of A and B (changes in intercepts)." is a little of: the way your fixed effects are set up (ABX), you're estimating a different intercept AND SLOPE IN X for each combination of the levels of A and B. – fabians Feb 20 '14 at 14:11

## 3 Answers

For visualizing interaction terms, you may look at the sjPlot-package (see examples here).

Your function call would be

sjp.int(fit, type ="eff")


I'm not sure, however, if this meets your needs?

I personally think that if you want to examine the true relationship between Y and the factors in your model after controlling for X you should be looking at the plotted adjusted rather than raw means computed from your favorite model. For the purposes there are R packages such as lsmeans which are quite handy and user-friendly!

You can investigate the VIFs of your model. VIF stands for Variance Inflation Factor and is a way to measure co-linearity.

https://onlinecourses.science.psu.edu/stat501/node/347

There is a vif function in the car package for R.