[R] Error message when calculating BIC

Ben Bolker bolker at ufl.edu
Thu Sep 25 15:38:43 CEST 2008


Donald Catanzaro, PhD <dgcatanzaro <at> gmail.com> writes:

> 
> Hi All,
> 
> Could someone help me decode what this error means ?
>  > BIC(nb.80)
> Error in log(attr(object, "nobs")) :
> Non-numeric argument to mathematical function
>  >
> 
> BTW, nb.80 is a negative binomial glm model created using the MASS 
> library with the call at the bottom of the message
> 
> In the hopes of trying to figure this out I tried the following 
> workaround but it did not work either
> since AIC = (Deviance(Mu) + 2C) / N
> where: Mu is deviance of unconstrained model
> C is number of coefficients
> N is sample size
> 
> and BIC = Deviance(Mu) - (df1 *ln(N))
> where: Mu is deviance of unconstrained model
> df1 is the sample size minus the number of coeffcients
> N is the sample size
> 
> thus by substitution BIC = (AIC*N - 2C) - (df1 * ln(N))
> 
> In R the code I tried was:
> AIC.80<-AIC(nb.80)
> first.term <- AIC.80*length(Sample.80)-2*length(nb.80$coefficients)
> second.term <- 
> length(Sample.80)-length(nb.80$coefficients)*log(length(Sample.80))
> BIC.80 <- first.term - second.term
> 
> The results of my code seem completely out of whack, the BIC should be 
> somewhat close to the AIC and thus I am most assuredly not understanding 
> some fundamental principle here:
>  > AIC.80
> [1] 1006.705
>  > BIC.80
> [1] 413368.9
> 
> How does one surmount my original error of "Error in log(attr(object, 
> "nobs")) : Non-numeric argument to mathematical function" ?
> 
> -Don
> 

   A few comments:

1. we need a little bit more information about the packages you
are using (there are BIC functions defined in several different
packages, and it seems as though you may be picking up the wrong
one); what are the results of sessionInfo() ?  [There's a chance
you're getting BIC from my package, bbmle, and that there's a
bug in it, so I'd be interested to find out]

2. Your formulae for AIC and BIC are a bit weird.
It's my understanding that

AIC = deviance+2*C
BIC = deviance+log(N)*C

so BIC = AIC-2*C+log(N)*C

where N=sample size, C=number of parameters

  (Can you give a reference for your formulae?)

 good luck,
   Ben Bolker



More information about the R-help mailing list