[R] indexing model names for AICc table

Mark Drever mdrever at interchange.ubc.ca
Thu Feb 26 00:58:36 CET 2009


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]
}




More information about the R-help mailing list