In [2]:
%matplotlib inline
In [1]:
import numpy as np
import pandas as pd
# 統計用ツール
import statsmodels.api as sm
import statsmodels.tsa.api as tsa
from patsy import dmatrices
# 自作の空間統計用ツール
from spatialstat import *
#描画
import matplotlib.pyplot as plt
from pandas.tools.plotting import autocorrelation_plot
import seaborn as sns
sns.set(font=['IPAmincho'])
import pyper
/Users/NIGG/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:1035: UserWarning: Duplicate key in file "/Users/NIGG/.matplotlib/matplotlibrc", line #515
(fname, cnt))
/Users/NIGG/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py:1035: UserWarning: Duplicate key in file "/Users/NIGG/.matplotlib/matplotlibrc", line #516
(fname, cnt))
In [3]:
data = pd.read_csv("TokyoSingle.csv")
In [1]:
data.head
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-051a76ec4ac4> in <module>()
----> 1 data.head
NameError: name 'data' is not defined
In [5]:
data[-6:-1]
Out[5]:
CENSUS
P
S
L
R
RW
CY
A
TS
TT
...
SOUTH
RSD
CMD
IDD
FAR
FLR
TDQ
X
Y
CITY_CODE
77495
13123043004
2780
82.60
57.44
3
4.0
200106
169
15
23
...
0
0
0
0
60
200
201503
35.72261
139.88423
13123
77496
13123053002
3480
111.56
76.69
4
4.0
201504
3
17
18
...
0
1
0
0
60
150
201503
35.71659
139.87892
13123
77497
13123021002
3490
86.76
88.59
4
7.5
201505
2
23
32
...
1
1
0
0
60
150
201503
35.69842
139.87823
13123
77498
13123051002
3600
77.00
78.53
3
8.1
201412
7
18
23
...
0
1
0
0
60
100
201503
35.72606
139.87268
13123
77499
13123055001
3999
99.77
74.94
4
6.0
201503
4
10
35
...
0
0
0
0
60
300
201503
35.69921
139.89479
13123
5 rows × 22 columns
In [6]:
data.shape
Out[6]:
(77501, 22)
In [7]:
data = data.dropna()
In [8]:
CITY_NAME = data['CITY_CODE'].copy()
In [9]:
CITY_NAME[CITY_NAME == 13101] = '01千代田区'
CITY_NAME[CITY_NAME == 13102] = "02中央区"
CITY_NAME[CITY_NAME == 13103] = "03港区"
CITY_NAME[CITY_NAME == 13104] = "04新宿区"
CITY_NAME[CITY_NAME == 13105] = "05文京区"
CITY_NAME[CITY_NAME == 13106] = "06台東区"
CITY_NAME[CITY_NAME == 13107] = "07墨田区"
CITY_NAME[CITY_NAME == 13108] = "08江東区"
CITY_NAME[CITY_NAME == 13109] = "09品川区"
CITY_NAME[CITY_NAME == 13110] = "10目黒区"
CITY_NAME[CITY_NAME == 13111] = "11大田区"
CITY_NAME[CITY_NAME == 13112] = "12世田谷区"
CITY_NAME[CITY_NAME == 13113] = "13渋谷区"
CITY_NAME[CITY_NAME == 13114] = "14中野区"
CITY_NAME[CITY_NAME == 13115] = "15杉並区"
CITY_NAME[CITY_NAME == 13116] = "16豊島区"
CITY_NAME[CITY_NAME == 13117] = "17北区"
CITY_NAME[CITY_NAME == 13118] = "18荒川区"
CITY_NAME[CITY_NAME == 13119] = "19板橋区"
CITY_NAME[CITY_NAME == 13120] = "20練馬区"
CITY_NAME[CITY_NAME == 13121] = "21足立区"
CITY_NAME[CITY_NAME == 13122] = "22葛飾区"
CITY_NAME[CITY_NAME == 13123] = "23江戸川区"
In [10]:
#Make Japanese Block name
BLOCK = data["CITY_CODE"].copy()
BLOCK[BLOCK == 13101] = "01都心・城南"
BLOCK[BLOCK == 13102] = "01都心・城南"
BLOCK[BLOCK == 13103] = "01都心・城南"
BLOCK[BLOCK == 13104] = "01都心・城南"
BLOCK[BLOCK == 13109] = "01都心・城南"
BLOCK[BLOCK == 13110] = "01都心・城南"
BLOCK[BLOCK == 13111] = "01都心・城南"
BLOCK[BLOCK == 13112] = "01都心・城南"
BLOCK[BLOCK == 13113] = "01都心・城南"
BLOCK[BLOCK == 13114] = "02城西・城北"
BLOCK[BLOCK == 13115] = "02城西・城北"
BLOCK[BLOCK == 13105] = "02城西・城北"
BLOCK[BLOCK == 13106] = "02城西・城北"
BLOCK[BLOCK == 13116] = "02城西・城北"
BLOCK[BLOCK == 13117] = "02城西・城北"
BLOCK[BLOCK == 13119] = "02城西・城北"
BLOCK[BLOCK == 13120] = "02城西・城北"
BLOCK[BLOCK == 13107] = "03城東"
BLOCK[BLOCK == 13108] = "03城東"
BLOCK[BLOCK == 13118] = "03城東"
BLOCK[BLOCK == 13121] = "03城東"
BLOCK[BLOCK == 13122] = "03城東"
BLOCK[BLOCK == 13123] = "03城東"
In [11]:
names = list(data.columns) + ['CITY_NAME', 'BLOCK']
data = pd.concat((data, CITY_NAME, BLOCK), axis = 1)
data.columns = names
CENSUS: 市区町村コード(9桁)
P: 成約価格
S: 専有面積
L: 土地面積
R: 部屋数
RW: 前面道路幅員
CY: 建築年
A: 建築後年数(成約時)
TS: 最寄駅までの距離
TT: 東京駅までの時間
ACC: ターミナル駅までの時間
WOOD: 木造ダミー
SOUTH: 南向きダミー
RSD: 住居系地域ダミー
CMD: 商業系地域ダミー
IDD: 工業系地域ダミー
FAR: 建ぺい率
FLR: 容積率
TDQ: 成約時点(四半期)
X: 緯度
Y: 経度
CITY_CODE: 市区町村コード(5桁)
CITY_NAME: 市区町村名
BLOCK: 地域ブロック名
In [12]:
s_data = data[['P', 'S', 'L', 'R', 'A', 'RW', 'TS', 'TT']]
In [13]:
s_data.describe()
Out[13]:
P
S
L
R
A
RW
TS
TT
count
77388.000000
77388.000000
77388.000000
77388.000000
77388.000000
77388.000000
77388.000000
77388.000000
mean
5745.409689
101.496476
86.631660
3.488978
50.046067
4.898872
10.339898
30.807698
std
3056.826263
35.732280
40.390705
0.918125
92.814379
1.997453
4.865877
7.738183
min
850.000000
31.190000
19.610000
0.000000
0.000000
2.000000
0.000000
1.000000
25%
3980.000000
84.250000
60.780000
3.000000
1.000000
4.000000
7.000000
26.000000
50%
4980.000000
94.600000
79.430000
3.000000
4.000000
4.000000
10.000000
31.000000
75%
6380.000000
106.510000
100.200000
4.000000
46.000000
5.500000
13.000000
37.000000
max
30000.000000
497.810000
495.860000
47.000000
412.000000
35.000000
69.000000
154.000000
In [14]:
print(data['TDQ'].value_counts())
201104 2108
201502 1923
200504 1900
200604 1816
200602 1755
201204 1713
200404 1645
200704 1564
200501 1564
200502 1542
200601 1542
201501 1519
200503 1499
201404 1495
200702 1477
200701 1476
200603 1469
200703 1438
200902 1437
200802 1417
200403 1382
201304 1374
200804 1373
201202 1289
200104 1272
200803 1271
200204 1260
200903 1242
201201 1237
201203 1235
...
201004 1161
200402 1158
200304 1105
201403 1066
201303 1056
201102 1055
201402 1038
200904 1033
200004 1021
200103 991
200202 989
200101 989
201002 981
200201 979
200102 977
201301 975
201101 974
201401 962
201003 958
201103 954
200401 926
201001 920
200302 901
200203 841
200301 839
200001 834
200002 800
200003 739
200303 689
201503 583
Name: TDQ, dtype: int64
In [15]:
print(data['CITY_NAME'].value_counts())
12世田谷区 12340
20練馬区 9979
15杉並区 8131
11大田区 7052
21足立区 6479
19板橋区 4827
14中野区 3924
10目黒区 3418
22葛飾区 3165
23江戸川区 3156
09品川区 2424
16豊島区 2153
04新宿区 1885
17北区 1799
13渋谷区 1487
05文京区 1242
18荒川区 1005
08江東区 981
03港区 757
07墨田区 725
06台東区 371
02中央区 56
01千代田区 32
Name: CITY_NAME, dtype: int64
In [16]:
print(data.pivot_table(index=['TDQ'], columns=['CITY_NAME']))
CENSUS \
CITY_NAME 01千代田区 02中央区 03港区 04新宿区
TDQ
200001 1.310105e+10 NaN 1.310302e+10 1.310406e+10
200002 NaN NaN 1.310302e+10 1.310405e+10
200003 1.310100e+10 NaN 1.310302e+10 1.310405e+10
200004 NaN NaN 1.310302e+10 1.310405e+10
200101 NaN 1.310202e+10 1.310302e+10 1.310405e+10
200102 NaN 1.310202e+10 1.310302e+10 1.310406e+10
200103 1.310105e+10 NaN 1.310302e+10 1.310406e+10
200104 NaN NaN 1.310302e+10 1.310405e+10
200201 NaN NaN 1.310302e+10 1.310406e+10
200202 1.310105e+10 1.310204e+10 1.310302e+10 1.310405e+10
200203 1.310105e+10 NaN 1.310302e+10 1.310406e+10
200204 1.310105e+10 1.310203e+10 1.310302e+10 1.310406e+10
200301 1.310105e+10 1.310201e+10 1.310302e+10 1.310405e+10
200302 1.310101e+10 1.310204e+10 1.310302e+10 1.310406e+10
200303 1.310104e+10 1.310201e+10 1.310301e+10 1.310406e+10
200304 NaN 1.310202e+10 1.310302e+10 1.310405e+10
200401 NaN 1.310202e+10 1.310302e+10 1.310405e+10
200402 1.310104e+10 1.310201e+10 1.310302e+10 1.310406e+10
200403 1.310104e+10 1.310202e+10 1.310302e+10 1.310405e+10
200404 NaN 1.310202e+10 1.310302e+10 1.310406e+10
200501 NaN 1.310201e+10 1.310302e+10 1.310406e+10
200502 NaN NaN 1.310302e+10 1.310406e+10
200503 NaN 1.310203e+10 1.310302e+10 1.310406e+10
200504 NaN 1.310203e+10 1.310301e+10 1.310406e+10
200601 NaN NaN 1.310302e+10 1.310406e+10
200602 NaN NaN 1.310302e+10 1.310405e+10
200603 NaN 1.310201e+10 1.310302e+10 1.310406e+10
200604 NaN 1.310204e+10 1.310302e+10 1.310406e+10
200701 NaN NaN 1.310302e+10 1.310405e+10
200702 NaN 1.310201e+10 1.310302e+10 1.310406e+10
... ... ... ... ...
200802 NaN 1.310203e+10 1.310302e+10 1.310406e+10
200803 NaN 1.310203e+10 1.310302e+10 1.310405e+10
200804 NaN NaN 1.310302e+10 1.310407e+10
200901 NaN NaN 1.310302e+10 1.310405e+10
200902 NaN NaN 1.310300e+10 1.310406e+10
200903 NaN NaN 1.310301e+10 1.310405e+10
200904 NaN 1.310204e+10 1.310302e+10 1.310406e+10
201001 NaN NaN 1.310302e+10 1.310406e+10
201002 NaN 1.310201e+10 1.310302e+10 1.310405e+10
201003 NaN NaN 1.310302e+10 1.310405e+10
201004 NaN 1.310201e+10 1.310302e+10 1.310405e+10
201101 NaN NaN 1.310302e+10 1.310405e+10
201102 NaN 1.310201e+10 1.310302e+10 1.310406e+10
201103 NaN 1.310202e+10 1.310302e+10 1.310406e+10
201104 NaN NaN 1.310301e+10 1.310406e+10
201201 1.310100e+10 NaN 1.310302e+10 1.310405e+10
201202 1.310105e+10 1.310202e+10 1.310301e+10 1.310406e+10
201203 NaN NaN 1.310302e+10 1.310406e+10
201204 NaN 1.310202e+10 1.310302e+10 1.310405e+10
201301 NaN 1.310202e+10 1.310301e+10 1.310406e+10
201302 1.310104e+10 1.310201e+10 1.310302e+10 1.310406e+10
201303 NaN NaN 1.310301e+10 1.310406e+10
201304 1.310105e+10 NaN 1.310302e+10 1.310405e+10
201401 NaN 1.310201e+10 1.310302e+10 1.310405e+10
201402 1.310105e+10 NaN 1.310302e+10 1.310406e+10
201403 NaN NaN 1.310302e+10 1.310405e+10
201404 NaN 1.310201e+10 1.310302e+10 1.310406e+10
201501 1.310102e+10 NaN 1.310302e+10 1.310406e+10
201502 1.310100e+10 1.310201e+10 1.310302e+10 1.310405e+10
201503 NaN NaN NaN 1.310405e+10
\
CITY_NAME 05文京区 06台東区 07墨田区 08江東区
TDQ
200001 1.310501e+10 1.310602e+10 1.310703e+10 1.310803e+10
200002 1.310501e+10 1.310603e+10 1.310702e+10 1.310802e+10
200003 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
200004 1.310501e+10 1.310602e+10 1.310701e+10 1.310801e+10
200101 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200102 1.310501e+10 1.310603e+10 1.310701e+10 1.310802e+10
200103 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200104 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200201 1.310501e+10 1.310602e+10 NaN 1.310802e+10
200202 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200203 1.310501e+10 1.310603e+10 1.310702e+10 1.310802e+10
200204 1.310501e+10 1.310602e+10 1.310702e+10 1.310801e+10
200301 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
200302 1.310501e+10 1.310601e+10 1.310702e+10 1.310803e+10
200303 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
200304 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200401 1.310501e+10 1.310602e+10 1.310702e+10 1.310801e+10
200402 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
200403 1.310501e+10 1.310602e+10 1.310702e+10 1.310801e+10
200404 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200501 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200502 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200503 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200504 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200601 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200602 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200603 1.310501e+10 1.310601e+10 1.310701e+10 1.310802e+10
200604 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
200701 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
200702 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
... ... ... ... ...
200802 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200803 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200804 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200901 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200902 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
200903 1.310501e+10 1.310601e+10 1.310701e+10 1.310801e+10
200904 1.310501e+10 1.310601e+10 1.310701e+10 1.310802e+10
201001 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201002 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201003 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201004 1.310501e+10 1.310601e+10 1.310701e+10 1.310802e+10
201101 1.310501e+10 1.310601e+10 1.310701e+10 1.310801e+10
201102 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201103 1.310501e+10 1.310602e+10 1.310701e+10 1.310801e+10
201104 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201201 1.310501e+10 1.310603e+10 1.310702e+10 1.310802e+10
201202 1.310501e+10 1.310603e+10 1.310702e+10 1.310802e+10
201203 1.310501e+10 1.310601e+10 1.310702e+10 1.310802e+10
201204 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201301 1.310501e+10 1.310602e+10 1.310702e+10 1.310801e+10
201302 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201303 1.310501e+10 NaN 1.310701e+10 1.310803e+10
201304 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201401 1.310501e+10 1.310601e+10 1.310701e+10 1.310802e+10
201402 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201403 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201404 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
201501 1.310501e+10 1.310601e+10 1.310701e+10 1.310802e+10
201502 1.310501e+10 1.310602e+10 1.310701e+10 1.310802e+10
201503 1.310501e+10 1.310602e+10 1.310702e+10 1.310802e+10
... CITY_CODE \
CITY_NAME 09品川区 10目黒区 ... 14中野区 15杉並区 16豊島区 17北区
TDQ ...
200001 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200002 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200003 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200004 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200101 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200102 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200103 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200104 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200201 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200202 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200203 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200204 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200301 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200302 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200303 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200304 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200401 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200402 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200403 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200404 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200501 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200502 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200503 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200504 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200601 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200602 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200603 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200604 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200701 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200702 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
... ... ... ... ... ... ... ...
200802 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200803 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200804 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200901 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200902 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
200903 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
200904 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201001 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201002 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201003 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201004 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201101 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201102 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201103 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201104 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201201 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201202 1.310902e+10 1.311001e+10 ... 13114 13115 13116 13117
201203 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201204 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201301 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201302 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201303 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201304 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201401 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201402 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201403 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201404 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201501 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
201502 1.310901e+10 1.311001e+10 ... 13114 13115 13116 13117
201503 1.310901e+10 1.311002e+10 ... 13114 13115 13116 13117
CITY_NAME 18荒川区 19板橋区 20練馬区 21足立区 22葛飾区 23江戸川区
TDQ
200001 13118 13119 13120 13121 13122 13123
200002 13118 13119 13120 13121 13122 13123
200003 13118 13119 13120 13121 13122 13123
200004 13118 13119 13120 13121 13122 13123
200101 13118 13119 13120 13121 13122 13123
200102 13118 13119 13120 13121 13122 13123
200103 13118 13119 13120 13121 13122 13123
200104 13118 13119 13120 13121 13122 13123
200201 13118 13119 13120 13121 13122 13123
200202 13118 13119 13120 13121 13122 13123
200203 13118 13119 13120 13121 13122 13123
200204 13118 13119 13120 13121 13122 13123
200301 13118 13119 13120 13121 13122 13123
200302 13118 13119 13120 13121 13122 13123
200303 13118 13119 13120 13121 13122 13123
200304 13118 13119 13120 13121 13122 13123
200401 13118 13119 13120 13121 13122 13123
200402 13118 13119 13120 13121 13122 13123
200403 13118 13119 13120 13121 13122 13123
200404 13118 13119 13120 13121 13122 13123
200501 13118 13119 13120 13121 13122 13123
200502 13118 13119 13120 13121 13122 13123
200503 13118 13119 13120 13121 13122 13123
200504 13118 13119 13120 13121 13122 13123
200601 13118 13119 13120 13121 13122 13123
200602 13118 13119 13120 13121 13122 13123
200603 13118 13119 13120 13121 13122 13123
200604 13118 13119 13120 13121 13122 13123
200701 13118 13119 13120 13121 13122 13123
200702 13118 13119 13120 13121 13122 13123
... ... ... ... ... ... ...
200802 13118 13119 13120 13121 13122 13123
200803 13118 13119 13120 13121 13122 13123
200804 13118 13119 13120 13121 13122 13123
200901 13118 13119 13120 13121 13122 13123
200902 13118 13119 13120 13121 13122 13123
200903 13118 13119 13120 13121 13122 13123
200904 13118 13119 13120 13121 13122 13123
201001 13118 13119 13120 13121 13122 13123
201002 13118 13119 13120 13121 13122 13123
201003 13118 13119 13120 13121 13122 13123
201004 13118 13119 13120 13121 13122 13123
201101 13118 13119 13120 13121 13122 13123
201102 13118 13119 13120 13121 13122 13123
201103 13118 13119 13120 13121 13122 13123
201104 13118 13119 13120 13121 13122 13123
201201 13118 13119 13120 13121 13122 13123
201202 13118 13119 13120 13121 13122 13123
201203 13118 13119 13120 13121 13122 13123
201204 13118 13119 13120 13121 13122 13123
201301 13118 13119 13120 13121 13122 13123
201302 13118 13119 13120 13121 13122 13123
201303 13118 13119 13120 13121 13122 13123
201304 13118 13119 13120 13121 13122 13123
201401 13118 13119 13120 13121 13122 13123
201402 13118 13119 13120 13121 13122 13123
201403 13118 13119 13120 13121 13122 13123
201404 13118 13119 13120 13121 13122 13123
201501 13118 13119 13120 13121 13122 13123
201502 13118 13119 13120 13121 13122 13123
201503 13118 13119 13120 13121 13122 13123
[63 rows x 483 columns]
In [17]:
print(data.pivot_table(index=['TDQ'], columns=['BLOCK']))
CENSUS P \
BLOCK 01都心・城南 02城西・城北 03城東 01都心・城南 02城西・城北
TDQ
200001 1.311033e+10 1.311581e+10 1.312004e+10 7399.858911 5872.318681
200002 1.311049e+10 1.311637e+10 1.312009e+10 7276.618938 5932.909408
200003 1.311055e+10 1.311578e+10 1.312082e+10 7139.290816 6176.982456
200004 1.311079e+10 1.311620e+10 1.312014e+10 7459.767967 5993.241259
200101 1.311038e+10 1.311591e+10 1.312024e+10 7151.689342 5833.323113
200102 1.311053e+10 1.311655e+10 1.312063e+10 7554.334135 5519.058796
200103 1.311082e+10 1.311643e+10 1.312039e+10 7442.875670 5529.286207
200104 1.311045e+10 1.311618e+10 1.312042e+10 7318.639191 5471.789796
200201 1.311046e+10 1.311595e+10 1.312069e+10 6842.570213 5469.279188
200202 1.311071e+10 1.311551e+10 1.312051e+10 6772.594912 5562.571148
200203 1.311062e+10 1.311589e+10 1.312000e+10 7093.306619 5543.623567
200204 1.311072e+10 1.311578e+10 1.312049e+10 6833.169727 5685.290974
200301 1.311070e+10 1.311610e+10 1.311914e+10 7396.902975 5280.512821
200302 1.311064e+10 1.311602e+10 1.312039e+10 6759.205567 5374.607407
200303 1.311055e+10 1.311641e+10 1.312097e+10 6939.937391 5201.690043
200304 1.311050e+10 1.311633e+10 1.312075e+10 7262.770251 5324.960497
200401 1.311041e+10 1.311636e+10 1.312045e+10 7109.541119 5213.655108
200402 1.311070e+10 1.311678e+10 1.312044e+10 6923.363345 4987.354267
200403 1.311062e+10 1.311613e+10 1.311985e+10 7000.491568 5309.601212
200404 1.311049e+10 1.311601e+10 1.312027e+10 7055.453600 5343.703800
200501 1.311051e+10 1.311653e+10 1.312005e+10 6886.984151 5202.612126
200502 1.311050e+10 1.311640e+10 1.311954e+10 7150.359728 5340.393874
200503 1.311057e+10 1.311634e+10 1.311947e+10 7335.625516 5260.281683
200504 1.311087e+10 1.311613e+10 1.311917e+10 7835.427525 5541.041437
200601 1.311073e+10 1.311617e+10 1.311982e+10 7789.539701 5444.865127
200602 1.311080e+10 1.311664e+10 1.311997e+10 7957.132747 5545.012022
200603 1.311097e+10 1.311652e+10 1.311953e+10 7899.027634 5567.982686
200604 1.311078e+10 1.311699e+10 1.311884e+10 8585.407240 5598.507763
200701 1.311059e+10 1.311669e+10 1.311971e+10 8362.876740 5851.591239
200702 1.311068e+10 1.311665e+10 1.311951e+10 8699.175887 5747.957524
... ... ... ... ... ...
200802 1.311091e+10 1.311697e+10 1.311943e+10 8726.384946 5435.136049
200803 1.311086e+10 1.311677e+10 1.311970e+10 8592.913420 5404.359375
200804 1.311073e+10 1.311694e+10 1.311946e+10 7785.852273 5267.044248
200901 1.311073e+10 1.311695e+10 1.311998e+10 6568.142184 5044.784749
200902 1.311071e+10 1.311678e+10 1.311962e+10 6429.386024 5014.242623
200903 1.311071e+10 1.311666e+10 1.311935e+10 7150.550905 5034.155670
200904 1.311046e+10 1.311688e+10 1.312054e+10 6908.893939 5004.963519
201001 1.311058e+10 1.311705e+10 1.312052e+10 7765.467148 5057.545642
201002 1.311044e+10 1.311726e+10 1.312051e+10 7537.208481 5019.010515
201003 1.311045e+10 1.311690e+10 1.311983e+10 7137.339175 4993.959406
201004 1.311005e+10 1.311683e+10 1.312017e+10 6675.804154 5145.535135
201101 1.311025e+10 1.311732e+10 1.311987e+10 6976.826165 4984.240534
201102 1.311049e+10 1.311718e+10 1.311974e+10 6933.179211 5033.169742
201103 1.311055e+10 1.311719e+10 1.312004e+10 6966.469582 4903.657282
201104 1.311048e+10 1.311718e+10 1.311971e+10 6328.623408 5035.399886
201201 1.311027e+10 1.311768e+10 1.312025e+10 6222.344512 4637.095986
201202 1.311026e+10 1.311673e+10 1.312021e+10 6071.030585 4955.065480
201203 1.311021e+10 1.311705e+10 1.311968e+10 6715.687831 4769.312000
201204 1.311053e+10 1.311693e+10 1.312015e+10 6569.068468 4916.640488
201301 1.311031e+10 1.311692e+10 1.311989e+10 6626.559322 4701.993534
201302 1.311033e+10 1.311699e+10 1.311966e+10 6388.288571 4971.381910
201303 1.311061e+10 1.311732e+10 1.311940e+10 6300.783489 4989.930285
201304 1.311040e+10 1.311717e+10 1.312022e+10 7163.943128 4859.165391
201401 1.311048e+10 1.311691e+10 1.311948e+10 6822.179104 4911.749465
201402 1.311025e+10 1.311740e+10 1.311980e+10 7153.518272 5087.525253
201403 1.311036e+10 1.311722e+10 1.312020e+10 6556.274667 5068.709552
201404 1.311037e+10 1.311713e+10 1.312025e+10 6852.042691 5078.867982
201501 1.311047e+10 1.311652e+10 1.312094e+10 6994.015232 5306.357456
201502 1.311042e+10 1.311782e+10 1.312087e+10 6859.167411 5057.464821
201503 1.311087e+10 1.311715e+10 1.312066e+10 6568.333333 5211.302752
S L \
BLOCK 03城東 01都心・城南 02城西・城北 03城東 01都心・城南
TDQ
200001 4342.893939 109.886510 101.313049 95.806061 96.094109
200002 4263.587500 110.943626 98.588850 96.373875 90.328984
200003 3885.451613 110.268878 104.887825 89.108871 90.320893
200004 3877.380952 109.713285 102.114779 91.677238 93.488316
200101 4000.080645 111.666531 99.680849 93.551452 91.848413
200102 3998.627907 115.039038 97.776389 92.194496 95.097476
200103 3938.796296 115.121094 98.338046 90.566944 99.352522
200104 3807.068345 114.098927 98.800694 90.891799 94.741104
200201 3946.328696 108.481426 99.895203 94.344870 90.678340
200202 3850.991736 108.577593 100.753221 94.817438 89.865068
200203 3902.548077 112.454374 102.413408 96.396442 94.828676
200204 3765.760563 110.505681 104.168551 95.223239 91.662525
200301 3711.511628 117.275584 101.960842 94.006589 98.038215
200302 3563.806849 107.987505 102.074481 93.208356 93.900165
200303 3632.924779 111.113014 99.758961 91.883363 93.382203
200304 3527.335676 114.895753 100.466547 92.002486 94.593853
200401 3741.924476 113.213650 101.440565 90.395385 98.272628
200402 3669.998561 107.927527 97.883939 92.669281 90.107189
200403 3699.347656 110.898564 98.960162 94.314531 90.994585
200404 3892.790576 110.278777 96.764214 94.518796 90.713611
200501 3623.847390 107.042693 96.776877 94.167229 84.594306
200502 3620.228175 110.890762 98.323964 92.478373 89.931878
200503 3832.634884 110.107581 96.561386 95.084791 89.122522
200504 3743.683516 115.244205 98.122275 92.941209 93.506717
200601 3810.079182 113.246860 98.441923 93.572268 91.155432
200602 3944.528873 112.933518 97.822036 97.791444 92.177226
200603 3852.379779 109.085596 97.203689 92.237794 89.620466
200604 4066.222022 115.380060 96.780582 95.986534 93.240332
200701 4036.992537 110.395201 98.892175 95.334216 88.085110
200702 4051.605455 112.706578 94.409969 93.955855 88.693422
... ... ... ... ... ...
200802 4073.076950 114.779032 96.855806 97.110887 91.047993
200803 4048.696226 112.015736 94.480533 93.900679 87.243550
200804 3934.287037 110.003760 94.639416 95.405093 86.697438
200901 3748.933929 101.480968 93.525290 94.656036 80.677122
200902 3767.257053 101.103012 94.692705 95.880721 78.172402
200903 3732.136508 109.276244 96.970144 92.538476 88.493688
200904 3676.596667 103.466465 95.532146 92.793815 87.305488
201001 3586.077295 112.258520 98.282982 93.171353 94.694585
201002 3629.482072 113.664452 95.185772 94.813386 95.894028
201003 3635.551331 111.118522 94.095520 93.342433 92.458213
201004 3633.464052 103.400504 96.477819 95.044216 83.251840
201101 3519.669611 108.764409 96.603932 91.858763 85.954839
201102 3770.754839 109.740143 96.366953 94.011323 87.358889
201103 3632.810036 106.479772 94.378908 94.004373 85.781141
201104 3536.671381 100.830573 94.504107 94.249318 80.012006
201201 3434.345238 100.832774 92.668482 96.376756 79.550030
201202 3334.376068 101.839947 95.896014 94.123789 81.162340
201203 3379.436170 107.701429 96.543652 96.905142 86.283095
201204 3403.239645 106.357730 95.730671 95.343077 87.074595
201301 3452.037037 109.063356 94.608405 97.298287 84.765627
201302 3483.681004 107.559171 97.460754 96.070538 85.030571
201303 3462.378601 101.901651 96.244309 95.532099 84.027352
201304 3494.872910 108.257393 94.492481 93.579197 88.679526
201401 3580.691630 108.491866 93.916895 94.515154 88.164813
201402 3532.954545 109.673688 96.399455 93.780083 90.575781
201403 3572.537549 107.543733 95.648207 96.449328 86.863100
201404 3484.062469 107.780070 95.239241 97.161235 83.963225
201501 3442.073982 107.368146 99.350724 96.764376 87.974371
201502 3552.597533 105.017433 95.557935 95.747089 82.450647
201503 3499.192857 106.680578 95.268624 94.126857 88.039600
... FLR X Y \
BLOCK ... 03城東 01都心・城南 02城西・城北 03城東 01都心・城南
TDQ ...
200001 ... 234.393939 35.630043 35.722496 35.733464 139.680251
200002 ... 212.500000 35.629669 35.724128 35.729507 139.676333
200003 ... 202.096774 35.629520 35.725294 35.725902 139.678867
200004 ... 199.238095 35.633891 35.721874 35.740678 139.671286
200101 ... 206.322581 35.635773 35.723339 35.738500 139.675384
200102 ... 206.666667 35.632474 35.727582 35.734954 139.676147
200103 ... 209.351852 35.628844 35.726785 35.733586 139.672155
200104 ... 207.266187 35.632836 35.725522 35.735263 139.677330
200201 ... 211.573913 35.628624 35.722669 35.742449 139.681407
200202 ... 211.157025 35.629130 35.721566 35.745758 139.675710
200203 ... 214.423077 35.628354 35.725421 35.744459 139.675646
200204 ... 205.408451 35.625121 35.721058 35.747268 139.672471
200301 ... 200.186047 35.626068 35.722233 35.739261 139.672514
200302 ... 211.986301 35.623800 35.726029 35.750007 139.675078
200303 ... 213.734513 35.629136 35.731217 35.741070 139.675683
200304 ... 224.108108 35.625096 35.727924 35.747115 139.678946
200401 ... 212.657343 35.625870 35.726181 35.740994 139.681423
200402 ... 216.776978 35.626256 35.731345 35.745774 139.675894
200403 ... 219.765625 35.627503 35.725403 35.738646 139.675597
200404 ... 218.324607 35.627143 35.725046 35.732742 139.680131
200501 ... 218.955823 35.628011 35.730142 35.741997 139.680485
200502 ... 222.753968 35.626627 35.728124 35.739197 139.677334
200503 ... 232.497674 35.630453 35.729936 35.738252 139.677789
200504 ... 218.263736 35.629625 35.726231 35.736446 139.671230
200601 ... 222.267658 35.630608 35.728927 35.738099 139.676025
200602 ... 216.158451 35.629633 35.730181 35.739113 139.671838
200603 ... 212.205882 35.626906 35.729815 35.739319 139.670670
200604 ... 223.552347 35.625756 35.731999 35.737863 139.675983
200701 ... 211.977612 35.628254 35.733513 35.734373 139.678770
200702 ... 220.872727 35.630020 35.733647 35.739891 139.675765
... ... ... ... ... ... ...
200802 ... 214.680851 35.627703 35.738356 35.747284 139.673660
200803 ... 206.709434 35.633291 35.732597 35.739248 139.673331
200804 ... 208.641975 35.634198 35.733916 35.740282 139.669751
200901 ... 210.089286 35.630074 35.734541 35.745442 139.672215
200902 ... 217.269592 35.627954 35.735144 35.746884 139.676090
200903 ... 213.304762 35.629330 35.732546 35.744821 139.676358
200904 ... 212.374074 35.633071 35.734704 35.749027 139.674321
201001 ... 212.309179 35.630347 35.737451 35.755518 139.675238
201002 ... 223.537849 35.627164 35.737017 35.755349 139.679731
201003 ... 205.102662 35.632317 35.738675 35.756564 139.673538
201004 ... 212.787582 35.634778 35.735675 35.759718 139.677998
201101 ... 209.621908 35.629108 35.739901 35.757462 139.678536
201102 ... 216.174194 35.631420 35.738100 35.754371 139.673153
201103 ... 210.774194 35.629988 35.740201 35.758988 139.671948
201104 ... 207.051581 35.624915 35.733924 35.761114 139.678299
201201 ... 206.375000 35.624753 35.742329 35.753440 139.682148
201202 ... 212.062678 35.622668 35.733227 35.760703 139.681607
201203 ... 213.882979 35.621498 35.737343 35.755607 139.687295
201204 ... 212.707101 35.620917 35.736367 35.752881 139.682315
201301 ... 215.537037 35.627383 35.736899 35.745723 139.682754
201302 ... 212.301075 35.621128 35.737420 35.747653 139.682540
201303 ... 213.703704 35.627200 35.734930 35.742879 139.679392
201304 ... 213.347826 35.626072 35.737011 35.746977 139.679402
201401 ... 212.687225 35.622717 35.735975 35.742254 139.682915
201402 ... 213.698347 35.622825 35.735145 35.746510 139.682949
201403 ... 203.857708 35.631445 35.735341 35.750486 139.674674
201404 ... 206.195062 35.625509 35.736719 35.754400 139.677781
201501 ... 198.308804 35.622149 35.736509 35.769413 139.683071
201502 ... 197.643092 35.619530 35.740447 35.763233 139.683499
201503 ... 199.257143 35.602161 35.735219 35.759738 139.689096
CITY_CODE
BLOCK 02城西・城北 03城東 01都心・城南 02城西・城北 03城東
TDQ
200001 139.649451 139.834092 13110.299505 13115.793956 13120.015152
200002 139.644771 139.842428 13110.459584 13116.351916 13120.050000
200003 139.648323 139.845460 13110.525510 13115.761404 13120.790323
200004 139.643573 139.838385 13110.761807 13116.184149 13120.104762
200101 139.652287 139.835395 13110.351474 13115.891509 13120.201613
200102 139.649514 139.837392 13110.495192 13116.530093 13120.596899
200103 139.647426 139.841819 13110.792411 13116.406897 13120.361111
200104 139.651751 139.842005 13110.418351 13116.157143 13120.388489
200201 139.646920 139.833643 13110.431915 13115.928934 13120.660870
200202 139.651515 139.829698 13110.686888 13115.495798 13120.479339
200203 139.650306 139.831712 13110.595745 13115.869427 13119.961538
200204 139.649557 139.829357 13110.694405 13115.764846 13120.457746
200301 139.646554 139.832306 13110.670481 13116.084249 13119.108527
200302 139.647117 139.824471 13110.618557 13116.000000 13120.356164
200303 139.649193 139.834882 13110.518841 13116.389610 13120.929204
200304 139.647735 139.829131 13110.474910 13116.306630 13120.713514
200401 139.645021 139.836905 13110.379562 13116.338710 13120.419580
200402 139.643990 139.833927 13110.674377 13116.763676 13120.410072
200403 139.644290 139.836949 13110.595520 13116.107071 13119.820312
200404 139.649179 139.839443 13110.466286 13115.986183 13120.240838
200501 139.648260 139.833198 13110.479663 13116.508306 13120.016064
200502 139.647200 139.834959 13110.468027 13116.381982 13119.511905
200503 139.649991 139.831001 13110.536873 13116.318482 13119.441860
200504 139.648032 139.838210 13110.838384 13116.106587 13119.142857
200601 139.654241 139.836145 13110.697674 13116.146051 13119.791822
200602 139.647578 139.839687 13110.775372 13116.621585 13119.936620
200603 139.648569 139.833187 13110.946459 13116.501618 13119.496324
200604 139.645956 139.832390 13110.752640 13116.970320 13118.812274
200701 139.652187 139.841142 13110.556777 13116.672205 13119.679104
200702 139.651173 139.832926 13110.648936 13116.631661 13119.483636
... ... ... ... ... ...
200802 139.656294 139.826465 13110.883513 13116.946274 13119.400709
200803 139.651862 139.837203 13110.831169 13116.751838 13119.671698
200804 139.651720 139.835030 13110.702479 13116.923894 13119.419753
200901 139.657372 139.828553 13110.704715 13116.928571 13119.946429
200902 139.659791 139.827122 13110.683071 13116.757377 13119.586207
200903 139.657754 139.829289 13110.680995 13116.641237 13119.317460
200904 139.654332 139.830089 13110.427609 13116.860515 13120.503704
201001 139.653327 139.820225 13110.555957 13117.029817 13120.483092
201002 139.650750 139.826256 13110.409894 13117.243848 13120.474104
201003 139.656494 139.822836 13110.419244 13116.883663 13119.787072
201004 139.655110 139.817664 13110.020772 13116.812741 13120.137255
201101 139.649089 139.823822 13110.225806 13117.298544 13119.833922
201102 139.652478 139.821606 13110.462366 13117.154506 13119.706452
201103 139.657300 139.818537 13110.517110 13117.169903 13120.003584
201104 139.648339 139.811954 13110.453822 13117.161547 13119.658902
201201 139.650280 139.819006 13110.250000 13117.659686 13120.205357
201202 139.655550 139.817293 13110.234043 13116.713523 13120.168091
201203 139.654861 139.819908 13110.179894 13117.031304 13119.645390
201204 139.657071 139.822542 13110.497297 13116.914634 13120.109467
201301 139.657950 139.823817 13110.281356 13116.900862 13119.851852
201302 139.651693 139.827017 13110.302857 13116.974874 13119.627240
201303 139.651808 139.829478 13110.582555 13117.300813 13119.374486
201304 139.650595 139.831361 13110.367299 13117.145482 13120.190635
201401 139.653129 139.829940 13110.455224 13116.886510 13119.449339
201402 139.645310 139.826844 13110.222591 13117.379798 13119.768595
201403 139.649722 139.828153 13110.333333 13117.196881 13120.158103
201404 139.649729 139.819608 13110.343387 13117.106222 13120.209877
201501 139.659141 139.810189 13110.443709 13116.502193 13120.888305
201502 139.641752 139.823394 13110.388393 13117.797001 13120.827303
201503 139.656263 139.825987 13110.840000 13117.133028 13120.621429
[63 rows x 63 columns]
In [18]:
data['P'].hist()
Out[18]:
<matplotlib.axes._subplots.AxesSubplot at 0x117034828>
In [19]:
(np.log(data['P'])).hist()
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x117034f60>
In [20]:
data['A'].hist()
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x108cb4198>
In [21]:
plt.figure(figsize=(20,8))
plt.subplot(4, 2, 1)
data['P'].hist()
plt.title(u"成約価格")
plt.subplot(4, 2, 2)
data['S'].hist()
plt.title("専有面積")
plt.subplot(4, 2, 3)
data['L'].hist()
plt.title("土地面積")
plt.subplot(4, 2, 4)
data['R'].hist()
plt.title("部屋数")
plt.subplot(4, 2, 5)
data['A'].hist()
plt.title("建築後年数")
plt.subplot(4, 2, 6)
data['RW'].hist()
plt.title("前面道路幅員")
plt.subplot(4, 2, 7)
data['TS'].hist()
plt.title("最寄駅までの距離")
plt.subplot(4, 2, 8)
data['TT'].hist()
plt.title(u"東京駅までの時間")
Out[21]:
<matplotlib.text.Text at 0x11a7ca7b8>
In [22]:
plt.figure(figsize=(20,8))
data['TDQ'].value_counts().plot(kind='bar')
Out[22]:
<matplotlib.axes._subplots.AxesSubplot at 0x1171cd898>
In [23]:
plt.figure(figsize=(20,8))
data['CITY_NAME'].value_counts().plot(kind='bar') #市区町村別の件数
Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x11ee65cc0>
In [24]:
def fml_build(varlst):
"""
Binding OLS formula from a list of variable names
varlst: variable names, the 1st var should be endogeneouse variable
"""
varlst.reverse()
fml=varlst.pop()+'~'
while len(varlst) != 0:
fml=fml+'+'+varlst.pop()
return fml
In [25]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR', 'FLR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data, return_type='dataframe')
logy = np.log(y)
model1 = sm.OLS(logy, X, intercept=True)
reg1 = model1.fit()
print(reg1.summary())
OLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.602
Model: OLS Adj. R-squared: 0.602
Method: Least Squares F-statistic: 8996.
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:56:03 Log-Likelihood: -5306.9
No. Observations: 77388 AIC: 1.064e+04
Df Residuals: 77374 BIC: 1.077e+04
Df Model: 13
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 8.7594 0.013 669.274 0.000 8.734 8.785
S 0.0056 4.27e-05 131.678 0.000 0.006 0.006
L 0.0028 3.79e-05 72.864 0.000 0.003 0.003
R -0.0236 0.001 -20.327 0.000 -0.026 -0.021
RW -0.0033 0.000 -6.800 0.000 -0.004 -0.002
A -0.0009 1.08e-05 -84.310 0.000 -0.001 -0.001
TS -0.0183 0.000 -91.348 0.000 -0.019 -0.018
TT -0.0076 0.000 -54.058 0.000 -0.008 -0.007
WOOD -0.1230 0.004 -35.086 0.000 -0.130 -0.116
SOUTH 0.0018 0.002 0.793 0.428 -0.003 0.006
CMD 0.0184 0.005 3.423 0.001 0.008 0.029
IDD -0.1846 0.003 -57.255 0.000 -0.191 -0.178
FAR -0.0032 0.000 -16.477 0.000 -0.004 -0.003
FLR -0.0007 2.08e-05 -33.350 0.000 -0.001 -0.001
==============================================================================
Omnibus: 3131.597 Durbin-Watson: 1.033
Prob(Omnibus): 0.000 Jarque-Bera (JB): 8525.057
Skew: -0.178 Prob(JB): 0.00
Kurtosis: 4.587 Cond. No. 3.52e+03
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The condition number is large, 3.52e+03. This might indicate that there are
strong multicollinearity or other numerical problems.
In [26]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data, return_type='dataframe')
CITY_NAME = pd.get_dummies(data['CITY_NAME'])
TDQ = pd.get_dummies(data['TDQ'])
X = pd.concat((X, CITY_NAME, TDQ), axis=1)
logy = np.log(y)
model2 = sm.OLS(logy, X, intercept=True)
reg2 = model2.fit()
print(reg2.summary())
OLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.826
Model: OLS Adj. R-squared: 0.826
Method: Least Squares F-statistic: 3834.
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:56:05 Log-Likelihood: 26824.
No. Observations: 77388 AIC: -5.345e+04
Df Residuals: 77291 BIC: -5.256e+04
Df Model: 96
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 7.8672 0.009 880.317 0.000 7.850 7.885
S 0.0040 2.9e-05 137.870 0.000 0.004 0.004
L 0.0034 2.53e-05 135.016 0.000 0.003 0.003
R 0.0060 0.001 7.565 0.000 0.004 0.008
RW 0.0068 0.000 21.114 0.000 0.006 0.007
A -0.0010 7.15e-06 -136.776 0.000 -0.001 -0.001
TS -0.0107 0.000 -75.508 0.000 -0.011 -0.010
TT -0.0065 0.000 -52.256 0.000 -0.007 -0.006
WOOD -0.0565 0.002 -23.918 0.000 -0.061 -0.052
SOUTH 0.0184 0.002 11.942 0.000 0.015 0.021
CMD -0.0145 0.004 -3.954 0.000 -0.022 -0.007
IDD -0.0593 0.002 -25.721 0.000 -0.064 -0.055
FAR -0.0018 0.000 -14.907 0.000 -0.002 -0.002
01千代田区 0.7349 0.029 25.202 0.000 0.678 0.792
02中央区 0.4068 0.022 18.403 0.000 0.364 0.450
03港区 0.8244 0.006 131.005 0.000 0.812 0.837
04新宿区 0.4376 0.004 103.745 0.000 0.429 0.446
05文京区 0.4841 0.005 96.169 0.000 0.474 0.494
06台東区 0.2134 0.009 24.025 0.000 0.196 0.231
07墨田区 0.1179 0.007 17.857 0.000 0.105 0.131
08江東区 0.1998 0.006 35.141 0.000 0.189 0.211
09品川区 0.4080 0.004 106.416 0.000 0.400 0.415
10目黒区 0.6447 0.003 186.897 0.000 0.638 0.651
11大田区 0.3387 0.003 125.218 0.000 0.333 0.344
12世田谷区 0.5562 0.003 204.934 0.000 0.551 0.562
13渋谷区 0.6848 0.005 146.939 0.000 0.676 0.694
14中野区 0.3682 0.003 109.599 0.000 0.362 0.375
15杉並区 0.4321 0.003 152.077 0.000 0.427 0.438
16豊島区 0.3273 0.004 81.568 0.000 0.319 0.335
17北区 0.1264 0.004 29.483 0.000 0.118 0.135
18荒川区 0.1037 0.006 17.745 0.000 0.092 0.115
19板橋区 0.1888 0.003 55.957 0.000 0.182 0.195
20練馬区 0.2770 0.003 86.821 0.000 0.271 0.283
21足立区 -0.0776 0.003 -26.304 0.000 -0.083 -0.072
22葛飾区 -0.0241 0.004 -6.814 0.000 -0.031 -0.017
23江戸川区 0.0942 0.004 26.155 0.000 0.087 0.101
200001 0.1396 0.006 23.697 0.000 0.128 0.151
200002 0.1554 0.006 25.861 0.000 0.144 0.167
200003 0.1273 0.006 20.367 0.000 0.115 0.140
200004 0.1421 0.005 26.658 0.000 0.132 0.153
200101 0.1341 0.005 24.787 0.000 0.123 0.145
200102 0.1322 0.005 24.321 0.000 0.122 0.143
200103 0.1162 0.005 21.525 0.000 0.106 0.127
200104 0.0931 0.005 19.471 0.000 0.084 0.102
200201 0.0828 0.005 15.241 0.000 0.072 0.093
200202 0.0765 0.005 14.149 0.000 0.066 0.087
200203 0.0769 0.006 13.141 0.000 0.065 0.088
200204 0.0715 0.005 14.875 0.000 0.062 0.081
200301 0.0612 0.006 10.438 0.000 0.050 0.073
200302 0.0605 0.006 10.695 0.000 0.049 0.072
200303 0.0566 0.006 8.757 0.000 0.044 0.069
200304 0.0616 0.005 12.035 0.000 0.052 0.072
200401 0.0570 0.006 10.222 0.000 0.046 0.068
200402 0.0660 0.005 13.196 0.000 0.056 0.076
200403 0.0681 0.005 14.838 0.000 0.059 0.077
200404 0.0853 0.004 20.260 0.000 0.077 0.094
200501 0.0901 0.004 20.897 0.000 0.082 0.099
200502 0.0907 0.004 20.882 0.000 0.082 0.099
200503 0.1135 0.004 25.784 0.000 0.105 0.122
200504 0.1346 0.004 34.310 0.000 0.127 0.142
200601 0.1369 0.004 31.529 0.000 0.128 0.145
200602 0.1704 0.004 41.786 0.000 0.162 0.178
200603 0.1842 0.004 41.431 0.000 0.175 0.193
200604 0.2096 0.004 52.289 0.000 0.202 0.217
200701 0.2242 0.004 50.550 0.000 0.215 0.233
200702 0.2519 0.004 56.825 0.000 0.243 0.261
200703 0.2680 0.004 59.648 0.000 0.259 0.277
200704 0.2680 0.004 62.147 0.000 0.260 0.276
200801 0.2391 0.005 49.357 0.000 0.230 0.249
200802 0.2244 0.005 49.566 0.000 0.215 0.233
200803 0.2214 0.005 46.401 0.000 0.212 0.231
200804 0.1732 0.005 37.663 0.000 0.164 0.182
200901 0.1302 0.005 26.510 0.000 0.121 0.140
200902 0.1229 0.004 27.330 0.000 0.114 0.132
200903 0.1183 0.005 24.500 0.000 0.109 0.128
200904 0.1323 0.005 25.021 0.000 0.122 0.143
201001 0.1266 0.006 22.617 0.000 0.116 0.138
201002 0.1344 0.005 24.771 0.000 0.124 0.145
201003 0.1331 0.005 24.248 0.000 0.122 0.144
201004 0.1330 0.005 26.630 0.000 0.123 0.143
201101 0.1142 0.005 20.962 0.000 0.104 0.125
201102 0.1296 0.005 24.746 0.000 0.119 0.140
201103 0.1287 0.006 23.378 0.000 0.118 0.139
201104 0.1030 0.004 27.525 0.000 0.096 0.110
201201 0.0879 0.005 18.128 0.000 0.078 0.097
201202 0.0780 0.005 16.430 0.000 0.069 0.087
201203 0.0732 0.005 15.114 0.000 0.064 0.083
201204 0.0829 0.004 20.073 0.000 0.075 0.091
201301 0.0677 0.005 12.436 0.000 0.057 0.078
201302 0.0774 0.005 15.919 0.000 0.068 0.087
201303 0.0806 0.005 15.403 0.000 0.070 0.091
201304 0.1000 0.005 21.740 0.000 0.091 0.109
201401 0.0980 0.005 17.895 0.000 0.087 0.109
201402 0.1173 0.005 22.223 0.000 0.107 0.128
201403 0.1131 0.005 21.708 0.000 0.103 0.123
201404 0.1175 0.004 26.611 0.000 0.109 0.126
201501 0.1139 0.004 25.736 0.000 0.105 0.123
201502 0.1359 0.004 34.703 0.000 0.128 0.144
201503 0.1530 0.007 21.788 0.000 0.139 0.167
==============================================================================
Omnibus: 7061.422 Durbin-Watson: 1.585
Prob(Omnibus): 0.000 Jarque-Bera (JB): 32917.594
Skew: -0.338 Prob(JB): 0.00
Kurtosis: 6.123 Cond. No. 5.28e+17
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 7.88e-27. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.
In [27]:
reg1.fvalue
Out[27]:
8996.2042653827066
In [28]:
reg2.fvalue
Out[28]:
3833.9161361682782
In [29]:
reg1.aic
Out[29]:
10641.747737480211
In [30]:
reg2.aic
Out[30]:
-53454.990898209217
In [31]:
reg1_n = len(reg1.params)
reg2_n = len(reg2.params)
In [32]:
reg1.f_test(np.identity(reg1_n))
Out[32]:
<class 'statsmodels.stats.contrast.ContrastResults'>
<F test: F=array([[ 6040199.7470554]]), p=0.0, df_denom=77374, df_num=14>
In [33]:
reg2.f_test(np.identity(reg2_n))
Out[33]:
<class 'statsmodels.stats.contrast.ContrastResults'>
<F test: F=array([[ 3015155.96012016]]), p=0.0, df_denom=77291, df_num=99>
In [34]:
plt.figure(figsize=(20,10))
plt.plot(data['A'], reg2.resid, 'o')
Out[34]:
[<matplotlib.lines.Line2D at 0x103202860>]
In [35]:
plt.figure(figsize=(20,10))
plt.plot(data['L'], reg2.resid, 'o')
Out[35]:
[<matplotlib.lines.Line2D at 0x117132a90>]
In [36]:
plt.figure(figsize=(20,10))
plt.plot(data['S'], reg2.resid, 'o')
Out[36]:
[<matplotlib.lines.Line2D at 0x11af61ef0>]
In [37]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data, return_type='dataframe')
CITY_NAME = pd.get_dummies(data['CITY_NAME'])
TDQ = pd.get_dummies(data['TDQ'])
X = pd.concat((X, CITY_NAME, TDQ), axis=1)
logy = np.log(y)
S = data['S'].values
model3 = sm.GLS(logy, X, intercept=True, sigma=1/S)
reg3 = model3.fit()
print(reg3.summary())
GLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.988
Model: GLS Adj. R-squared: 0.988
Method: Least Squares F-statistic: 6.403e+04
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:56:10 Log-Likelihood: 18660.
No. Observations: 77388 AIC: -3.713e+04
Df Residuals: 77291 BIC: -3.623e+04
Df Model: 96
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 8.0334 0.010 844.794 0.000 8.015 8.052
S 0.0030 2.38e-05 128.203 0.000 0.003 0.003
L 0.0034 2.27e-05 149.349 0.000 0.003 0.003
R 0.0050 0.001 6.791 0.000 0.004 0.006
RW 0.0082 0.000 23.962 0.000 0.007 0.009
A -0.0009 7.95e-06 -112.258 0.000 -0.001 -0.001
TS -0.0112 0.000 -72.922 0.000 -0.012 -0.011
TT -0.0071 0.000 -52.635 0.000 -0.007 -0.007
WOOD -0.0750 0.002 -32.034 0.000 -0.080 -0.070
SOUTH 0.0191 0.002 11.419 0.000 0.016 0.022
CMD -0.0170 0.004 -4.308 0.000 -0.025 -0.009
IDD -0.0665 0.003 -25.761 0.000 -0.072 -0.061
FAR -0.0022 0.000 -17.258 0.000 -0.002 -0.002
01千代田区 0.8176 0.026 31.774 0.000 0.767 0.868
02中央区 0.4520 0.022 20.614 0.000 0.409 0.495
03港区 0.8656 0.006 142.826 0.000 0.854 0.877
04新宿区 0.4400 0.004 99.285 0.000 0.431 0.449
05文京区 0.4982 0.005 95.393 0.000 0.488 0.508
06台東区 0.2023 0.009 21.423 0.000 0.184 0.221
07墨田区 0.1157 0.007 16.025 0.000 0.102 0.130
08江東区 0.1909 0.006 30.181 0.000 0.179 0.203
09品川区 0.4160 0.004 102.189 0.000 0.408 0.424
10目黒区 0.6676 0.003 194.987 0.000 0.661 0.674
11大田区 0.3394 0.003 121.166 0.000 0.334 0.345
12世田谷区 0.5681 0.003 205.996 0.000 0.563 0.574
13渋谷区 0.7338 0.005 155.275 0.000 0.725 0.743
14中野区 0.3621 0.004 100.973 0.000 0.355 0.369
15杉並区 0.4238 0.003 142.679 0.000 0.418 0.430
16豊島区 0.3238 0.004 74.464 0.000 0.315 0.332
17北区 0.1116 0.005 23.513 0.000 0.102 0.121
18荒川区 0.0990 0.006 15.307 0.000 0.086 0.112
19板橋区 0.1811 0.004 50.155 0.000 0.174 0.188
20練馬区 0.2684 0.003 79.280 0.000 0.262 0.275
21足立区 -0.0903 0.003 -28.808 0.000 -0.096 -0.084
22葛飾区 -0.0354 0.004 -9.180 0.000 -0.043 -0.028
23江戸川区 0.0823 0.004 21.134 0.000 0.075 0.090
200001 0.1355 0.006 21.507 0.000 0.123 0.148
200002 0.1534 0.006 23.859 0.000 0.141 0.166
200003 0.1152 0.007 17.323 0.000 0.102 0.128
200004 0.1333 0.006 23.335 0.000 0.122 0.145
200101 0.1348 0.006 23.203 0.000 0.123 0.146
200102 0.1260 0.006 21.595 0.000 0.115 0.137
200103 0.1093 0.006 18.933 0.000 0.098 0.121
200104 0.0897 0.005 17.582 0.000 0.080 0.100
200201 0.0810 0.006 13.818 0.000 0.069 0.092
200202 0.0744 0.006 12.806 0.000 0.063 0.086
200203 0.0774 0.006 12.449 0.000 0.065 0.090
200204 0.0648 0.005 12.704 0.000 0.055 0.075
200301 0.0509 0.006 8.257 0.000 0.039 0.063
200302 0.0536 0.006 8.795 0.000 0.042 0.066
200303 0.0567 0.007 8.175 0.000 0.043 0.070
200304 0.0485 0.005 8.913 0.000 0.038 0.059
200401 0.0549 0.006 9.192 0.000 0.043 0.067
200402 0.0629 0.005 11.597 0.000 0.052 0.074
200403 0.0606 0.005 12.352 0.000 0.051 0.070
200404 0.0852 0.005 18.783 0.000 0.076 0.094
200501 0.0926 0.005 19.675 0.000 0.083 0.102
200502 0.0823 0.005 17.563 0.000 0.073 0.091
200503 0.1139 0.005 23.885 0.000 0.105 0.123
200504 0.1386 0.004 32.926 0.000 0.130 0.147
200601 0.1403 0.005 29.966 0.000 0.131 0.150
200602 0.1817 0.004 41.461 0.000 0.173 0.190
200603 0.1967 0.005 40.556 0.000 0.187 0.206
200604 0.2233 0.004 51.658 0.000 0.215 0.232
200701 0.2334 0.005 48.598 0.000 0.224 0.243
200702 0.2668 0.005 55.264 0.000 0.257 0.276
200703 0.2878 0.005 59.729 0.000 0.278 0.297
200704 0.2861 0.005 61.491 0.000 0.277 0.295
200801 0.2454 0.005 46.256 0.000 0.235 0.256
200802 0.2385 0.005 48.996 0.000 0.229 0.248
200803 0.2304 0.005 44.204 0.000 0.220 0.241
200804 0.1792 0.005 35.594 0.000 0.169 0.189
200901 0.1328 0.005 24.225 0.000 0.122 0.144
200902 0.1255 0.005 25.109 0.000 0.116 0.135
200903 0.1192 0.005 22.545 0.000 0.109 0.130
200904 0.1326 0.006 22.539 0.000 0.121 0.144
201001 0.1344 0.006 22.039 0.000 0.122 0.146
201002 0.1403 0.006 23.644 0.000 0.129 0.152
201003 0.1367 0.006 22.601 0.000 0.125 0.149
201004 0.1352 0.006 24.456 0.000 0.124 0.146
201101 0.1196 0.006 19.905 0.000 0.108 0.131
201102 0.1316 0.006 22.829 0.000 0.120 0.143
201103 0.1354 0.006 22.174 0.000 0.123 0.147
201104 0.1071 0.004 25.644 0.000 0.099 0.115
201201 0.0922 0.005 16.981 0.000 0.082 0.103
201202 0.0795 0.005 15.060 0.000 0.069 0.090
201203 0.0767 0.005 14.438 0.000 0.066 0.087
201204 0.0878 0.005 19.306 0.000 0.079 0.097
201301 0.0746 0.006 12.469 0.000 0.063 0.086
201302 0.0774 0.005 14.517 0.000 0.067 0.088
201303 0.0836 0.006 14.405 0.000 0.072 0.095
201304 0.1047 0.005 20.615 0.000 0.095 0.115
201401 0.1068 0.006 17.617 0.000 0.095 0.119
201402 0.1270 0.006 21.911 0.000 0.116 0.138
201403 0.1216 0.006 21.207 0.000 0.110 0.133
201404 0.1249 0.005 25.725 0.000 0.115 0.134
201501 0.1189 0.005 24.474 0.000 0.109 0.128
201502 0.1424 0.004 32.805 0.000 0.134 0.151
201503 0.1597 0.008 20.674 0.000 0.145 0.175
==============================================================================
Omnibus: 12394.370 Durbin-Watson: 1.572
Prob(Omnibus): 0.000 Jarque-Bera (JB): 167928.025
Skew: -0.341 Prob(JB): 0.00
Kurtosis: 10.184 Cond. No. 1.07e+18
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 2.52e-25. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.
In [38]:
data01 = data[data['BLOCK'] == "01都心・城南"]
data02 = data[data['BLOCK'] == "02城西・城北"]
data03 = data[data['BLOCK'] == "03城東"]
In [39]:
# R のインスタンスを作る
r = pyper.R(use_pandas='True')
In [40]:
r.assign("data01", data01)
r("index_mean_01 <- tapply(data01$P, data01$TDQ, mean)")
r.assign("data02", data02)
r("index_mean_02 <- tapply(data02$P, data02$TDQ, mean)")
r.assign("data03", data03)
r("index_mean_03 <- tapply(data03$P, data03$TDQ, mean)")
Out[40]:
'try({index_mean_03 <- tapply(data03$P, data03$TDQ, mean)})\n'
In [41]:
r("index_mean_01 <- index_mean_01 / index_mean_01[1]")
r("index_mean_02 <- index_mean_02 / index_mean_02[1]")
r("index_mean_03 <- index_mean_03 / index_mean_03[1]")
r("index_mean <- cbind(index_mean_01, index_mean_02, index_mean_03)")
r("index_mean_ts <- ts(index_mean, start = 2000, end = 2015.5, freq = 4)")
Out[41]:
'try({index_mean_ts <- ts(index_mean, start = 2000, end = 2015.5, freq = 4)})\n'
In [42]:
index_mean = r.get("index_mean")
In [44]:
plt.figure(figsize=(20,12))
plt.plot(index_mean)
plt.xticks(np.arange(0, len(index_mean), 1), np.arange(0, 15.5, 0.1))
plt.show()
In [45]:
white = reg2.HC0_se
print(white)
Intercept 0.010599
S 0.000059
L 0.000044
R 0.001211
RW 0.000371
A 0.000010
TS 0.000147
TT 0.000130
WOOD 0.002972
SOUTH 0.001580
CMD 0.003723
IDD 0.002111
FAR 0.000136
01千代田区 0.051589
02中央区 0.037495
03港区 0.010650
04新宿区 0.004786
05文京区 0.005755
06台東区 0.011093
07墨田区 0.006732
08江東区 0.006118
09品川区 0.004674
10目黒区 0.004754
11大田区 0.003643
12世田谷区 0.003646
13渋谷区 0.007320
14中野区 0.003694
15杉並区 0.003561
16豊島区 0.004166
17北区 0.004736
...
200802 0.004594
200803 0.004705
200804 0.004612
200901 0.004282
200902 0.004106
200903 0.005091
200904 0.005225
201001 0.005817
201002 0.005262
201003 0.005192
201004 0.004327
201101 0.005413
201102 0.005180
201103 0.005118
201104 0.003393
201201 0.004584
201202 0.004319
201203 0.004926
201204 0.003976
201301 0.005181
201302 0.004585
201303 0.004980
201304 0.004558
201401 0.005172
201402 0.005400
201403 0.004877
201404 0.004302
201501 0.004178
201502 0.003764
201503 0.006940
dtype: float64
In [46]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data01, return_type='dataframe')
CITY_NAME = pd.get_dummies(data01['CITY_NAME'])
TDQ = pd.get_dummies(data01['TDQ'])
X = pd.concat((X, CITY_NAME, TDQ), axis=1)
logy = np.log(y)
hed01_model = sm.OLS(logy, X, intercept=True)
hed01 = hed01_model.fit()
print(hed01.summary())
OLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.779
Model: OLS Adj. R-squared: 0.778
Method: Least Squares F-statistic: 1263.
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:56:59 Log-Likelihood: 6279.5
No. Observations: 29451 AIC: -1.239e+04
Df Residuals: 29368 BIC: -1.170e+04
Df Model: 82
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 7.7893 0.016 489.396 0.000 7.758 7.821
S 0.0040 4.57e-05 88.522 0.000 0.004 0.004
L 0.0033 4.3e-05 76.523 0.000 0.003 0.003
R -0.0006 0.001 -0.442 0.658 -0.003 0.002
RW 0.0112 0.001 17.845 0.000 0.010 0.012
A -0.0007 1.33e-05 -56.226 0.000 -0.001 -0.001
TS -0.0103 0.000 -36.812 0.000 -0.011 -0.010
TT -0.0076 0.000 -29.490 0.000 -0.008 -0.007
WOOD -0.0647 0.003 -18.536 0.000 -0.071 -0.058
SOUTH 0.0189 0.003 6.441 0.000 0.013 0.025
CMD 0.0075 0.007 1.028 0.304 -0.007 0.022
IDD -0.1119 0.005 -24.674 0.000 -0.121 -0.103
FAR -0.0051 0.000 -21.854 0.000 -0.006 -0.005
01千代田区 1.0640 0.032 33.660 0.000 1.002 1.126
02中央区 0.7157 0.024 29.562 0.000 0.668 0.763
03港区 1.1219 0.008 140.268 0.000 1.106 1.138
04新宿区 0.7451 0.006 115.406 0.000 0.732 0.758
09品川区 0.7156 0.006 119.150 0.000 0.704 0.727
10目黒区 0.9468 0.006 153.032 0.000 0.935 0.959
11大田区 0.6454 0.006 115.996 0.000 0.635 0.656
12世田谷区 0.8481 0.006 136.153 0.000 0.836 0.860
13渋谷区 0.9867 0.007 145.349 0.000 0.973 1.000
200001 0.0974 0.010 10.050 0.000 0.078 0.116
200002 0.1201 0.009 12.821 0.000 0.102 0.138
200003 0.0939 0.010 9.543 0.000 0.075 0.113
200004 0.1157 0.009 13.069 0.000 0.098 0.133
200101 0.0932 0.009 10.036 0.000 0.075 0.111
200102 0.1017 0.010 10.658 0.000 0.083 0.120
200103 0.0919 0.009 9.992 0.000 0.074 0.110
200104 0.0654 0.008 8.474 0.000 0.050 0.081
200201 0.0540 0.009 6.004 0.000 0.036 0.072
200202 0.0557 0.009 6.452 0.000 0.039 0.073
200203 0.0479 0.009 5.066 0.000 0.029 0.066
200204 0.0542 0.007 7.298 0.000 0.040 0.069
200301 0.0531 0.009 5.699 0.000 0.035 0.071
200302 0.0457 0.009 5.162 0.000 0.028 0.063
200303 0.0359 0.010 3.431 0.001 0.015 0.056
200304 0.0392 0.008 4.746 0.000 0.023 0.055
200401 0.0443 0.010 4.621 0.000 0.026 0.063
200402 0.0699 0.008 8.502 0.000 0.054 0.086
200403 0.0563 0.007 7.915 0.000 0.042 0.070
200404 0.0719 0.007 10.833 0.000 0.059 0.085
200501 0.0818 0.007 11.159 0.000 0.067 0.096
200502 0.0751 0.007 10.401 0.000 0.061 0.089
200503 0.1233 0.008 16.434 0.000 0.109 0.138
200504 0.1373 0.007 19.733 0.000 0.124 0.151
200601 0.1383 0.008 17.379 0.000 0.123 0.154
200602 0.1835 0.007 25.494 0.000 0.169 0.198
200603 0.2090 0.008 25.765 0.000 0.193 0.225
200604 0.2415 0.008 31.805 0.000 0.227 0.256
200701 0.2534 0.008 30.380 0.000 0.237 0.270
200702 0.2965 0.008 36.114 0.000 0.280 0.313
200703 0.3151 0.008 38.456 0.000 0.299 0.331
200704 0.3045 0.008 37.612 0.000 0.289 0.320
200801 0.2547 0.010 26.345 0.000 0.236 0.274
200802 0.2506 0.008 30.349 0.000 0.234 0.267
200803 0.2600 0.009 28.714 0.000 0.242 0.278
200804 0.1833 0.009 20.702 0.000 0.166 0.201
200901 0.1100 0.010 11.353 0.000 0.091 0.129
200902 0.1228 0.009 14.199 0.000 0.106 0.140
200903 0.1304 0.009 14.088 0.000 0.112 0.149
200904 0.1355 0.011 12.038 0.000 0.113 0.158
201001 0.1661 0.012 14.253 0.000 0.143 0.189
201002 0.1484 0.012 12.873 0.000 0.126 0.171
201003 0.1394 0.011 12.250 0.000 0.117 0.162
201004 0.1337 0.011 12.636 0.000 0.113 0.154
201101 0.1201 0.012 10.339 0.000 0.097 0.143
201102 0.1155 0.012 9.943 0.000 0.093 0.138
201103 0.1546 0.012 12.923 0.000 0.131 0.178
201104 0.0887 0.008 11.359 0.000 0.073 0.104
201201 0.0770 0.011 7.179 0.000 0.056 0.098
201202 0.0608 0.010 6.062 0.000 0.041 0.080
201203 0.0884 0.010 8.839 0.000 0.069 0.108
201204 0.0759 0.008 9.167 0.000 0.060 0.092
201301 0.0638 0.011 5.647 0.000 0.042 0.086
201302 0.0621 0.010 5.980 0.000 0.042 0.082
201303 0.0595 0.011 5.491 0.000 0.038 0.081
201304 0.1164 0.009 12.284 0.000 0.098 0.135
201401 0.1051 0.012 8.867 0.000 0.082 0.128
201402 0.1262 0.011 11.282 0.000 0.104 0.148
201403 0.0840 0.011 7.491 0.000 0.062 0.106
201404 0.1333 0.009 14.201 0.000 0.115 0.152
201501 0.1275 0.011 11.415 0.000 0.106 0.149
201502 0.1660 0.009 18.006 0.000 0.148 0.184
201503 0.1628 0.013 12.561 0.000 0.137 0.188
==============================================================================
Omnibus: 1987.103 Durbin-Watson: 1.560
Prob(Omnibus): 0.000 Jarque-Bera (JB): 6973.740
Skew: -0.287 Prob(JB): 0.00
Kurtosis: 5.314 Cond. No. 9.53e+17
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 1.07e-27. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.
In [47]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data02, return_type='dataframe')
CITY_NAME = pd.get_dummies(data02['CITY_NAME'])
TDQ = pd.get_dummies(data02['TDQ'])
X = pd.concat((X, CITY_NAME, TDQ), axis=1)
logy = np.log(y)
hed02_model = sm.OLS(logy, X, intercept=True)
hed02 = hed02_model.fit()
print(hed02.summary())
OLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.762
Model: OLS Adj. R-squared: 0.761
Method: Least Squares F-statistic: 1277.
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:57:00 Log-Likelihood: 16370.
No. Observations: 32426 AIC: -3.258e+04
Df Residuals: 32344 BIC: -3.189e+04
Df Model: 81
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 7.1563 0.011 627.286 0.000 7.134 7.179
S 0.0037 4.43e-05 83.665 0.000 0.004 0.004
L 0.0035 3.55e-05 97.239 0.000 0.003 0.004
R 0.0149 0.001 13.793 0.000 0.013 0.017
RW 0.0047 0.000 9.803 0.000 0.004 0.006
A -0.0010 9.41e-06 -105.047 0.000 -0.001 -0.001
TS -0.0115 0.000 -57.780 0.000 -0.012 -0.011
TT -0.0058 0.000 -36.940 0.000 -0.006 -0.006
WOOD -0.0260 0.004 -6.961 0.000 -0.033 -0.019
SOUTH 0.0153 0.002 7.603 0.000 0.011 0.019
CMD -0.0454 0.005 -9.212 0.000 -0.055 -0.036
IDD -0.0629 0.004 -15.727 0.000 -0.071 -0.055
FAR -0.0001 0.000 -0.611 0.542 -0.000 0.000
05文京区 1.0807 0.004 260.091 0.000 1.073 1.089
06台東区 0.8159 0.007 112.057 0.000 0.802 0.830
14中野区 0.9545 0.003 310.989 0.000 0.948 0.961
15杉並区 1.0298 0.003 411.240 0.000 1.025 1.035
16豊島区 0.9149 0.003 269.277 0.000 0.908 0.922
17北区 0.7176 0.004 198.768 0.000 0.710 0.725
19板橋区 0.7750 0.003 228.199 0.000 0.768 0.782
20練馬区 0.8679 0.003 260.643 0.000 0.861 0.874
200001 0.1525 0.008 20.028 0.000 0.138 0.167
200002 0.1765 0.009 20.624 0.000 0.160 0.193
200003 0.1561 0.009 18.167 0.000 0.139 0.173
200004 0.1446 0.007 20.599 0.000 0.131 0.158
200101 0.1519 0.007 21.520 0.000 0.138 0.166
200102 0.1325 0.007 18.962 0.000 0.119 0.146
200103 0.1133 0.007 16.282 0.000 0.100 0.127
200104 0.0988 0.007 15.036 0.000 0.086 0.112
200201 0.0818 0.007 11.190 0.000 0.067 0.096
200202 0.0773 0.008 10.057 0.000 0.062 0.092
200203 0.0822 0.008 10.047 0.000 0.066 0.098
200204 0.0662 0.007 9.349 0.000 0.052 0.080
200301 0.0425 0.009 4.845 0.000 0.025 0.060
200302 0.0520 0.009 5.896 0.000 0.035 0.069
200303 0.0500 0.010 5.261 0.000 0.031 0.069
200304 0.0676 0.008 8.874 0.000 0.053 0.083
200401 0.0342 0.008 4.553 0.000 0.019 0.049
200402 0.0369 0.007 5.436 0.000 0.024 0.050
200403 0.0665 0.007 10.178 0.000 0.054 0.079
200404 0.0819 0.006 13.531 0.000 0.070 0.094
200501 0.0788 0.006 13.266 0.000 0.067 0.090
200502 0.0819 0.006 13.264 0.000 0.070 0.094
200503 0.0804 0.006 13.602 0.000 0.069 0.092
200504 0.1204 0.005 23.791 0.000 0.110 0.130
200601 0.1197 0.006 21.283 0.000 0.109 0.131
200602 0.1428 0.005 26.483 0.000 0.132 0.153
200603 0.1475 0.006 25.187 0.000 0.136 0.159
200604 0.1799 0.005 36.420 0.000 0.170 0.190
200701 0.1956 0.006 34.542 0.000 0.184 0.207
200702 0.2091 0.006 36.288 0.000 0.198 0.220
200703 0.2184 0.006 36.452 0.000 0.207 0.230
200704 0.2300 0.006 41.185 0.000 0.219 0.241
200801 0.2084 0.006 33.290 0.000 0.196 0.221
200802 0.1892 0.006 31.214 0.000 0.177 0.201
200803 0.1779 0.006 28.529 0.000 0.166 0.190
200804 0.1458 0.006 23.830 0.000 0.134 0.158
200901 0.1227 0.006 19.205 0.000 0.110 0.135
200902 0.1007 0.006 17.063 0.000 0.089 0.112
200903 0.0738 0.007 11.192 0.000 0.061 0.087
200904 0.1068 0.007 15.866 0.000 0.094 0.120
201001 0.0936 0.007 13.455 0.000 0.080 0.107
201002 0.1109 0.007 16.141 0.000 0.097 0.124
201003 0.1154 0.007 15.974 0.000 0.101 0.130
201004 0.1214 0.006 18.981 0.000 0.109 0.134
201101 0.1062 0.007 14.840 0.000 0.092 0.120
201102 0.1086 0.007 16.119 0.000 0.095 0.122
201103 0.1073 0.007 14.990 0.000 0.093 0.121
201104 0.1087 0.005 21.959 0.000 0.099 0.118
201201 0.0927 0.006 15.203 0.000 0.081 0.105
201202 0.0890 0.006 14.486 0.000 0.077 0.101
201203 0.0705 0.006 11.610 0.000 0.059 0.082
201204 0.0830 0.005 16.240 0.000 0.073 0.093
201301 0.0608 0.007 9.008 0.000 0.048 0.074
201302 0.0815 0.006 13.674 0.000 0.070 0.093
201303 0.0940 0.007 14.333 0.000 0.081 0.107
201304 0.0836 0.006 14.660 0.000 0.072 0.095
201401 0.0813 0.007 12.099 0.000 0.068 0.095
201402 0.1117 0.007 17.084 0.000 0.099 0.124
201403 0.1226 0.006 19.093 0.000 0.110 0.135
201404 0.1113 0.006 19.585 0.000 0.100 0.122
201501 0.1225 0.007 18.007 0.000 0.109 0.136
201502 0.1292 0.005 25.943 0.000 0.119 0.139
201503 0.1552 0.010 15.838 0.000 0.136 0.174
==============================================================================
Omnibus: 4349.234 Durbin-Watson: 1.653
Prob(Omnibus): 0.000 Jarque-Bera (JB): 21732.841
Skew: -0.559 Prob(JB): 0.00
Kurtosis: 6.852 Cond. No. 5.85e+17
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 2.54e-27. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.
In [48]:
vars = ['P', 'S', 'L', 'R', 'RW', 'A', 'TS', 'TT', 'WOOD', 'SOUTH', 'CMD', 'IDD', 'FAR']
eq = fml_build(vars)
y, X = dmatrices(eq, data=data03, return_type='dataframe')
CITY_NAME = pd.get_dummies(data03['CITY_NAME'])
TDQ = pd.get_dummies(data03['TDQ'])
X = pd.concat((X, CITY_NAME, TDQ), axis=1)
logy = np.log(y)
hed03_model = sm.OLS(logy, X, intercept=True)
hed03 = hed03_model.fit()
print(hed03.summary())
OLS Regression Results
==============================================================================
Dep. Variable: P R-squared: 0.702
Model: OLS Adj. R-squared: 0.701
Method: Least Squares F-statistic: 460.8
Date: Sat, 03 Dec 2016 Prob (F-statistic): 0.00
Time: 11:57:00 Log-Likelihood: 7893.5
No. Observations: 15511 AIC: -1.563e+04
Df Residuals: 15431 BIC: -1.502e+04
Df Model: 79
Covariance Type: nonrobust
==============================================================================
coef std err t P>|t| [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept 6.6433 0.015 430.813 0.000 6.613 6.673
S 0.0041 7e-05 58.407 0.000 0.004 0.004
L 0.0029 5.5e-05 52.739 0.000 0.003 0.003
R 0.0123 0.002 7.367 0.000 0.009 0.016
RW 0.0051 0.000 10.773 0.000 0.004 0.006
A -0.0014 1.44e-05 -99.149 0.000 -0.001 -0.001
TS -0.0093 0.000 -41.353 0.000 -0.010 -0.009
TT -0.0050 0.000 -22.702 0.000 -0.005 -0.005
WOOD -0.0674 0.007 -9.855 0.000 -0.081 -0.054
SOUTH 0.0242 0.003 8.422 0.000 0.019 0.030
CMD 0.0047 0.006 0.746 0.456 -0.008 0.017
IDD -0.0120 0.003 -3.758 0.000 -0.018 -0.006
FAR 0.0010 0.000 4.751 0.000 0.001 0.001
07墨田区 1.1152 0.006 182.377 0.000 1.103 1.127
08江東区 1.2328 0.005 267.969 0.000 1.224 1.242
18荒川区 1.1024 0.006 196.415 0.000 1.091 1.113
21足立区 0.9930 0.004 275.396 0.000 0.986 1.000
22葛飾区 1.0406 0.004 291.411 0.000 1.034 1.048
23江戸川区 1.1592 0.004 294.424 0.000 1.151 1.167
200001 0.2294 0.018 12.923 0.000 0.195 0.264
200002 0.2023 0.016 12.542 0.000 0.171 0.234
200003 0.1808 0.018 9.868 0.000 0.145 0.217
200004 0.1839 0.014 13.032 0.000 0.156 0.212
200101 0.1631 0.013 12.555 0.000 0.138 0.189
200102 0.1755 0.013 13.774 0.000 0.151 0.200
200103 0.1587 0.014 11.415 0.000 0.131 0.186
200104 0.1419 0.012 11.566 0.000 0.118 0.166
200201 0.1464 0.013 10.867 0.000 0.120 0.173
200202 0.1047 0.013 7.972 0.000 0.079 0.130
200203 0.1085 0.014 7.669 0.000 0.081 0.136
200204 0.1033 0.012 8.515 0.000 0.080 0.127
200301 0.0737 0.013 5.786 0.000 0.049 0.099
200302 0.0709 0.012 5.928 0.000 0.047 0.094
200303 0.0654 0.014 4.820 0.000 0.039 0.092
200304 0.0576 0.011 5.405 0.000 0.037 0.078
200401 0.0931 0.012 7.704 0.000 0.069 0.117
200402 0.0788 0.012 6.427 0.000 0.055 0.103
200403 0.0774 0.013 6.061 0.000 0.052 0.102
200404 0.0866 0.010 8.257 0.000 0.066 0.107
200501 0.0782 0.009 8.489 0.000 0.060 0.096
200502 0.0946 0.009 10.341 0.000 0.077 0.113
200503 0.0897 0.010 9.075 0.000 0.070 0.109
200504 0.0999 0.009 11.357 0.000 0.083 0.117
200601 0.1075 0.009 12.117 0.000 0.090 0.125
200602 0.1370 0.009 15.867 0.000 0.120 0.154
200603 0.1391 0.009 15.779 0.000 0.122 0.156
200604 0.1508 0.009 17.251 0.000 0.134 0.168
200701 0.1698 0.009 19.120 0.000 0.152 0.187
200702 0.1893 0.009 21.571 0.000 0.172 0.207
200703 0.2023 0.009 23.290 0.000 0.185 0.219
200704 0.2163 0.008 25.790 0.000 0.200 0.233
200801 0.2029 0.009 23.723 0.000 0.186 0.220
200802 0.1761 0.009 20.324 0.000 0.159 0.193
200803 0.1728 0.009 19.366 0.000 0.155 0.190
200804 0.1420 0.008 17.525 0.000 0.126 0.158
200901 0.1112 0.009 12.773 0.000 0.094 0.128
200902 0.0987 0.008 12.075 0.000 0.083 0.115
200903 0.1102 0.008 13.412 0.000 0.094 0.126
200904 0.1060 0.009 11.982 0.000 0.089 0.123
201001 0.0771 0.010 7.653 0.000 0.057 0.097
201002 0.0944 0.009 10.282 0.000 0.076 0.112
201003 0.0917 0.009 10.221 0.000 0.074 0.109
201004 0.0902 0.008 10.823 0.000 0.074 0.107
201101 0.0642 0.009 7.411 0.000 0.047 0.081
201102 0.1205 0.008 14.559 0.000 0.104 0.137
201103 0.0841 0.009 9.639 0.000 0.067 0.101
201104 0.0591 0.006 9.786 0.000 0.047 0.071
201201 0.0383 0.008 4.805 0.000 0.023 0.054
201202 0.0188 0.008 2.402 0.016 0.003 0.034
201203 0.0042 0.009 0.482 0.629 -0.013 0.021
201204 0.0276 0.008 3.479 0.001 0.012 0.043
201301 0.0294 0.010 2.981 0.003 0.010 0.049
201302 0.0290 0.009 3.333 0.001 0.012 0.046
201303 0.0218 0.009 2.340 0.019 0.004 0.040
201304 0.0530 0.008 6.288 0.000 0.036 0.069
201401 0.0649 0.010 6.741 0.000 0.046 0.084
201402 0.0473 0.009 5.065 0.000 0.029 0.066
201403 0.0661 0.009 7.243 0.000 0.048 0.084
201404 0.0516 0.007 7.083 0.000 0.037 0.066
201501 0.0532 0.005 9.726 0.000 0.042 0.064
201502 0.0707 0.006 11.762 0.000 0.059 0.083
201503 0.0898 0.012 7.342 0.000 0.066 0.114
==============================================================================
Omnibus: 1326.252 Durbin-Watson: 1.694
Prob(Omnibus): 0.000 Jarque-Bera (JB): 5204.772
Skew: -0.363 Prob(JB): 0.00
Kurtosis: 5.743 Cond. No. 3.12e+17
==============================================================================
Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 3.71e-27. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.
In [ ]:
r.assign("data", data)
In [ ]:
r("t <- sort(unique(data$TDQ))")
r("tt <- paste('factor(TDQ)', t, sep = "")")
In [ ]:
tt = r.get("tt")
TDQ_hd01 = hed01.params[1:(len(tt)+1)]
TDQ_hd02 = hed02.params[1:(len(tt)+1)]
TDQ_hd03 = hed03.params[1:(len(tt)+1)]
In [ ]:
index_hd_01 = np.exp(TDQ_hd01)
index_hd_02 = np.exp(TDQ_hd02)
index_hd_03 = np.exp(TDQ_hd03)
index_hd = np.array([index_hd_01, index_hd_02, index_hd_03])
plt.plot(index_hd.T)
In [ ]:
'''
par(mfrow = c(3, 1))
ts.plot(index_mean_ts[, 1], index_hd_ts[, 1], col = c("lightblue", "blue"), lwd = c(1, 1.5), main = "都心5区・城南地域")
ts.plot(index_mean_ts[, 2], index_hd_ts[, 2], col = c("pink", "red"), lwd = c(1, 1.5), main = "城西・城北地域")
ts.plot(index_mean_ts[, 3], index_hd_ts[, 3], col = c("lightgreen", "green"), lwd = c(1, 1.5), main = "城東地域")
par(mfrow = c(1, 1))
#Weight
volume01 <- tapply(data01$P, data01$TDQ, sum)
volume02 <- tapply(data02$P, data02$TDQ, sum)
volume03 <- tapply(data03$P, data03$TDQ, sum)
volume <- tapply(data$P, data$TDQ, sum)
weight01 <- volume01 / volume
weight02 <- volume02 / volume
weight03 <- volume03 / volume
weight <- cbind(weight01, weight02, weight03)
fixed_weight <- matrix(rep(weight[1, ], length(t)), ncol = 3, byrow = T)
#Las
index_laspeyres <- apply(index_hd * fixed_weight, 1, sum)
#Pache
index_paasche <- apply(index_hd^-1 * weight, 1, sum)^-1
#Fisher
index_fisher <- (index_laspeyres * index_paasche)^0.5
#Plot
composite_index <- cbind(index_laspeyres, index_paasche, index_fisher)
composite_index_ts <- ts(composite_index, start = 2000, end = 2015.5, freq = 4)
ts.plot(composite_index_ts, col = c("navy", "brown", "orange"))
ts.plot(index_hd_ts, composite_index_ts[, 1], col = c("blue", "red", "green", "navy"), lwd = c(1, 1, 1, 2))
ts.plot(index_hd_ts, composite_index_ts[, 1:2], col = c("blue", "red", "green", "navy", "brown"), lwd = c(1, 1, 1, 2, 2))
ts.plot(index_hd_ts, composite_index_ts[, 1:3], col = c("blue", "red", "green", "navy", "brown", "orange"), lwd = c(1, 1, 1, 2, 2, 3))
write.csv(weight, "output/08_weight.csv")
write.csv(index_hd, "output/09_index_hd.csv")
write.csv(composite_index, "output/10_composite_index.csv")'''
Content source: NlGG/Projects
Similar notebooks: