Specifying (and interpreting) LMMs using factorial designs with nlme/lme4 - should variables be coded as factors? 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:

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:

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.
 A: 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"
