tags:

views:

149

answers:

2

Hi guys ,

How do I specify random factors in R ?

If I have a factor x1 which is supposed to be random , can I try something like this ?

lm(y ~ x1, data = p)

+2  A: 

Are you by chance looking for the lme4 package which is focussed on linear mixed-effects (ie. fixed versus random) modelling?

Dirk Eddelbuettel
if I write lm(y ~ x1, data = p), x1 will be treated as a fixed factor in R , Im wondering if there is way in R to specify that x1 is a random factor
TKBell
Yes, in the **lme4** package. Follow the link in my answer and read up on the documentation of the lme4 package. The `lm()` function is for basic linear modelling and does **not** support random effects.
Dirk Eddelbuettel
A: 

So if I try lme4(y ~ x1, data = p), will x1 be treated as a random factor ?

TKBell
I suspect x1 will be treated as "Error: could not find function "lme4"" since there is no function named lme4.
JD Long