zero values in Poisson GLM / perfect prediction in GLM

Author: jseaboldCreated Feb 14, 2014Updated Sep 28, 2026
Labelscomp-genmodcorner-casetype-possible-bug

Are we guarding against these things?

https://stackoverflow.com/questions/21785049/statsmodels-poisson-glm-different-than-r/21788917#21788917

import numpy as np
import pandas as pd
import statsmodels.formula.api as smf
import statsmodels.api as sm
from scipy.stats.stats import pearsonr

data = pd.read_csv('https://gist.github.com/jseabold/9008683/raw/250ff03e6a3ab3514fe4c0e2a95d4b5fcab9aad1/AT_Austria.csv')

What's going on here? The parameters are wrong, it converges to a big negative number

Model = smf.glm('Data~Origin+Destination+Dij', data=data, offset=np.log(data['Offset']), family=sm.families.Poisson()).fit()

This matches R's GLM (default solver fails, bfgs does something at least), but isn't necessarily converged.

mod = smf.poisson('Data~Origin+Destination+Dij', data=data, offset=np.log(data['Offset'])).fit(method='bfgs')
print mod.mle_retvals['converged']

R gives these warnings

Warning messages:
1: glm.fit: fitted rates numerically 0 occurred 
2: glm.fit: fitted rates numerically 0 occurred