Here's some code for generating AIC tables.  Note, this is adapted  
from some code allowing for Conditional AICs that work with lmer  
(hence the separate AIC function) but I've removed that  
functionality.  This should work on lm and glm objects.  I haven't  
tested it with glm.nb objects, but I would imagine it should work.

I'm sure it's all a little clunky, but it gets the job done.

-Jarrett

#after Burnham and Anderson 2002
#outputs a matrix of AIC values and AIC weights
#defaults to finite aic (AICc)
aicW<-function(model.list, finite=T){
	aiclist<-vector()
	for(index in 1:length(model.list)){
		aicname<-"finite AIC"
		if(finite==T) {
			aiclist<-c(aiclist, AIC.finite.lm(model.list[[index]]))
			aicname<-"AIC"}
		else {aiclist<-c(aiclist, AIC.lm(model.list[[index]]))}
	}
		
	delta.i<-aiclist-min(aiclist)
	aicw<-exp(delta.i*-0.5)/sum(exp(delta.i*-0.5))
	return.matrix<-matrix(c(aiclist,delta.i, aicw), ncol=3)
	colnames(return.matrix)<-c(aicname,"delta.i", "weight")
	return(return.matrix)
}

#after Burnham and Anderson 2002
#approximate AIC accomodating sample size
#asymptotically approaches AIC as n increases
AIC.finite.lm<-function(model){
	ML = as.numeric(logLik(model))
	p = attributes(logLik(model))$df
	N = length(model$data[,1])
	AICc = AIC(logLik(model)) + (2*p*(p+1))/(N-p-1)
	return(AICc)
	}


AIC.lm<-function(object) {
	ret<-AIC(logLik(object))
	return(ret)
}





----------------------------------------
Jarrett Byrnes
Population Biology Graduate Group, UC Davis
Bodega Marine Lab
707-875-1969
http://www-eve.ucdavis.edu/stachowicz/byrnes.shtml

On May 29, 2008, at 10:47 AM, Ben Bolker wrote:

>
> ICtab() and friends in bbmle (on CRAN) will do this, although these  
> capabilities aren't tremendously well tested.  I'd be interested in  
> feedback.
>
>  Ben Bolker
>
>
> Brianne Addison wrote:
>> Manuel,
>> If you are looking for a package or command in R that will produce  
>> AIC
>> tables for you, I haven't found one.  Once I produce my AIC scores I
>> compute the rest of my table values (usually AICc scores, delta
>> values, weights, and parameter weights from model averaging) by hand
>> in R using formulas in B & A.  Maybe someone else has a better way.
>> If so, I'd love to know it.  Good luck!
>> BriAnne
>>

	[[alternative HTML version deleted]]

