Skip to content

Error message when calculating BIC

3 messages · Ben Bolker, Donald Catanzaro, PhD

#
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

---------------------- CALL TO CREATE MODEL 
------------------------------------------------
summary(nb.80)

Call:
glm.nb(formula = TOTCASES ~ TECI + CENT43 + SQ.CENT43 + CENT.INC +
SQ.CENT.IN + offset(log(ADJ.POP)), data = LymeDisease[Sample.80,
], na.action = na.omit, control = glm.control(maxit = 500),
init.theta = 5.10199509364407, link = log)

Deviance Residuals:
Min 1Q Median 3Q Max
-2.98902 -0.43886 -0.12211 -0.01188 3.01860

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -9.5989380 0.1279558 -75.018 < 2e-16 ***
TECI 0.0289785 0.0033103 8.754 < 2e-16 ***
CENT43 0.0320249 0.0084381 3.795 0.000147 ***
SQ.CENT43 -0.0004099 0.0001836 -2.232 0.025605 *
CENT.INC 0.0370709 0.0067814 5.467 4.59e-08 ***
SQ.CENT.IN -0.0005500 0.0001109 -4.959 7.10e-07 ***
---
Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1

(Dispersion parameter for Negative Binomial(5.102) family taken to be 1)

Null deviance: 798.64 on 410 degrees of freedom
Residual deviance: 289.84 on 405 degrees of freedom
AIC: 1006.7

Number of Fisher Scoring iterations: 1


Theta: 5.10
Std. Err.: 1.15

2 x log-likelihood: -992.705
#
Donald Catanzaro, PhD <dgcatanzaro <at> gmail.com> writes:
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