# Ordinal independent variable in mixed model - coding as factor vs continuous

I want to model data from behavioural experiment (mixed model using R's lme4) with continuous DV and two predictors: condition (binary) and block (24 subsequent blocks of experimental task). Both are my fixed effects, and (if model converges) also random effects. I'm wondering how I should handle ordinal block variable given I'm interested in both main effect of block and comparisons of conditions within blocks. Should I code block as factor or continuous (numeric)?

I want to compare conditions within blocks, so if I code block as factor I'm getting such comparisons straight away from the model's summary. But then how I can report if there is main effect of block?

If I code block as numeric (which I think can be justified as all blocks are of equal length etc), my model's output would give me main effect of block and its interaction with condition, but how can I then compare conditions within specific blocks? I have problems with conceptualising pairwise comparisons of binary and continuous variable.

It would be easiest to fit both models (with factor and numeric version of block), and report pairwise comparisons and main effects from them respectively, but I have a feeling that this wouldn't be appropriate - or would it? Any opinions/tips on how should I approach this?

• Are you sure this is a mixed model? If you're interested in main effect of block, then block should be fixed effect. What is random effect then? – Łukasz Deryło May 8 at 10:10
• Right, perhaps I didn't make it clear enough in the main post (now edited): effects of condition and block are both fixed. I'm still considering what random term to choose, but if the model will converge I'll include condition and block there too (if not, then I'll compare models to decide which factor to drop) – Bartosz M May 8 at 11:58
• Now I'm lost. You want to use block (and perhaps condition too) as fixed and random at once? – Łukasz Deryło May 8 at 15:22
• Yes, it's a structure generally recommended in my field: factors included in the fixed term are allowed to vary by each subject (i.e. participant of the experiment) in the random term. So the model is like: y ~ x1 * x2 + (x1 * x2 | subject). (see Barr et al. (2013) Random effects structure for confirmatory hypothesis testing: Keep it maximal) – Bartosz M May 8 at 21:26
• So "subject" is your random effect, and x1 and x2 are fixed. – Łukasz Deryło May 9 at 13:47

When you code your block variable as numeric and use linear model (no matter mixed or no), you silently assume that "distances" between "adjacent" blocks are the same. E.g. distance between block 1 and block 2 is the same as between block 23 and 24. And what is more distance between e.g. block 1 and block 3 is twice as big as between block 23 and 24.
This is equivalent to assumption that difference in your DV is the same between block 1 and black 2 as between block 23 and 24. And what is more difference in your DV between block 1 and block 3 is twice as big as between block 23 and 24. (Holding condition variable constant, of course).
If that's not a realistic assumption, you should code block as factor.
And one more: if block was random effect e.g. you used model like y ~ x + (x|block), block would be treated as factor, no matter how you coded it.