예제 #1
0
    def test_BS_F(self):
        est_Int = self.BS_F.by_col(' est_Intercept')
        se_Int = self.BS_F.by_col(' se_Intercept')
        t_Int = self.BS_F.by_col(' t_Intercept')
        est_OCC = self.BS_F.by_col(' est_OCC_TEC')
        se_OCC = self.BS_F.by_col(' se_OCC_TEC')
        t_OCC = self.BS_F.by_col(' t_OCC_TEC')
        est_OWN = self.BS_F.by_col(' est_OWNH')
        se_OWN = self.BS_F.by_col(' se_OWNH')
        t_OWN = self.BS_F.by_col(' t_OWNH')
        est_POP = self.BS_F.by_col(' est_POP65')
        se_POP = self.BS_F.by_col(' se_POP65')
        t_POP = self.BS_F.by_col(' t_POP65')
        est_UNEMP = self.BS_F.by_col(' est_UNEMP')
        se_UNEMP = self.BS_F.by_col(' se_UNEMP')
        t_UNEMP = self.BS_F.by_col(' t_UNEMP')
        yhat = self.BS_F.by_col(' yhat')
        pdev = np.array(self.BS_F.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=26029.625,
                    family=Poisson(),
                    kernel='bisquare',
                    fixed=True)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 13294.0)
        self.assertAlmostEquals(np.floor(AIC), 13247.0)
        self.assertAlmostEquals(np.floor(BIC), 13485.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-05)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-03)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-03)
        np.testing.assert_allclose(est_OCC, rslt.params[:, 1], rtol=1e-04)
        np.testing.assert_allclose(se_OCC, rslt.bse[:, 1], rtol=1e-02)
        np.testing.assert_allclose(t_OCC, rslt.tvalues[:, 1], rtol=1e-02)
        np.testing.assert_allclose(est_OWN, rslt.params[:, 2], rtol=1e-04)
        np.testing.assert_allclose(se_OWN, rslt.bse[:, 2], rtol=1e-03)
        np.testing.assert_allclose(t_OWN, rslt.tvalues[:, 2], rtol=1e-03)
        np.testing.assert_allclose(est_POP, rslt.params[:, 3], rtol=1e-04)
        np.testing.assert_allclose(se_POP, rslt.bse[:, 3], rtol=1e-02)
        np.testing.assert_allclose(t_POP, rslt.tvalues[:, 3], rtol=1e-02)
        np.testing.assert_allclose(est_UNEMP, rslt.params[:, 4], rtol=1e-04)
        np.testing.assert_allclose(se_UNEMP, rslt.bse[:, 4], rtol=1e-02)
        np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:, 4], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-05)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-05)
예제 #2
0
    def test_GS_NN(self):
        est_Int = self.GS_NN.by_col(' est_Intercept')
        se_Int = self.GS_NN.by_col(' se_Intercept')
        t_Int = self.GS_NN.by_col(' t_Intercept')
        est_OCC = self.GS_NN.by_col(' est_OCC_TEC')
        se_OCC = self.GS_NN.by_col(' se_OCC_TEC')
        t_OCC = self.GS_NN.by_col(' t_OCC_TEC')
        est_OWN = self.GS_NN.by_col(' est_OWNH')
        se_OWN = self.GS_NN.by_col(' se_OWNH')
        t_OWN = self.GS_NN.by_col(' t_OWNH')
        est_POP = self.GS_NN.by_col(' est_POP65')
        se_POP = self.GS_NN.by_col(' se_POP65')
        t_POP = self.GS_NN.by_col(' t_POP65')
        est_UNEMP = self.GS_NN.by_col(' est_UNEMP')
        se_UNEMP = self.GS_NN.by_col(' se_UNEMP')
        t_UNEMP = self.GS_NN.by_col(' t_UNEMP')
        yhat = self.GS_NN.by_col(' yhat')
        pdev = np.array(self.GS_NN.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=50,
                    family=Poisson(),
                    kernel='gaussian',
                    fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEquals(np.floor(AICc), 21070.0)
        self.assertAlmostEquals(np.floor(AIC), 21069.0)
        self.assertAlmostEquals(np.floor(BIC), 21111.0)
        np.testing.assert_allclose(est_Int, rslt.params[:, 0], rtol=1e-04)
        np.testing.assert_allclose(se_Int, rslt.bse[:, 0], rtol=1e-02)
        np.testing.assert_allclose(t_Int, rslt.tvalues[:, 0], rtol=1e-02)
        np.testing.assert_allclose(est_OCC, rslt.params[:, 1], rtol=1e-03)
        np.testing.assert_allclose(se_OCC, rslt.bse[:, 1], rtol=1e-02)
        np.testing.assert_allclose(t_OCC, rslt.tvalues[:, 1], rtol=1e-02)
        np.testing.assert_allclose(est_OWN, rslt.params[:, 2], rtol=1e-04)
        np.testing.assert_allclose(se_OWN, rslt.bse[:, 2], rtol=1e-02)
        np.testing.assert_allclose(t_OWN, rslt.tvalues[:, 2], rtol=1e-02)
        np.testing.assert_allclose(est_POP, rslt.params[:, 3], rtol=1e-02)
        np.testing.assert_allclose(se_POP, rslt.bse[:, 3], rtol=1e-02)
        np.testing.assert_allclose(t_POP, rslt.tvalues[:, 3], rtol=1e-02)
        np.testing.assert_allclose(est_UNEMP, rslt.params[:, 4], rtol=1e-02)
        np.testing.assert_allclose(se_UNEMP, rslt.bse[:, 4], rtol=1e-02)
        np.testing.assert_allclose(t_UNEMP, rslt.tvalues[:, 4], rtol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-04)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-05)
예제 #3
0
    def test_BS_NN_Offset(self):
        est_Int = self.BS_NN_OFF.by_col(' est_Intercept')
        se_Int = self.BS_NN_OFF.by_col(' se_Intercept')
        t_Int = self.BS_NN_OFF.by_col(' t_Intercept')
        est_OCC = self.BS_NN_OFF.by_col(' est_OCC_TEC')
        se_OCC = self.BS_NN_OFF.by_col(' se_OCC_TEC')
        t_OCC = self.BS_NN_OFF.by_col(' t_OCC_TEC')
        est_OWN = self.BS_NN_OFF.by_col(' est_OWNH')
        se_OWN = self.BS_NN_OFF.by_col(' se_OWNH')
        t_OWN = self.BS_NN_OFF.by_col(' t_OWNH')
        est_POP = self.BS_NN_OFF.by_col(' est_POP65')
        se_POP = self.BS_NN_OFF.by_col(' se_POP65')
        t_POP = self.BS_NN_OFF.by_col(' t_POP65')
        est_UNEMP = self.BS_NN_OFF.by_col(' est_UNEMP')
        se_UNEMP = self.BS_NN_OFF.by_col(' se_UNEMP')
        t_UNEMP = self.BS_NN_OFF.by_col(' t_UNEMP')
        yhat = self.BS_NN_OFF.by_col(' yhat')
        pdev = np.array(self.BS_NN_OFF.by_col(' localpdev')).reshape((-1, 1))

        model = GWR(self.coords,
                    self.y,
                    self.X,
                    bw=100,
                    offset=self.off,
                    family=Poisson(),
                    kernel='bisquare',
                    fixed=False)
        rslt = model.fit()

        AICc = get_AICc(rslt)
        AIC = get_AIC(rslt)
        BIC = get_BIC(rslt)

        self.assertAlmostEqual(np.floor(AICc), 367.0)
        self.assertAlmostEqual(np.floor(AIC), 361.0)
        self.assertAlmostEqual(np.floor(BIC), 451.0)
        np.testing.assert_allclose(est_Int,
                                   rslt.params[:, 0],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(se_Int,
                                   rslt.bse[:, 0],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(t_Int,
                                   rslt.tvalues[:, 0],
                                   rtol=1e-01,
                                   atol=1e-02)
        np.testing.assert_allclose(est_OCC,
                                   rslt.params[:, 1],
                                   rtol=1e-03,
                                   atol=1e-02)
        np.testing.assert_allclose(se_OCC,
                                   rslt.bse[:, 1],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(t_OCC,
                                   rslt.tvalues[:, 1],
                                   rtol=1e-01,
                                   atol=1e-02)
        np.testing.assert_allclose(est_OWN,
                                   rslt.params[:, 2],
                                   rtol=1e-04,
                                   atol=1e-02)
        np.testing.assert_allclose(se_OWN,
                                   rslt.bse[:, 2],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(t_OWN,
                                   rslt.tvalues[:, 2],
                                   rtol=1e-01,
                                   atol=1e-02)
        np.testing.assert_allclose(est_POP,
                                   rslt.params[:, 3],
                                   rtol=1e-03,
                                   atol=1e-02)
        np.testing.assert_allclose(se_POP,
                                   rslt.bse[:, 3],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(t_POP,
                                   rslt.tvalues[:, 3],
                                   rtol=1e-01,
                                   atol=1e-02)
        np.testing.assert_allclose(est_UNEMP,
                                   rslt.params[:, 4],
                                   rtol=1e-04,
                                   atol=1e-02)
        np.testing.assert_allclose(se_UNEMP,
                                   rslt.bse[:, 4],
                                   rtol=1e-02,
                                   atol=1e-02)
        np.testing.assert_allclose(t_UNEMP,
                                   rslt.tvalues[:, 4],
                                   rtol=1e-01,
                                   atol=1e-02)
        np.testing.assert_allclose(yhat, rslt.mu, rtol=1e-03, atol=1e-02)
        np.testing.assert_allclose(pdev, rslt.pDev, rtol=1e-04, atol=1e-02)