# [R] Error message when calculating BIC

Donald Catanzaro, PhD dgcatanzaro at gmail.com
Wed Sep 24 22:25:08 CEST 2008

```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
 1006.705
> BIC.80
 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

--

-Don

Don Catanzaro, PhD                  Landscape Ecologist
dgcatanzaro at gmail.com               16144 Sigmond Lane
479-751-3616                        Lowell, AR 72745

```