forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregressions.py
50 lines (35 loc) · 1.2 KB
/
regressions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from datetime import datetime
import string
import numpy as np
from pandas.core.api import DataMatrix, DateRange
from pandas.stats.linmodel import LinearModel, XSLinearModel
N = 100
start = datetime(2009, 9, 2)
dateRange = DateRange(start, periods=N)
def makeDataMatrix():
data = DataMatrix(np.random.randn(N, 7),
columns=list(string.ascii_uppercase[:7]),
index=dateRange)
return data
#-------------------------------------------------------------------------------
# Standard rolling linear regression
data = makeDataMatrix()
model = LinearModel(data, window=100, minPeriods=80)
model.parseFormula('A ~ B + C + D + E + F + G + I')
model.fit()
# Extremely basic summary
model.summary(dateRange[-1])
print model.beta()
print model.rsquare()
print model.tstat()
#-------------------------------------------------------------------------------
# Panel regression
data = {
'A' : makeDataMatrix(),
'B' : makeDataMatrix(),
'C' : makeDataMatrix()
}
panelModel = XSLinearModel(data, window=50, minPeriods=20)
panelModel.parseFormula('A ~ B + C + I')
panelModel.fit()
# Same diagnostic statistics as per above