Hi Jean, Is there something missing in the function?
ids <- a$id for(i in 2:4){ for(j in 5:7){ y <- a[, j] x <- a[, i] model<-lme(y ~ x , random= ~1|ids, na.action="na.exclude") }} summary(model) Linear mixed-effects model fit by REML Data: NULL AIC BIC logLik 281.1838 291.5236 -136.5919 Random effects: Formula: ~1 | ids (Intercept) Residual StdDev: 0.1109054 0.9251637 Fixed effects: y ~ x Value Std.Error DF t-value p-value (Intercept) 0.03931479 0.09909825 89 0.3967254 0.6925 x -0.11826047 0.09731719 89 -1.2152063 0.2275 Correlation: (Intr) x 0.056 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -2.0882452 -0.7718563 0.1156507 0.6119178 1.7986478 Number of Observations: 100 Number of Groups: 10 A.K. ----- Original Message ----- From: Jean V Adams <jvad...@usgs.gov> To: Berta Ibáñez <bertu...@hotmail.com> Cc: Lista de R <r-help@r-project.org> Sent: Wednesday, July 18, 2012 1:02 PM Subject: Re: [R] fitting several lme sistematically 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 <bertu...@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]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.