Skip to content

random factor of type integer

2 messages · Henrik Pärn, Douglas Bates

#
Dear all,

I have a dataset where the variables that I later will use as random 
grouping factors in a lmer-model are integers. Do I first need to 
convert them to factors?

I just tried if the example on the help page for lmer (where the 
grouping factor 'Subject' actually is a factor)...

str(sleepstudy$Subject)
fm1 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy)
summary(fm1)

...differed from:

Subject2 <- as.integer(as.character(sleepstudy$Subject))
fm2 <- lmer(Reaction ~ Days + (Days|Subject2), sleepstudy)
summary(fm2)

...but it did not.

Is this a general case or could the use of a random factor of integer 
type may cause problems in lmer?

Thanks in advance!

Henrik
#
On Jan 29, 2008 8:26 AM, Henrik Parn <henrik.parn at bio.ntnu.no> wrote:
The short answer is that you do not need to have grouping factors
represented as factors for lmer, but it is advisable.

Internally the variables used as grouping factors for random effects
are converted to factors before being incorporated into the flist
slot.