# Can I have a categorical variable (similar to the likert scale) on the predictor side of the equation in lme?

My mixed model looks something like this

weight ~ age + sex + fruits + (subject | time)


The predictor fruit has been converted to a categorical scale of High Medium and Low.

Do I have to set labels and levels to the variable Fruit? Before I enter it into the model?

summary(lol$fruittotaldi) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 0.000 0.000 1.000 1.107 2.000 2.000 2 Linear mixed model fit by maximum likelihood ['lmerMod'] Formula: weight ~ age + sex + treatment + time + treatment * time + factor(fruittotaldi) + (time | code) Data: lol AIC BIC logLik deviance df.resid 619.6 652.3 -297.8 595.6 100 Scaled residuals: Min 1Q Median 3Q Max -1.99904 -0.35179 0.04656 0.38198 1.33412 Random effects: Groups Name Variance Std.Dev. Corr code (Intercept) 151.44427 12.3063 time 0.05832 0.2415 -0.55 Residual 0.91735 0.9578 Number of obs: 112, groups: code, 38 Fixed effects: Estimate Std. Error t value (Intercept) 80.05023 5.61314 14.261 age 0.02017 0.11992 0.168 sexm 7.18388 5.57894 1.288 treatmentb -13.43906 4.08158 -3.293 time -0.37393 0.06007 -6.225 factor(fruittotaldi).L -0.67890 0.30987 -2.191 factor(fruittotaldi).Q 0.86437 0.28231 3.062 treatmentb:time 0.28061 0.08786 3.194 Correlation of Fixed Effects: (Intr) age sexm trtmnt time fc().L fc().Q age -0.865 sexm -0.027 -0.083 treatmentb -0.493 0.187 -0.030 time -0.254 -0.004 0.002 0.352 fctr(frt).L 0.029 -0.046 0.005 0.007 0.115 fctr(frt).Q -0.037 0.036 0.021 0.010 0.031 -0.142 tretmntb:tm 0.176 0.000 -0.004 -0.509 -0.690 -0.120 -0.052  • can you show us what summary(fruits) is ? – Ben Bolker Aug 28 '18 at 15:24 • fruitstotaldi is data converted to categorical scale. Original data was in cup (volume) intake. This data was not normally distributed. Transformation didn't work either. So I converted it to categorical scale of low-medium-high fruit intake based on cups of fruit intake per person. – DiscoStat Aug 28 '18 at 19:48 • @BenBolker Did so in the main text. – DiscoStat Aug 28 '18 at 20:14 ## 2 Answers First of all, there is absolutely no reason that your predictor variables need to be Normally distributed in order to use a linear model or one of its extensions; the only assumptions linear models make about the predictors are that they are measured without error (and even this assumption can be relaxed under certain circumstances). (e.g. see here or here). What's important in numeric predictor variables is whether the expected response is linear, i.e. whether you expect a one-unit change in the predictor to give rise to the same amount of change in the response, regardless of the baseline value of the predictor. If not, you might want to consider transforming the predictor in some way (not because it's not Normal, but because you want to transform it to a scale where a one-unit change will have a constant response). Binning/categorizing continuous predictors is not generally recommended, because it loses information (e.g. see here). However, if you do decide to do so, you should convert your numeric value to an ordered factor, i.e. lol$fruittotaldi <- ordered(lol\$fruittotaldi,
levels=c(0,1,2),
labels=c("low","medium","high"))


This isn't a particularly mixed-model-specific question; ordered (ordinal) predictors are handled similarly across most R packages that fit statistical models. There are a few confusing aspects of factors in R:

• all factors in R have an "order of levels", which determines (1) the baseline level for treatment contrasts; (2) the order in which the levels will be plotted in summaries, shown in graphs, etc..
• the difference between ordered factors and ordinary (non-ordered) factors in R (f <- ordered(f)) is that the default contrasts for ordered factors are polynomial contrasts rather than treatment contrasts; instead of "intercept", "level 2 vs baseline", "level 3 vs baseline", the parameters will refer to "mean", "linear effect", "quadratic effect" ...
• in any case, the overall fit of the model (log-likelihood, AIC, etc. etc.) will be independent of the contrasts/how the factors are defined.
• thanks for this response and the attached papers. I am going to rerun my analysis without categorization as I agree information is lost. I have a question regarding this "What's important in numeric predictor variables is whether the expected response is linear, i.e. whether you expect a one-unit change in the predictor to give rise to the same amount of change in the response, regardless of the baseline value of the predictor" How does one go about testing whether expected response is linear? – DiscoStat Aug 29 '18 at 14:58
• typically, examine the residuals-vs-fitted plots and/or partial residuals plots to see if there are signs that the residuals aren't approximately constant with respect to the predictor – Ben Bolker Aug 29 '18 at 15:04
• Thanks, I just tried ordering fruittotaldi as a factor to see the analysis. How do I interpret the 'L' and 'Q' terms associated with fruittotaldi. I see that they indicated linear and quadratic terms? I have update the initial post with my output. – DiscoStat Aug 29 '18 at 15:33
• this is starting to turn into a bit of a chameleon question ... can you search CV (and Google) to see if there is an existing answer about interpreting the parameters for ordered factors ("orthogonal polynomial" is another useful keyword), and think about whether this should be a new question? – Ben Bolker Aug 29 '18 at 16:27
• thanks, I will do that. I will call this question resolved. – DiscoStat Aug 29 '18 at 17:03

The predictor fruit has been converted to a categorical scale of High Medium and Low.

Not sure about what "has been converted" entails, but if you have used something like fruit <- factor(fruit) and if is.factor(fruit) is indeed true then read on.

R will automatically use the one with the lowest numerical value as your reference group, keeping only the binary indicators of the other two levels in the model. If you wish to change that to some other group, check ?relevel.

• Penguin_Knight thanks! I meant that originally fruit intake data was on a continuous scale and I have manually transformed it into a ordinal scale based on a set of parameters. – DiscoStat Aug 28 '18 at 14:26