That's a great guide!!! Thanks....

I guess, I wasn't 2 clear about my question.

I have succeed naming my vars, but I can't seem to be able to create a c()
of objects named after the string.

So far I have MyList$lm1 MyList$lm2, ... but can't use them as an input to
AIC()

that is, AIC(Mylist) won't work neither will
AIC(paste("MyList$lm",1:length(MyList),sep=""))


As Patrick mentioned it on the botton of page 52 of the R inferno it
suggests something of the sort: for(i in 1:n) assign(paste('obj', i,
sep='.'), mylist[[i]]), but I can;t see how this could be used to generate a
list of lms...

I'ld think  this to be pretty simple.. but arggg....

So any hint will be appreciated


thanks,

H

On Mon, Aug 3, 2009 at 12:33 PM, Patrick Burns <pburns@pburns.seanet.com>wrote:

> I'm convinced the answer is in
> 'The R Inferno' but I'm not very
> clear on your question, so I don't
> know where.  Perhaps you want
> 'do.call', or perhaps you should
> look at page 52.
>
>
>
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of "The R Inferno" and "A Guide for the Unwilling S User")
>
> Horacio Samaniego wrote:
>
>> 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.
>>
>>


-- 
Horacio Samaniego, PhD
Instituto de Silvicultura
Facultad de Ciencias Forestales
Universidad Austral de Chile
Valdivia, Chile

+56 (63) 222480 [of.]
http://www.ecoinformatica.cl

	[[alternative HTML version deleted]]


