[R-sig-ME] Managing person identifier variable

Theodore Lytras thlytras at gmail.com
Wed Oct 5 21:21:38 CEST 2016


Στις Τετάρτη, 5 Οκτωβρίου 2016 6:59:30 Μ.Μ. EEST MACDOUGALL Margaret έγραψε:
> I would be most grateful for some advice in relation to the interpretation
> of a person identifier variable (persID, say),  in R. I would like to
> represent persons, as an independent variable, by a random effect. However,
> there are over 200 such persons. Each person is allocated a random
> numerical code as a unique identifier.  Currently, R is reading the
> identifier variable as a numeric variable. Is there a quick way of
> addressing this problem by recoding the variable?  (I do not wish to bin
> the values into category ranges; rather, I wish to avoid the numerical
> codes being interpreted literally.)

Just recode it as a factor, i.e. factor(persID).

By the way, lme4 does that implicitly if you specify a numeric variable as a 
random effect in a model formula, i.e. you can just say: y ~ x + (1|persID) 
instead of: y ~ x + (1|factor(persID))



More information about the R-sig-mixed-models mailing list