Re: [R] AIC v. extractAIC

From: Ben Bolker <bolker_at_ufl.edu>
Date: Thu, 6 Dec 2007 19:11:25 -0800 (PST)

Ryan Briscoe Runquist wrote:
>
>
> Hello,
>
> I am using a simple linear model and I would like to get an AIC value. I
> came across both AIC() and extractAIC() and I am not sure which is best to
> use. I assumed that I should use AIC for a glm and extractAIC() for lm,
> but if I run my model in glm the AIC value is the same if I use AIC() on
> an
> lm object. What might be going on? Did I interpret these functions
> incorrectly?
>
> Thanks,
> Ryan
>
>

  The documentation for these functions does explain what's going on, albeit fairly tersely. The bottom line is that you should be OK with either one, provided that you stick to one or the other.

set.seed(1001)
x = runif(100)
y = 1 + 2*x+3*x^2+rnorm(100,sd=0.02)

lm1 = lm(y~x)
lm2 = lm(y~x+I(x^2))

## different
AIC(lm1,lm2)
extractAIC(lm1)
extractAIC(lm2)

## the same
AIC(lm1)-AIC(lm2)
extractAIC(lm1)[2]-extractAIC(lm2)[2]

lm3 = glm(y~x)
lm4 = glm(y~x+I(x^2))

## the same
AIC(lm4)
extractAIC(lm4)

-- 
View this message in context: http://www.nabble.com/AIC-v.-extractAIC-tf4959483.html#a14206069
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_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.
Received on Fri 07 Dec 2007 - 03:15:26 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 07 Dec 2007 - 03:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.