Skip to content

Continuous variable as random slope and the minimum number of levels for a categorical variable to be treated as random

4 messages · Conor Michael Goold, Michele Scandola

#
Dear all,

I've recently read in this page (https://dynamicecology.
wordpress.com/2015/11/04/is-it-a-fixed-or-random-effect/) the following
text "First you CANNOT treat a continuous variable as a random effect. So
if you are putting area or temperature or body size is in they may be a
nuisance/control variable but they are a fixed effect. Of course you are
only estimating one parameter (the slope) so there is no degree of freedom
cost to treating it as random. And it makes no sense to ask what is the
variance across a continuous variable."
Actually I don't know why it doesn't make any sense ask what is the
variance across a continuous variable.
I've seen the classical example on sleepstudy data which treats a cntinuous
variable as random slope:
fm1 <- lmer (Reaction~Days+(Days|Subject), sleepstudy)
with sleepstudy$Days being a continuous variable, and lmer estimates the
variance of the Days slope.

So... is it OK to use a continuous variable as random slope or not?

Furthermore the post says: "[...] you should not treat a categorical
variable with only two levels (e.g. two sites), also known as a binary
variable, as a random effect. You wouldn?t take two measures and then try
to estimate variance, but that is what you?re asking R to do if you treat
it as random. Beyond that there is a lot of debate. But many people think
<http://stats.stackexchange.com/questions/37647/minimum-number-of-levels-for-a-random-effects-factor>
you
should have at least 5 levels (e.g. 5 sites) before you treat something as
random"

Actually I've seen a lot of GLMMs done with random factors with just 2
levels. Is it acceptable or not?

Thanks in advance,

Michele
#
Hi, 

The post you link to is to treating "random effect" solely as the blocking factor or hierarchical grouping factor in the model, when one wants to estimate different intercept parameters for each of the grouping factors. For instance, when observations are nested within individuals as in the sleep study, then individuals are the grouping factor or the "random effect" and will have their own intercept. Actually, in one of the comments (second one), the author admits he doesn't include the topic of random slopes for brevity. But even with random slope terms, the slope is varying with respect to the same blocking factor as the intercept. 

However, continuous variables that respect order (e.g. different ages) can also be treated as random effects or grouping variables through Gaussian process models. 

When you say you have seen GLMMs with only 2 levels, do you mean random slopes or random intercepts? I'm guessing the former based on your first question. 

The minimum size for a discrete grouping factor is dependent on the exact context (e.g. how many parameters are being estimated), but many recommend 5 as a minimum (although, this would only stand for the simplest of models) and more is always better. For instance, Stegmueller 2013 (http://onlinelibrary.wiley.com/doi/10.1111/ajps.12001/abstract) says that having at least 15-20 levels of the grouping factor in ML estimation is best, whereas Bayesian methods are more robust at lower number of levels per grouping factor. 

Also, as another commenter discussed, the random/fixed effect terms can be confusing and perhaps a better way to think about these sorts of models is simply whether parameters vary by some grouping factor or not. Thus, you could have intercepts or slopes varying with respect to a grouping factor. I prefer to write "Intercepts and the slope of predictor X varied by each individual" rather than "Random intercepts and slopes were included" because I think it's ultimately clearer about what is being done and what readers can expect from the analysis.

Best regards
Conor Goold
PhD Student
Phone:        +47 67 23 27 24



Norwegian University of Life Sciences
Campus ?s. www.nmbu.no
#
Dear Conor,

Thanks a lot for your answers. I don't know why but I have misunderstood
the article, I've thought it was talking about random slopes. Now it makes
sense.
However I didn't know that even continuous, ordered variables can be used
as grouping factors. Do you have any reference about that? The link I've
shared clearly states it is not possible.
However, in your example you have spoken about age. May be a good idea to
use it as a nested grouping factor in the participant grouping factor? I
mean something like (1|subject:age).

Best regards,

Michele


Il 14 Apr 2017 12:50 PM, "Conor Michael Goold" <conor.goold at nmbu.no> ha
scritto:

Hi,

The post you link to is to treating "random effect" solely as the blocking
factor or hierarchical grouping factor in the model, when one wants to
estimate different intercept parameters for each of the grouping factors.
For instance, when observations are nested within individuals as in the
sleep study, then individuals are the grouping factor or the "random
effect" and will have their own intercept. Actually, in one of the comments
(second one), the author admits he doesn't include the topic of random
slopes for brevity. But even with random slope terms, the slope is varying
with respect to the same blocking factor as the intercept.

However, continuous variables that respect order (e.g. different ages) can
also be treated as random effects or grouping variables through Gaussian
process models.

When you say you have seen GLMMs with only 2 levels, do you mean random
slopes or random intercepts? I'm guessing the former based on your first
question.

The minimum size for a discrete grouping factor is dependent on the exact
context (e.g. how many parameters are being estimated), but many recommend
5 as a minimum (although, this would only stand for the simplest of models)
and more is always better. For instance, Stegmueller 2013 (
http://onlinelibrary.wiley.com/doi/10.1111/ajps.12001/abstract) says that
having at least 15-20 levels of the grouping factor in ML estimation is
best, whereas Bayesian methods are more robust at lower number of levels
per grouping factor.

Also, as another commenter discussed, the random/fixed effect terms can be
confusing and perhaps a better way to think about these sorts of models is
simply whether parameters vary by some grouping factor or not. Thus, you
could have intercepts or slopes varying with respect to a grouping factor.
I prefer to write "Intercepts and the slope of predictor X varied by each
individual" rather than "Random intercepts and slopes were included"
because I think it's ultimately clearer about what is being done and what
readers can expect from the analysis.

Best regards
Conor Goold
PhD Student
Phone:        +47 67 23 27 24



Norwegian University of Life Sciences
Campus ?s. www.nmbu.no
#
Dear Michele,


I don't have a good reference to hand, but have a look at Gaussian process models and there will be lots of information. The grouping factor could still be discrete, but Gaussian processes allow the modelling of the covariances between "random effects". For instance, the modelling of spatial autocorrelation within hierarchical levels.


Actually, Richard McElreath has an example of the above in his book Statistical Rethinking, where he models the number of tools in different cultures using a Poisson regression, and using a Gaussian process to represent the correlations among the different cultures (since the number of tools by cultures are spatially correlated).?


Best

Conor