Пример #1
0
 def test_local_Production(self):
     model = grav.Production(self.f, self.o, self.d_var, self.dij, 'exp')
     local = model.local(locs=np.unique(self.o))
     self.assertEqual(local.keys().sort(), [
         'pvalue2', 'SRMSE', 'pvalue0', 'deviance', 'adj_pseudoR2',
         'pvalue1', 'tvalue0', 'tvalue2', 'adj_D2', 'tvalue1', 'SSI', 'AIC',
         'param1', 'param0', 'D2', 'pseudoR2', 'param2'
     ].sort())
Пример #2
0
 def test_Attraction(self):
     model = grav.Production(self.f,
                             self.d,
                             self.o_var,
                             self.dij,
                             'exp',
                             constant=True)
     np.testing.assert_allclose(model.params, [
         -0.88439723, 1.62180605, 1.92772078, 0.12462001, 0.62378812,
         0.69646073, 0.20909411, 0.6856777, 0.48539625, 0.89235874,
         -0.00693755
     ],
                                atol=.001)
     self.assertAlmostEqual(model.AIC, 16275.899321893821, delta=.0001)
     np.testing.assert_allclose(model.cov_params, [
         [
             3.01436996e-03, -2.61742292e-04, -3.18191276e-04,
             -2.61736294e-04, -2.53401872e-04, -2.53545012e-04,
             -2.81169571e-04, -2.43409544e-04, -2.12802803e-04,
             -2.71488782e-04, -1.17108280e-06
         ],
         [
             -2.61742292e-04, 2.36371652e-04, 1.97978106e-04,
             1.92565769e-04, 1.94367290e-04, 1.93561823e-04, 1.93929484e-04,
             1.87837851e-04, 1.84018218e-04, 5.78923328e-06, 8.62912701e-08
         ],
         [
             -3.18191276e-04, 1.97978106e-04, 2.37130911e-04,
             1.95813824e-04, 1.96321084e-04, 1.95974290e-04, 1.97059881e-04,
             1.93136341e-04, 1.90444087e-04, 1.16187824e-05, 7.68842070e-08
         ],
         [
             -2.61736294e-04, 1.92565769e-04, 1.95813824e-04,
             4.45977428e-04, 1.98639315e-04, 2.00358776e-04, 2.01640218e-04,
             2.11745720e-04, 2.17565021e-04, 7.97756072e-06, -9.56753770e-08
         ],
         [
             -2.53401872e-04, 1.94367290e-04, 1.96321084e-04,
             1.98639315e-04, 3.12561535e-04, 1.97440629e-04, 1.98271627e-04,
             2.01952018e-04, 2.03971780e-04, 6.29181262e-06, -2.57004528e-08
         ],
         [
             -2.53545012e-04, 1.93561823e-04, 1.95974290e-04,
             2.00358776e-04, 1.97440629e-04, 3.20607776e-04, 1.99534150e-04,
             2.05855338e-04, 2.09446226e-04, 6.66273501e-06, -5.53303117e-08
         ],
         [
             -2.81169571e-04, 1.93929484e-04, 1.97059881e-04,
             2.01640218e-04, 1.98271627e-04, 1.99534150e-04, 4.04837719e-04,
             2.07747990e-04, 2.11608257e-04, 9.45143925e-06, -5.46040064e-08
         ],
         [
             -2.43409544e-04, 1.87837851e-04, 1.93136341e-04,
             2.11745720e-04, 2.01952018e-04, 2.05855338e-04, 2.07747990e-04,
             4.85148555e-04, 2.46472592e-04, 8.10725781e-06, -2.60737252e-07
         ],
         [
             -2.12802803e-04, 1.84018218e-04, 1.90444087e-04,
             2.17565021e-04, 2.03971780e-04, 2.09446226e-04, 2.11608257e-04,
             2.46472592e-04, 7.90692415e-04, 6.52409863e-06, -3.86785704e-07
         ],
         [
             -2.71488782e-04, 5.78923328e-06, 1.16187824e-05,
             7.97756072e-06, 6.29181262e-06, 6.66273501e-06, 9.45143925e-06,
             8.10725781e-06, 6.52409863e-06, 2.64461183e-05, 8.70031728e-08
         ],
         [
             -1.17108280e-06, 8.62912701e-08, 7.68842070e-08,
             -9.56753770e-08, -2.57004528e-08, -5.53303117e-08,
             -5.46040064e-08, -2.60737252e-07, -3.86785704e-07,
             8.70031728e-08, 2.62593686e-09
         ]
     ])
     self.assertAlmostEqual(model.deviance, 15673.222613627502, delta=.0001)
     self.assertAlmostEqual(model.llf, -8126.9496609469106, delta=.0001)
     self.assertAlmostEqual(model.llnull, -88037.0499629, delta=.0001)
     np.testing.assert_allclose(model.pvalues, [
         2.23154436e-058, 0.00000000e+000, 0.00000000e+000, 3.61133996e-009,
         1.05877746e-272, 0.00000000e+000, 2.69492058e-025, 9.38664385e-213,
         9.08121216e-067, 0.00000000e+000, 0.00000000e+000
     ])
     np.testing.assert_allclose(model.std_err, [
         5.49032782e-02, 1.53743830e-02, 1.53990555e-02, 2.11181777e-02,
         1.76794099e-02, 1.79055236e-02, 2.01205795e-02, 2.20260880e-02,
         2.81192535e-02, 5.14257895e-03, 5.12438958e-05
     ])
     np.testing.assert_allclose(model.tvalues, [
         -16.10827734, 105.487554, 125.18435157, 5.90107805, 35.28331128,
         38.89641795, 10.39205191, 31.13025333, 17.2620603, 173.52358548,
         -135.38293645
     ])
     np.testing.assert_allclose(model.yhat, [
         1.79502279e+03, 2.77690999e+03, 1.77376340e+02, 5.41058308e+02,
         3.28265191e+02, 1.61020145e+02, 9.55492240e+01, 3.54052486e+01,
         1.48342439e+03, 1.51642463e+04, 7.61962380e+02, 2.29718733e+03,
         2.29156465e+03, 9.24935115e+02, 5.55191561e+02, 2.11833031e+02,
         2.31106289e+03, 1.52712766e+04, 8.29095427e+02, 2.57322937e+03,
         2.28197035e+03, 9.39377653e+02, 5.59026730e+02, 2.12153271e+02,
         1.78795020e+02, 9.29389609e+02, 1.00418629e+03, 8.13086106e+02,
         5.79191340e+02, 5.35268359e+02, 4.24969889e+02, 1.60758895e+02,
         5.47719688e+02, 2.81394269e+03, 3.12998907e+03, 8.16565623e+02,
         1.15732912e+03, 7.21460431e+02, 4.41575377e+02, 1.63374443e+02,
         3.87326254e+02, 3.27181524e+03, 3.23528198e+03, 6.77976176e+02,
         1.34894643e+03, 1.19916138e+03, 8.01876754e+02, 3.13863001e+02,
         1.75685709e+02, 1.22115852e+03, 1.23153422e+03, 5.79386090e+02,
         7.77596785e+02, 1.10887286e+03, 7.06986190e+02, 2.63279368e+02,
         4.96907636e+01, 3.49378290e+02, 3.49326167e+02, 2.19253703e+02,
         2.26850151e+02, 3.53430501e+02, 3.36979293e+02, 5.49332748e+02,
         1.22952888e+01, 8.90162551e+01, 8.85260032e+01, 5.53842615e+01,
         5.60455225e+01, 9.23759900e+01, 8.37976212e+01, 3.66824277e+02
     ])
     self.assertAlmostEquals(model.D2, .910690541438)
     self.assertAlmostEquals(model.adj_D2, .896049646592)
     self.assertAlmostEquals(model.SSI, .750634498293)
     self.assertAlmostEquals(model.pseudoR2, .90768716507)
     self.assertAlmostEquals(model.adj_pseudoR2, .907562217676)
     self.assertAlmostEquals(model.SRMSE, 0.59483126233090433)
Пример #3
0
 def test_Production(self):
     model = grav.Production(self.f,
                             self.o,
                             self.d_var,
                             self.dij,
                             'exp',
                             constant=True)
     np.testing.assert_allclose(model.params, [
         -1.11700938, 1.68662317, 2.15188689, 0.60300297, 0.88380784,
         1.20926104, 0.68938983, 1.15472804, 1.02479968, 0.89278717,
         -0.00727113
     ],
                                atol=.0001)
     self.assertAlmostEqual(model.AIC, 15882.651018068489, delta=.0001)
     np.testing.assert_allclose(model.cov_params, [
         [
             2.58467540e-03, -3.29423877e-04, -3.27686611e-04,
             -3.08689103e-04, -2.97140418e-04, -2.89494010e-04,
             -3.24014540e-04, -3.00776842e-04, -2.84393168e-04,
             -2.24000219e-04, -9.64855587e-07
         ],
         [
             -3.29423877e-04, 3.03025458e-04, 2.53009591e-04,
             2.47263232e-04, 2.49058621e-04, 2.47981815e-04, 2.48504221e-04,
             2.42350062e-04, 2.38815483e-04, 7.03380199e-06, 9.21233182e-08
         ],
         [
             -3.27686611e-04, 2.53009591e-04, 2.87125687e-04,
             2.47623385e-04, 2.49193103e-04, 2.48208882e-04, 2.48776786e-04,
             2.43211814e-04, 2.40006717e-04, 6.93978830e-06, 8.51141937e-08
         ],
         [
             -3.08689103e-04, 2.47263232e-04, 2.47623385e-04,
             4.64543893e-04, 2.54358195e-04, 2.56271647e-04, 2.58881194e-04,
             2.72166616e-04, 2.79448200e-04, 7.48669925e-06, -1.28025978e-07
         ],
         [
             -2.97140418e-04, 2.49058621e-04, 2.49193103e-04,
             2.54358195e-04, 3.69553926e-04, 2.52457119e-04, 2.53895776e-04,
             2.59259137e-04, 2.62162787e-04, 5.35894223e-06, -4.43827259e-08
         ],
         [
             -2.89494010e-04, 2.47981815e-04, 2.48208882e-04,
             2.56271647e-04, 2.52457119e-04, 3.47667496e-04, 2.55361893e-04,
             2.63782581e-04, 2.68393880e-04, 5.00405857e-06, -8.03379392e-08
         ],
         [
             -3.24014540e-04, 2.48504221e-04, 2.48776786e-04,
             2.58881194e-04, 2.53895776e-04, 2.55361893e-04, 4.30583201e-04,
             2.68391703e-04, 2.74115589e-04, 8.62466197e-06, -9.29399372e-08
         ],
         [
             -3.00776842e-04, 2.42350062e-04, 2.43211814e-04,
             2.72166616e-04, 2.59259137e-04, 2.63782581e-04, 2.68391703e-04,
             5.29121755e-04, 3.15535312e-04, 8.88670616e-06, -3.18385859e-07
         ],
         [
             -2.84393168e-04, 2.38815483e-04, 2.40006717e-04,
             2.79448200e-04, 2.62162787e-04, 2.68393880e-04, 2.74115589e-04,
             3.15535312e-04, 7.96308690e-04, 8.69726183e-06, -4.44906514e-07
         ],
         [
             -2.24000219e-04, 7.03380199e-06, 6.93978830e-06,
             7.48669925e-06, 5.35894223e-06, 5.00405857e-06, 8.62466197e-06,
             8.88670616e-06, 8.69726183e-06, 2.17985878e-05, 6.51339971e-08
         ],
         [
             -9.64855587e-07, 9.21233182e-08, 8.51141937e-08,
             -1.28025978e-07, -4.43827259e-08, -8.03379392e-08,
             -9.29399372e-08, -3.18385859e-07, -4.44906514e-07,
             6.51339971e-08, 2.77308674e-09
         ]
     ])
     self.assertAlmostEqual(model.deviance, 15279.974241770311, delta=.0001)
     self.assertAlmostEqual(model.llf, -7930.3255090342445, delta=.0001)
     self.assertAlmostEqual(model.llnull, -88037.0499629, delta=.0001)
     np.testing.assert_allclose(model.pvalues, [
         5.43122293e-107, 0.00000000e+000, 0.00000000e+000, 3.06800447e-172,
         0.00000000e+000, 0.00000000e+000, 5.04395549e-242, 0.00000000e+000,
         9.03955976e-289, 0.00000000e+000, 0.00000000e+000
     ])
     np.testing.assert_allclose(model.std_err, [
         5.08397030e-02, 1.74076264e-02, 1.69447835e-02, 2.15532803e-02,
         1.92237854e-02, 1.86458439e-02, 2.07504988e-02, 2.30026467e-02,
         2.82189420e-02, 4.66889578e-03, 5.26601057e-05
     ])
     np.testing.assert_allclose(model.tvalues, [
         -21.97120187, 96.88989939, 126.99406254, 27.97731759, 45.97470357,
         64.85418671, 33.22280753, 50.19979035, 36.31602055, 191.22019711,
         -138.07670549
     ])
     np.testing.assert_allclose(model.yhat, [
         1.40705950e+03, 1.69457663e+03, 1.16508879e+02, 4.27850723e+02,
         2.23425179e+02, 1.08301078e+02, 3.08300817e+01, 7.44793331e+00,
         1.81162644e+03, 1.21014912e+04, 6.46999802e+02, 2.34696906e+03,
         2.06388796e+03, 8.15528209e+02, 2.34966095e+02, 5.85312512e+01,
         3.30741049e+03, 1.83446566e+04, 8.10873546e+02, 3.03231168e+03,
         2.35717102e+03, 9.50837295e+02, 2.71489717e+02, 6.72496632e+01,
         2.60277189e+02, 1.12260001e+03, 9.28118288e+02, 1.04284804e+03,
         6.44343295e+02, 6.06652130e+02, 2.34315477e+02, 5.78455649e+01,
         6.57379261e+02, 2.80075361e+03, 2.38710037e+03, 7.17245241e+02,
         1.03993511e+03, 6.48056270e+02, 1.90566474e+02, 4.59636590e+01,
         4.99603238e+02, 3.58445439e+03, 2.70058180e+03, 6.44960859e+02,
         1.51347637e+03, 1.20618713e+03, 3.89165529e+02, 9.95706858e+01,
         2.34675109e+02, 1.37251483e+03, 1.05563448e+03, 5.88432822e+02,
         9.13951678e+02, 1.16884200e+03, 3.66858927e+02, 8.90901579e+01,
         1.31244011e+02, 7.76879800e+02, 5.92149430e+02, 4.46507449e+02,
         5.27992298e+02, 7.40876898e+02, 7.20725128e+02, 4.04624989e+02,
         5.02255240e+01, 3.06563409e+02, 2.32354948e+02, 1.74615053e+02,
         2.01734215e+02, 3.00280455e+02, 2.77258060e+02, 6.40968342e+02
     ])
     self.assertAlmostEquals(model.D2, 0.912931356874)
     self.assertAlmostEquals(model.adj_D2, 0.89865780882)
     self.assertAlmostEquals(model.SSI, 0.740619203383)
     self.assertAlmostEquals(model.pseudoR2, 0.909920590111)
     self.assertAlmostEquals(model.adj_pseudoR2, 0.909795642717)
     self.assertAlmostEquals(model.SRMSE, 0.46626328789729393)