I am trying to calculate the AIC for log-linear model in R, but i get Inf as a result. The model aim is to predict sales in euros based on some variables.

As far as I understand by specifying poisson(link = log) in glm it changes calcultting method from LSM to maximizing likelihood and assumes different distribution (Poisson insted of normal). But why can't it calculate AIC?

In example below in model 2, where I make log-linear model manually i get AIC (i guess the assumed distribution is normal), but in model 3 AIC is calculated as Inf. What is the difference between approaches and which one is correct?

Sample code:

    d <- data.frame(x = runif(100, 1, 10))
    d$y = d$x + runif(100, 1, 10)

#linear model
    M1 <- glm(y ~ ., data = d)
#log-linear model
    M2 <- glm(log(y) ~ ., data = d)
#log-linear model
    M3 <- glm(y ~ ., data = d,  poisson(link = log))
  • 1
    $\begingroup$ The models M2 and M3 are not the same model with an only different implementation. TheInf may come from the wrong family according to the type of variable you used. The variable x it seems to be continuous, while the Poisson distribution is a discrete distribution, thus it take only a set of natural numbers. Please read about link-function in Generalized Linear Models. I am unable to clearly explain you a mathematic behind this idea, you should do it by yourself: link.springer.com/chapter/10.1007/978-0-387-87458-6_9 $\endgroup$
    – Jakub
    Aug 12, 2020 at 10:12

1 Answer 1


The AIC is defined as $$2k - 2\ln L(\theta)$$ where $k$ is the number of parameters and L is the likelihood of your model. The Poisson distribution assumes that you observe a non-negative whole number, so it doesn't really make sense to use a Poisson glm when y clearly is not an integer. If you try to evaluate the Poisson density in R, it will return 0 if you give in a decimal number, for example

dpois(12.5, lambda = 12)
[1] 0
Warning message:
In dpois(12.5, 12) : non-integer x = 12.500000

So if the likelihood is evaluated to 0 then the log-likelihood will evaluate to negative infinity and the AIC will be infinity.

If you on the other hand round the y variable to the closest whole number, the AIC value makes more sense:

d$y = round(d$y)
M3 <- glm(y ~ ., data = d,  poisson(link = log))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.