[R] help about how can R compute AIC?

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Oct 14 18:57:33 CEST 2008


On Tue, 14 Oct 2008, Arnau Mir Torres wrote:

>
> El 14/10/2008, a las 18:05, Martin Maechler escribió:
>
>>>>>>> "AMT" == Arnau Mir Torres <arnau.mir at uib.es>
>>>>>>>   on Tue, 14 Oct 2008 17:13:01 +0200 writes:
>>>>>>> "AMT" == Arnau Mir Torres <arnau.mir at uib.es>
>>>>>>>   on Tue, 14 Oct 2008 17:13:01 +0200 writes:
>>
>>   AMT> Hello.
>>
>>   AMT> I need to know how can R compute AIC when I study a regression 
>> model?

Out of curiosity, why do you 'need' to know?

>>   AMT> For example, if I use these data:
>>   AMT> growth tannin
>>   AMT> 1     12      0
>>   AMT> 2     10      1
>>   AMT> 3      8      2
>>   AMT> 4     11      3
>>   AMT> 5      6      4
>>   AMT> 6      7      5
>>   AMT> 7      2      6
>>   AMT> 8      3      7
>>   AMT> 9      3      8
>>   AMT> and I do
>>   AMT> model <- lm (growth ~ tannin)
>>   AMT> AIC(model)
>>
>>   AMT> R responses:
>>   AMT> 38.75990
>>
>>   AMT> I know the following formula to compute AIC:
>>   AMT> AIC= -2*log-likelihood + 2*(p+1)
>>
>>   AMT> In my example, it would be:
>>   AMT> AIC=-2*log-likelihood + 2*2
>>   AMT> but I don't know how R computes log-likelihood:
>>
>>   AMT> logLik(model)
>>   AMT> 'log Lik.' -16.37995 (df=3)
>> 
>> and so?
>
> What is the formula to compute logLik? I don't know how to compute "by hand" 
> logLik(model) and obtain -16.37995.

Do you not have a regression textbook to look this up in? The R posting 
guide makes quite clear this is not a list on basic statistics.

Hint: look at stats:::logLik.lm to see the formula expressed in R.

>
>
> Arnau.
>> 
>> 
>> Hint:     Your only problem is that your 'p' is wrongly off by one.
>> 2nd Hint: sigma is a parameter, too

I suspect it is the intercept that was forgotten in p, and sigma is the 
'1' in 'p+1'.

>
> ------------------------------------------------------------
> Arnau Mir Torres
> Edifici A. Turmeda
> Campus UIB
> Ctra. Valldemossa, km. 7,5
> 07122 Palma de Mca.
> tel: (+34) 971172987
> fax: (+34) 971173003
> email: arnau.mir at uib.es
> URL: http://dmi.uib.es/~arnau
> ------------------------------------------------------------

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list