I'm not sure why, but lme() doesn't seem to like the variables to be 
referenced as part of a list using [ or $.
Here's an easy workaround ...

ids <- a$id
for(i in 2:4){
for(j in 5:7){
        y <- a[, j]
        x <- a[, i]
        lme(y ~ x , random= ~1|ids, na.action="na.exclude")
        }}

Jean


Berta Ibáñez <bertuki6@hotmail.com> wrote on 07/18/2012 08:53:51 AM:

> Dear R-list, 
> 
> I have a data set (in the following example called "a") which have: 
> 
> one "subject indicator" variable (called "id")
> three dependent variables (varD, varE, var F)
> three independent variables (varA, varB, varC)
> 
> I want to fit 9 lme models, one per posible combination (DA, DB, DC,
> EA, EB, EC, FA, FB, FC).
> In stead of writting the 9 lme models, I want to do it 
> sistematically (the example is a simplification of what I really 
> have). Here you have the comands for the first model: 
> 
> library(nlme)
> set.seed(50)
> a<-data.frame(array(c(rep(1:10,10), rnorm(600)), c(100,7)))
> names(a)<-c("id", "varA", "varB", "varC", "varD", "varE", "varF")
> lme(varD ~ varA , random= ~1|id,  data=a, na.action="na.exclude")
> 
> I supossed that a simple sintaxis going through the variables of 
> dataset "a" could cope with it: 
> 
> for(i in 2:4){
> for(j in 5:7){
> lme(a[,j] ~ a[,i] , random= ~1|id,  data=a, na.action="na.exclude")
> }}
> 
> but it does not, and the use of eval, as.symbol and so on does not help. 

> 
> for(i in 2:4){
> for(j in 5:7){
> lme(eval(as.symbol(names(a)[j])) ~ eval(as.symbol(names(a)[i]))  , 
> random= ~1|id,  data=a, na.action="na.exclude")
> }}
> 
> Any help??? Thanks a lot in advance!

	[[alternative HTML version deleted]]

