validate_gravity
#import sys
#sys.path.append('/Users/toshan/dev/pysal/pysal/contrib/glm')
#from utils import
import numpy as np
import pandas as pd
import sys
sys.path.append('/Users/toshan/dev/pysal/pysal/contrib/spint')
from gravity import Gravity, Production, Attraction, Doubly, BaseGravity
import gravity
from utils import sorensen
import statsmodels.formula.api as smf
from statsmodels.api import families as families
austria = pd.read_csv('http://dl.dropbox.com/u/8649795/AT_Austria.csv')
austria = austria[austria['Origin'] != austria['Destination']]
f = austria['Data'].values
o = austria['Origin'].values
d = austria['Destination'].values
dij = austria['Dij'].values
o_vars = austria['Oi2007'].values
d_vars = austria['Dj2007'].values
grav = Gravity(f, o_vars, d_vars, dij, 'exp', framework='glm', constant=True)
print grav.params
gravity = smf.glm('Data~np.log(Oi2007)+np.log(Dj2007)+Dij', family=families.Poisson(), data=austria).fit()
print gravity.params.values
production = Production(f, o, d_vars, dij, 'exp', framework='glm')
print production.params
gravity = smf.glm('Data~Origin+np.log(Dj2007)+Dij', family=families.Poisson(), data=austria).fit()
print gravity.params.values
attraction = Attraction(f, d, o_vars, dij, 'exp', framework='glm', constant=True)
print attraction.params
gravity = smf.glm('Data~np.log(Oi2007)+Destination + Dij', family=families.Poisson(), data=austria).fit()
print gravity.params.values
doubly = Doubly(f, o, d, dij, 'exp', framework='glm', constant=True)
print doubly.params
gravity = smf.glm('Data~Origin+Destination+Dij', family=families.Poisson(), data=austria).fit()
print gravity.params.values