Dear Mark,
Try this:

models<-paste("model",1:3,sep="")
t(sapply(models,function(x){
           m<-get(x)
          c(aic=AIC(m),LL=logLik(m))
          }
         )
       )

See ?get, ?AIC, ?logLik and ?sapply for more information.

HTH,

Jorge


On Wed, Feb 25, 2009 at 6:58 PM, Mark Drever <mdrever@interchange.ubc.ca>wrote:

> hi folks,
>
> I'm trying to build a table that contains information about a series of
> General Linear Models in order to calculate Akaike weights and other
> measures to compare all models in the series.
>
> i have an issue with indexing models and extracting the information
> (loglikehood, AIC's, etc.) that I need to compile them into the table. Below
> is some sample code that illustrates my approach so far and my problem. I
> realize that somehow i need to provide actual object for the AIC or LogLik
> call, and I've tried a couple of different ideas (e.g., as.name,
> expression), but have come up empty.
>
> Thanks so much. Any help much appreciated.
> Mark.
>
> Sample code begins here....
>
> x1 <- rnorm(10,1,1)
> x2 <- rnorm(10,2,2)
> x3 <- rnorm(10,3,3)
> y <- x1*2 + x2*3 + x3*4 + rnorm(10,0,0.4)
>
> model1 <- lm(y ~ x1)
> model2 <- lm(y ~ x2)
> model3 <- lm(y ~ x3)
>
> aic.table <- data.frame(model.number = 1:3,  Log.lik = NA)
>
> for (i in 1:3)
> {
> aic.table$Log.lik[i] <- Loglik(paste("model",i,sep=""))[1]
> }
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]


