3
$\begingroup$

I’m trying to specify (and interpret) a LMM using data with the following factorial design:

• Condition (Active/Sham: between-subjects) • Session (1/2/3: within-subjects) • nbacklevel (1/2: within-subjects)

I have used dummy coding for now, which I know makes interpretation difficult when there is >1 factor (and/or factors with >2 levels).

My question is, is it important to specify variables as factors when building a LMM? I ask this because I get different outputs when the variables are or are not specified as factors. For example, when I specify Session and nbacklevel as factors I get the following output for the fixed-effects:

enter image description here

Here is it correct to interpret that Active is the reference category for Condition, Session 1 is the reference category for Session and nbacklevel 1 is the reference category for nbacklevel? And if so, the coefficient for Session2 would represent the difference between Session 2 and Session 1 for the active group at nbacklevel 1?

However, if session and n-back level aren’t coded as factors I get the following output:

Fixed effects: vis_hits ~ Condition * Session + nbacklevel
Value Std.Error DF t-value p-value
(Intercept) -0.5666667 0.19462010 7 -2.911655 0.0226
ConditionSham 3.1333333 0.21473498 0 14.591630 NaN
Session 0.9750000 0.07028852 7 13.871397 0.0000
nbacklevel 0.5666667 0.08116219 7 6.981904 0.0002
ConditionSham:Session -0.1000000 0.09940298 7 -1.006006 0.3479

Here, again Active is the reference category for Condition, but I can't work out what 'Session' or 'nbacklevel' would show you and what it does to the intercept value. The values for Intercept and ConditionSham are different, and less interpretable to me. I've been told that 'Session' is the slope for the Active condition, but I don't follow why that is the case?

Any help would be appreciated! Thanks.

$\endgroup$

1 Answer 1

1
$\begingroup$

This isn't really anytyhing to do with mixed models, but rather about how to code variables for regression models in general.

So the general rule is that if a variable is categorical, then it should always be a factor. Then you can use default contrast coding, or whatever other scheme you want for contrasts. By default the reference level for the factor will be included in the estimate for the intercept, and the estimates for the other levels will be contrasts with the reference level.

If you code a categorical variable as numeric, such as 1,2,3, then you are saying that the level 3 implies 3 times the quantity of that factor as level 1. So if you had for example eye colour, that would not make sense at all if you coded them, say, as 1 for blue, 2 for brown and 3 for other. When there is some natural ordering to the variable, such as low, medium, high, the same applies - if you code then 1,2,3 as a numeric variable you are saying that the high category represents 3 times as much of that variable as the low category. In this case you may want to code it as an ordered factor, or leave it as just a regular (unordered) factor. When a variable could be either, for instance time points, then it is a modelling decision as to how to encode it. If you leave it as numeric then you will estimate a linear trend, where the intercept would be the estimated response when the variable is zero. By encoding it as a factor, you will get a seperate estimate for all levels apart from the reference level, so this can sometimes be a good way to assess nonlinear associations - but of course you can allow for nonlinear associations with numeric variables by introducing nonlinear terms such as quadratic or splines.

For your specific case it looks like you should code them as factors. This is kind of given away in the name of the model - it's a "factorial design"

$\endgroup$
2
  • 1
    $\begingroup$ Thank you Robert! That's a great help with some useful examples. My variables definitely need to be factors in that case. $\endgroup$
    – sbooth
    Jun 7, 2021 at 7:56
  • $\begingroup$ You're welcome :) $\endgroup$ Jun 7, 2021 at 8:18

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.