I don't know the "best" way, but the following looks like it will
work:
tstDF <- data.frame(x=1:3, y=c(1,1,2))
fit0 <- lm(y~1, tstDF)
fitDF <- lm(y~x, tstDF)
AIC(fitDF,fit0)
df AIC
fitDF 3 5.842516
fit0 2 8.001399
The function AIC with only 1 argument returns only a single
number. However, given nested models, it returns a data.frame with
colums df and AIC. At least in this example (and I would think in all
other contexts as well), "df" is the K you want.
hope this helps.
Spencer Graves
Benjamin M. Osborne wrote:
>How can I extract K (number of parameters) from an AIC calculation, both to
>report K itself and to calculate AICc? I'm aware of the conversion from
AIC ->
>AICc, where AICc = AIC + 2K(K+1)/(n-K-1), but not sure of how K is
calculated
>or how to extract that value from either an AIC or logLik calculation.
>
>This is probably more of a basic statistics question than an R question, but
I
>thank you for your help.
>
>-Ben Osborne
>
>--
>Botany Department
>University of Vermont
>109 Carrigan Drive
>Burlington, VT 05405
>
>benjamin.osborne at uvm.edu
>phone: 802-656-0297
>fax: 802-656-0440
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>
>
--
Spencer Graves, PhD, Senior Development Engineer
O: (408)938-4420; mobile: (408)655-4567