Leandra Desousa
2007-Aug-15 21:05 UTC
[R] AIC and logLik for logistic regression in R and S-PLUS
Dear R users,
I am using 'R' version 2.2.1 and 'S-PLUS' version 6.0; and I
loaded the
MASS library in 'S-PLUS'.
I am running a logistic regression using glm:
---------------------------------------------------------------------------
> mydata.glm<-glm(COMU~MeanPycUpT+MeanPycUpS, family=binomial,
data=mydata)
---------------------------------------------------------------------------
The values in summary(mydata.glm) are identical for 'R' and
'S-PLUS'
(except that S-PLUS does not return an AIC value).
Here is the summary(mydata.glm):
-------------------------------------------------------------------
>summary(mydata.glm)
Call:
glm(formula = COMU ~ MeanPycUpT + MeanPycUpS, family = binomial,data =
mydata)
Deviance Residuals:
Min 1Q Median 3Q Max
-2.3514 -0.8268 -0.4831 0.8866 1.9864
Coefficients:
Estimate std.Error z value Pr(>|z|)
(Intercept) 75.482 41.616 1.814 0.0697 .
MeanPycUpT 1.143 2.867 0.399 0.6902
MeanPycUpS -2.548 1.225 -2.081 0.0374 *
---
Signif.codes: 0 '***' 0.001 '**' 0.01 '*' 0.05
'.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 30.316 on 21 degrees of freedom
Residual deviance: 23.900 on 19 degrees of freedom
AIC: 29.9
--------------------------------------------------------------------
When I use the 'AIC' and the 'logLik' command in 'R' and
'S-PLUS' I get
different values:
'R'
-----------------
> AIC(mydata.glm)
[1] 29.89986
> logLik(mydata.glm)
'log Lik.' -11.94993 (df=3)
-----------------
'S-PLUS'
-----------------
> AIC(mydata.glm)
[1] 71.03222
> logLik(mydata.glm)
[1] -31.51611
-----------------
However, if I use the 'extractAIC' command in 'S-PLUS' the
returned
value is the same as the one in 'R'.
'R'
------------------------
> AIC(mydata.glm)
[1] 29.89986
> extractAIC(mydata.glm)
[1] 3.00000 29.89986
-------------------------
'S-PLUS'
------------------------
> extractAIC(mydata.glm)
[1] 3.00000 29.89986
------------------------
*****************************************************
MY QUESTIONS ARE:
1) Which AIC value is the correct one?
2) Which log-likelihood value is the correct one?
3) If 'extractAIC' in 'S-PLUS' and all values in 'R'
are the correct
ones, and the 'AIC' and 'logLik' in 'S-PLUS' values are
wrong then:
Why 'S-PLUS' cannot retrieve a log-likelihood value from my glm
object('mydata.glm'), even though it is using log-likelihood to
calculate its residual deviance?
*******************************************************
Thank you for you time and Kind attention.
Sincerely,
Leandra de Sousa
--------------------------------------
Ph.D Candidate
School of Fisheries and Ocean Sciences
Universisty of Alaska Fairbanks
245 O'Neill Bldg.
Fairbanks, AK
99775
e.mail: sousa at ims.uaf.edu
Ben Bolker
2007-Aug-16 17:04 UTC
[R] AIC and logLik for logistic regression in R and S-PLUS
Leandra Desousa <sousa <at> ims.uaf.edu> writes:> I am using 'R' version 2.2.1 and 'S-PLUS' version 6.0; and I loaded the > MASS library in 'S-PLUS'. > > I am running a logistic regression using glm: > > >summary(mydata.glm) > Call: > glm(formula = COMU ~ MeanPycUpT + MeanPycUpS, family = binomial,data = > mydata)[snip]> Null deviance: 30.316 on 21 degrees of freedom > Residual deviance: 23.900 on 19 degrees of freedom > AIC: 29.9 > -------------------------------------------------------------------- > 'R' > ----------------- > > AIC(mydata.glm) > [1] 29.89986 > > > logLik(mydata.glm) > 'log Lik.' -11.94993 (df=3) > ----------------- > > 'S-PLUS' > ----------------- > > AIC(mydata.glm) > [1] 71.03222 > > > logLik(mydata.glm) > [1] -31.51611 > ----------------- > > > 1) Which AIC value is the correct one? > 2) Which log-likelihood value is the correct one?AIC and log-likelihood are often defined differently in software packages -- specifically, additive constants can be included or excluded as long as they are done consistently, without affecting inferences from the model. The absolute values of AIC and logLik aren't that important; the only thing that really matters are differences among models. Have you tried comparing models within R and within S-PLUS to establish whether they give the same inferences (I would guess they do)?> 3) If 'extractAIC' in 'S-PLUS' and all values in 'R' are the correct > ones, and the 'AIC' and 'logLik' in 'S-PLUS' values are wrong then: > Why 'S-PLUS' cannot retrieve a log-likelihood value from my glm > object('mydata.glm'), even though it is using log-likelihood to > calculate its residual deviance?It's very hard for us to debug S-PLUS! Some (most?) of us on the list don't even have S-PLUS installed any more ... Perhaps you should ask this question on an S-PLUS mailing list, or of the (paid) S-PLUS technical support team ... And the obligatory R-list nags: * it would help if you upgraded your R version -- R 2.3.0 came out in April 2006, and we're now up to 2.5.1 * it's the MASS "package", not the MASS "library" cheers Ben Bolker
Apparently Analagous Threads
- (Ben Bolker) AIC and logLik for logistic regression in R and S-PLUS
- logLik for poisson models
- stepAIC() that can use new extractAIC() function implementing AICc
- MASS:::dropterm.glm() and MASS:::addterm.glm() should use ... for extractAIC()
- extractAIC using surf.ls