[R] lmer() with no intercept
array chip
arrayprofile at yahoo.com
Sat Jun 12 01:06:54 CEST 2010
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.
test<-read.table("test.txt",sep='\t',header=T)
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)
Coefficients:
(Intercept) x x2
-1.7749104 0.1099160 -0.0006152
lm(y~x+x2-1, data=test)
Coefficients:
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')
x<-sort(x)
panel.lines(x,-1.324+0.1117*x-0.0006357*x*x)
panel.lines(x,0.1107*x-0.0006304*x*x,col='red')
panel.lines(x,0.04901*x-0.0001962*x*x,col='blue')
panel.lines(x,-1.7749+0.10992*x-0.0006152*x*x,col='green')
})
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?
Thanks
John
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100611/719104cf/attachment.txt>
More information about the R-help
mailing list