예제 #1
0
파일: test_moran.py 프로젝트: GRSEB9S/esda
 def test_by_col(self):
     from libpysal.io import geotable as pdio
     df = pdio.read_files(pysal.examples.get_path('sids2.dbf'))
     mi = moran.Moran_Rate.by_col(df, ['SID79'], ['BIR79'], w=self.w, two_tailed=False)
     sidr = np.unique(mi["SID79-BIR79_moran_rate"].values)
     pval = np.unique(mi["SID79-BIR79_p_sim"].values)
     np.testing.assert_allclose(sidr, 0.16622343552567395, rtol=RTOL, atol=ATOL)
     self.assertAlmostEqual(pval, 0.009)
예제 #2
0
파일: test_moran.py 프로젝트: GRSEB9S/esda
 def test_by_col(self):
     from libpysal.io import geotable as pdio
     df = pdio.read_files(pysal.examples.get_path('sids2.dbf'))
     lm = moran.Moran_Local_Rate.by_col(df, ['SID79'], ['BIR79'], w=self.w,
                                        outvals=['p_z_sim', 'z_sim'],
                                        transformation='r', permutations=99)
     self.assertAlmostEqual(lm['SID79-BIR79_z_sim'][0],  -0.13699844503985936, 7)
     self.assertAlmostEqual(lm['SID79-BIR79_p_z_sim'][0], 0.44551601210081715)
예제 #3
0
파일: test_moran.py 프로젝트: GRSEB9S/esda
 def test_by_col(self):
     from libpysal.io import geotable as pdio
     df = pdio.read_files(pysal.examples.get_path('sids2.dbf'))
     w = pysal.open(pysal.examples.get_path("sids2.gal")).read()
     mi = moran.Moran.by_col(df, ['SIDR74'], w=w, two_tailed=False)
     sidr = np.unique(mi.SIDR74_moran.values)
     pval = np.unique(mi.SIDR74_p_sim.values)
     np.testing.assert_allclose(sidr, 0.24772519320480135, atol=ATOL, rtol=RTOL)
     self.assertAlmostEqual(pval, 0.001)
예제 #4
0
파일: test_moran.py 프로젝트: GRSEB9S/esda
 def test_by_col(self):
     from libpysal.io import geotable as pdio
     df = pdio.read_files(pysal.examples.get_path('sids2.dbf'))
     np.random.seed(12345)
     moran.Moran_Local_BV.by_col(df, ['SIDR74', 'SIDR79'], w=self.w,
                                 inplace=True, outvals=['z_sim', 'p_z_sim'],
                                 transformation='r', permutations=99)
     bvstats = df['SIDR79-SIDR74_moran_local_bv'].values
     bvz = df['SIDR79-SIDR74_z_sim'].values
     bvzp = df['SIDR79-SIDR74_p_z_sim'].values
     self.assertAlmostEqual(bvstats[0], 1.4649221250620736)
     self.assertAlmostEqual(bvz[0],  1.657427, 5)
     self.assertAlmostEqual(bvzp[0], 0.048717, 5)
예제 #5
0
 def test_by_col(self):
     from libpysal.io import geotable as pdio
     np.random.seed(11213)
     df = pdio.read_files(libpysal.examples.get_path('sids2.dbf'))
     w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read()
     k = int(w.n/2)
     mi = moran.Moran.by_col(df, ['SIDR74'], w=w, two_tailed=False).I
     rho = np.unique(mi.SIDR74_moran.values).item()
     sm = Smaup(w.n, k, rho)
     np.testing.assert_allclose(sm.smaup, 0.15176796553181948, atol=ATOL, rtol=RTOL)
     self.assertAlmostEqual(sm.critical_01, 0.38970613333333337)
     self.assertAlmostEqual(sm.critical_05, 0.3557221333333333)
     self.assertAlmostEqual(sm.critical_1, 0.3157950666666666)
     self.assertEqual(sm.summary, 'Pseudo p-value > 0.10 (H0 is not rejected)')
예제 #6
0
    def test_by_col(self):
        from libpysal.io import geotable as pdio

        df = pdio.read_files(libpysal.examples.get_path("sids2.dbf"))
        lm = moran.Moran_Local_Rate.by_col(
            df,
            ["SID79"],
            ["BIR79"],
            w=self.w,
            outvals=["p_z_sim", "z_sim"],
            transformation="r",
            permutations=99,
            seed=SEED,
        )
        self.assertAlmostEqual(lm["SID79-BIR79_z_sim"][0], 0.02702781851384379, 7)
        self.assertAlmostEqual(lm["SID79-BIR79_p_z_sim"][0], 0.4892187730835096)
예제 #7
0
    def test_by_col(self):
        from libpysal.io import geotable as pdio

        df = pdio.read_files(libpysal.examples.get_path("sids2.dbf"))
        moran.Moran_Local_BV.by_col(
            df,
            ["SIDR74", "SIDR79"],
            w=self.w,
            inplace=True,
            outvals=["z_sim", "p_z_sim"],
            transformation="r",
            permutations=99,
            keep_simulations=True,
            seed=SEED,
        )
        bvstats = df["SIDR79-SIDR74_moran_local_bv"].values
        bvz = df["SIDR79-SIDR74_z_sim"].values
        bvzp = df["SIDR79-SIDR74_p_z_sim"].values
        self.assertAlmostEqual(bvstats[0], 1.4649221250620736)
        self.assertAlmostEqual(bvz[0], 1.7900932313425777, 5)
        self.assertAlmostEqual(bvzp[0], 0.036719462378528744, 5)
예제 #8
0
#import pysal as ps
from libpysal.io import geotable
from libpysal import examples, weights
import numpy as np
from sklearn.metrics import pairwise as skm
from region.skater.skater import Spanning_Forest

import types
import os
TESTDIR = os.path.dirname(os.path.abspath(__file__))

#df = ps.pdio.read_files(ps.examples.get_path('south.shp'))
df = geotable.read_files(examples.get_path('south.shp'))
data = df[df.filter(like='90').columns.tolist() +
          df.filter(like='89').columns.tolist()].values
data_c = (data - data.mean(axis=0)) / data.std(axis=0)
W = weights.Queen.from_dataframe(df)


def test_init():
    default = Spanning_Forest()
    assert default.metric == skm.manhattan_distances
    assert default.center == np.mean
    assert default.reduction == np.sum
    change = Spanning_Forest(dissimilarity=skm.euclidean_distances,
                             center=np.median,
                             reduction=np.max)
    assert change.metric == skm.euclidean_distances
    assert change.center == np.median
    assert change.reduction == np.max
예제 #9
0
# In[18]:

giddy.ergodic.fmpt(m5.p)

# Thus, for a state with income in the first quintile, it takes on average 11.5 years for it to first enter the second quintile, 29.6 to get to the third quintile, 53.4 years to enter the fourth, and 103.6 years to reach the richest quintile.

# #### Regional context and Moran's Is

# Thus far we have treated all the spatial units as independent to estimate the transition probabilities. This hides an implicit assumption: the movement of a spatial unit in the income distribution is independent of the movement of its neighbors or the position of the neighbors in the distribution. But what if spatial context matters??
#
# We could plot the choropleth maps of per capita incomes in US to get a first impression of the spatial distribution.

# In[19]:

data_table = pdio.read_files(libpysal.examples.get_path('us48.shp'))
income_table = pd.read_csv(libpysal.examples.get_path("usjoin.csv"))
complete_table = data_table.merge(income_table,
                                  left_on='STATE_NAME',
                                  right_on='Name')
complete_table.head()

# In[20]:

index_year = range(1929, 2010, 15)
fig, axes = plt.subplots(nrows=2, ncols=3, figsize=(15, 7))
for i in range(2):
    for j in range(3):
        ax = axes[i, j]
        maps.geoplot(complete_table,
                     col=str(index_year[i * 3 + j]),
예제 #10
0
#import pysal as ps
from libpysal.io import geotable
from libpysal import examples, weights
import numpy as np
from sklearn.metrics import pairwise as skm
from region.skater.skater import Spanning_Forest

import types
import os
TESTDIR = os.path.dirname(os.path.abspath(__file__))


#df = ps.pdio.read_files(ps.examples.get_path('south.shp'))
df = geotable.read_files(examples.get_path('south.shp'))
data = df[df.filter(like='90').columns.tolist()
               + df.filter(like='89').columns.tolist()].values
data_c = (data - data.mean(axis=0)) / data.std(axis=0)
W = weights.Queen.from_dataframe(df)
    
def test_init():
    default = Spanning_Forest()
    assert default.metric == skm.manhattan_distances
    assert default.center == np.mean
    assert default.reduction == np.sum
    change = Spanning_Forest(dissimilarity=skm.euclidean_distances,
                             center=np.median, reduction=np.max)
    assert change.metric == skm.euclidean_distances
    assert change.center == np.median
    assert change.reduction == np.max

    sym = Spanning_Forest(affinity=skm.cosine_similarity)
예제 #11
0
# In[1]:


import libpysal
import libpysal.api as ps
import libpysal.io.geotable as pdio
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pylab import rcParams

import giddy
from splot import mapping as maps

shp_link = libpysal.examples.get_path('us48.shp')
data_table = pdio.read_files(shp_link)
income_table = pd.read_csv(libpysal.examples.get_path("usjoin.csv"))
complete_table = data_table.merge(income_table,left_on='STATE_NAME',right_on='Name')
complete_table.head()


"""
We will visualize the spatial distributions of per capita incomes in US states across 1929 to 2009 to obtain a first impression of the dynamics.

"""

index_year = range(1929,2010,15)
fig, axes = plt.subplots(nrows=2, ncols=3,figsize = (15,7))
for i in range(2):
    for j in range(3):
        ax = axes[i,j]