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]]
______________________________________________
[email protected] 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.