Skip to content

Instantly share code, notes, and snippets.

@TaylorOshan
Created July 2, 2016 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaylorOshan/79aa3f71c573d8d7cac33463bb7efa9b to your computer and use it in GitHub Desktop.
Save TaylorOshan/79aa3f71c573d8d7cac33463bb7efa9b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import os\n",
"os.chdir('../')\n",
"from gravity import Gravity, Production, Attraction, Doubly, BaseGravity\n",
"import statsmodels.formula.api as smf\n",
"from statsmodels.api import families\n",
"import matplotlib.pyplot as plt\n",
"%pylab inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"austria = pd.read_csv('http://dl.dropbox.com/u/8649795/AT_Austria.csv')\n",
"austria = austria[austria['Origin'] != austria['Destination']]\n",
"f = austria['Data'].values\n",
"o = austria['Origin'].values\n",
"d = austria['Destination'].values\n",
"dij = austria['Dij'].values\n",
"o_vars = austria['Oi2007'].values\n",
"d_vars = austria['Dj2007'].values"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.00976746026969\n"
]
}
],
"source": [
"model = Gravity(f, o_vars, d_vars, dij, 'exp')\n",
"print model.params[-1]"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[-0.01699776161094757,\n",
" -0.0053210259160796358,\n",
" -0.0028594272276957211,\n",
" -0.006533037784217155,\n",
" -0.0024666647861060209,\n",
" -0.0058258251130860472,\n",
" -0.010739622617965516,\n",
" -0.0046867791898773659,\n",
" -0.0065940756391066335]"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"local = model.local(loc_index=o, locs=np.unique(o))\n",
"local['param2']"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.00727113391179\n"
]
}
],
"source": [
"model = Production(f, o, d_vars, dij, 'exp')\n",
"print model.params[-1]"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[-0.016997761610949791,\n",
" -0.005321025916080413,\n",
" -0.0028594272276953325,\n",
" -0.0065330377842177101,\n",
" -0.0024666647861060209,\n",
" -0.0058258251130863803,\n",
" -0.010739622617965183,\n",
" -0.0046867791898770328,\n",
" -0.0065940756391070776]"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"local = model.local()\n",
"local['param2']"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"-0.00693754909526\n"
]
}
],
"source": [
"model = Attraction(f, d, o_vars, dij, 'exp')\n",
"print model.params[-1]"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[-0.010872636479707154,\n",
" -0.0054690202130680543,\n",
" -0.0025567421332022833,\n",
" -0.0051439340488994012,\n",
" -0.0036020461535491433,\n",
" -0.010088935906795271,\n",
" -0.012926843651020203,\n",
" -0.0075750287063747201,\n",
" -0.0081576735088411123]"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"local = model.local()\n",
"local['param2']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment