Hi, I have been using R for a bit, but never came across this simple
issue... So, I wonder if anyone could give me a hint on it.

I have calculated a bunch o models  and now need to compare them using
AIC(). The issue seem to be that I have placed each output in a list object.
So, the question is how to convert a string into variable names.

Lets say I have all my models in a variables called : models and would like
to compare them using AIC(models[[1]],models[[2]], models[[2]], ...) ? (I
need the list of such output!)

I can get a vector of strings using
paste("models[[",1:length(models),"]]",sep="") but i don't seem to succeed
converting them into variable names...

I  tried: AIC(paste("models[[",1:length(models),"]]",sep=""))
and get the following error:
Error in UseMethod("logLik") : no applicable method for "logLik"


Any hint would be appreciated!


Thanks,

H

## I generate my models using the following function ###

regPares <- function(data=LR){
  nVars <- ncol(data);
  dv <- names(data)[1];
  modelos <- list();
  for (i in 2:(nVars-1)){
    for (j in (i+1):nVars){
      # get variable names
      var1 <- names(data)[i];
      var2 <- names(data)[j];
      # 1) get all pairs and
      ivs <- paste(var1,var2,sep=" + ");
      model.name <- paste("model",i,j,sep=".");
      model <- paste(dv,ivs,sep=" ~ ");
#      print(modName);
      modelos[[model.name]] <- lm(as.formula(model),data=data);
    }
  }
  # return all models in a list()
  return(modelos)
}

        [[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.

Reply via email to