I am trying to run different lme models for different section of my data.
 Consider the simple example where the data is partition into two "groups":


ytest<-rnorm(50)
xtest<-cbind(rep(1,50),ytest*2,rnorm(50),rnorm(50),rnorm(50))
IDtest<-rep(c(1:5),10)
grouptest<-c(rep(1,20),rep(2,30))

head(cbind(ytest,xtest,IDtest,grouptest))


The following function "under2" attempts to create lm as well as lme models.
 no problems are encountered with lm (when lme is commented out).

under2<-function(x,y,ID,group)
{
mod<-list()
lmemod<-list()
for(k in 1:K)
{
yy<-y[group==k]
xx<-matrix(c(x[group==k]),length(yy))
IDID<-ID[group==k]
thedatak<-data.frame(cbind(yy,xx,IDID))
print(head(thedatak))
mod[[k]]<-lm(yy~xx-1)
lmemod[[k]]<-lme(yy~xx-1, random=~1|IDID, method="ML", data=thedatak)
}

return(list(mod=mod,lmemod=lmemod))
}

PROBLEMS occur with lme:

under2(xtest,ytest,IDtest,grouptest)

returns:
Error in model.frame.default(formula = ~yy + xx + IDID, data = list(yy =
c(1.74992615120210,  :
  variable lengths differ (found for 'xx')


Why does lme have a problem?

I can't figure this out...

Any help would be greatly appreciated,

Harlan

	[[alternative HTML version deleted]]


