[R] lmer() with no intercept

Meyners, Michael meyners.m at pg.com
Mon Jun 14 09:49:09 CEST 2010

Why would you want to fit the model without intercept if you seemingly need it? 
Anyway, I assume that the intercept from your first model just moves into the random effects -- you have intercepts there for worker and day, so any of these (or both) will absorb it. No surprise that the estimates for the covariates only differ slightly, it should be that way. 
What you plot (your second call to panel.lines) is not the correct model, as you omit the intercept from the work and day (which is 0 or at least pretty close to it if you include the overall intercept in your model). That's why your red line is on the top edge (note that the intercept is negative). 
I'm therefore not sure that the model without intercept makes a lot of sense, but you consider posting related questions rather to the mixed-models SIG, where you might get more erudite comments than from me.
HTH, Michael

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of array chip
Sent: Saturday, June 12, 2010 1:07
To: r-help at r-project.org
Subject: [R] lmer() with no intercept

Hi, I asked this before, but haven't got any response. So would like to have another try. thanks for help. Also tried twice to join the  model mailing list so that I can ask question there, but still haven't got permission to join that list yet.


Hi, I am wondering how I can specify no intercept in a mixed model using lmer(). 

Here is an example dataset attached ("test.txt"). There are 3 workers, in 5 days, measured a response variable "y" on independent variable "x". I want to use a quadratic term (x2 in the dataset) to model the relationship between y and x.


If I just simply use lm() and ignore worker and day, so that I can try both a linear regression with and without an intercept, here is what I get:

lm(y~x+x2, data=test)
(Intercept)            x           x2  
-1.7749104    0.1099160   -0.0006152

lm(y~x+x2-1, data=test)
         x          x2  
0.0490097  -0.0001962

Now, I want to try mixed model considering worker and day as random effect. 

With an intercept:

lmer(y~x+x2+(1|worker)+(1|day), data=test)
Fixed effects:
              Estimate Std. Error t value
(Intercept) -1.324e+00  4.490e-01  -2.948
x            1.117e-01  8.563e-03  13.041
x2          -6.357e-04  7.822e-05  -8.127

Without an intercept:

lmer(y~x+x2+(1|worker)+(1|day)-1, data=test)
Fixed effects:
     Estimate Std. Error t value
x   1.107e-01  8.528e-03  12.981
x2 -6.304e-04  7.805e-05  -8.077

It seems working fine. But if you look at the fixed effect coefficients of both mixed models, the coefficients for x and x2 are not much different, regardless of whether an intercept is included or not. This is not the case for simple linear regression using lm() on the top.

If I plot all 4 models in the following plot:

xyplot(y~x,groups=worker,test, col.line = "grey", lwd = 2,
, panel = function(x,y) { 
    panel.xyplot(x,y, type='p')


As you can see, the mixed model without intercept (red line) does not fit the data very well (it's at the top edge of the data, instead of in the middle of the data), so I guess I did something wrong here.

Can anyone make any suggestions?




More information about the R-help mailing list