|
21 | 21 | reload(_pvar)
|
22 | 22 | from pandas.stats.var import VAR
|
23 | 23 |
|
24 |
| -try: |
25 |
| - import rpy2.robjects as robj |
26 |
| - from rpy2.robjects import r |
27 |
| - from rpy2.robjects.packages import importr |
28 |
| - import pandas.rpy.common as rpy |
29 |
| - vars = importr('vars') |
30 |
| - urca = importr('urca') |
31 |
| -except ImportError: |
32 |
| - pass |
33 |
| - |
34 | 24 | DECIMAL_6 = 6
|
35 | 25 | DECIMAL_5 = 5
|
36 | 26 | DECIMAL_4 = 4
|
@@ -99,97 +89,5 @@ def __init__(self):
|
99 | 89 | self.res2 = results_var.MacrodataResults()
|
100 | 90 |
|
101 | 91 |
|
102 |
| -class RVAR(object): |
103 |
| - """ |
104 |
| - Estimates VAR model using R vars package and rpy |
105 |
| - """ |
106 |
| - |
107 |
| - def __init__(self, data, p=1, type='both'): |
108 |
| - self.rdata = data |
109 |
| - self.p = p |
110 |
| - self.type = type |
111 |
| - |
112 |
| - self.pydata = rpy.convert_robj(data) |
113 |
| - self._estimate = None |
114 |
| - self.estimate() |
115 |
| - |
116 |
| - @property |
117 |
| - def aic(self): |
118 |
| - pass |
119 |
| - |
120 |
| - @property |
121 |
| - def bic(self): |
122 |
| - pass |
123 |
| - |
124 |
| - @property |
125 |
| - def beta(self): |
126 |
| - return rpy.convert_robj(r.coef(self._estimate)) |
127 |
| - |
128 |
| - def summary(self, equation=None): |
129 |
| - print(r.summary(self._estimate, equation=equation)) |
130 |
| - |
131 |
| - def output(self): |
132 |
| - print(self._estimate) |
133 |
| - |
134 |
| - def estimate(self): |
135 |
| - self._estimate = r.VAR(self.rdata, p=self.p, type=self.type) |
136 |
| - |
137 |
| - def plot(self, names=None): |
138 |
| - r.plot(model._estimate, names=names) |
139 |
| - |
140 |
| - def serial_test(self, lags_pt=16, type='PT.asymptotic'): |
141 |
| - f = r['serial.test'] |
142 |
| - |
143 |
| - test = f(self._estimate, **{'lags.pt': lags_pt, |
144 |
| - 'type': type}) |
145 |
| - |
146 |
| - return test |
147 |
| - |
148 |
| - def data_summary(self): |
149 |
| - print(r.summary(self.rdata)) |
150 |
| - |
151 |
| - |
152 |
| -class TestVAR(TestCase): |
153 |
| - |
154 |
| - def setUp(self): |
155 |
| - try: |
156 |
| - import rpy2 |
157 |
| - except ImportError: |
158 |
| - raise nose.SkipTest("No rpy2") |
159 |
| - |
160 |
| - self.rdata = rpy.load_data('Canada', package='vars', convert=False) |
161 |
| - self.data = rpy.load_data('Canada', package='vars', convert=True) |
162 |
| - |
163 |
| - self.res = VAR(self.data) |
164 |
| - self.ref = RVAR(self.rdata) |
165 |
| - |
166 |
| - def test_foo(self): |
167 |
| - pass |
168 |
| - |
169 | 92 | if __name__ == '__main__':
|
170 |
| - # canada = rpy.load_data('Canada', package='vars', convert=False) |
171 |
| - |
172 |
| - # model = RVAR(canada, p=1) |
173 |
| - |
174 |
| - # summary(Canada) |
175 |
| - |
176 |
| - # plot(Canada, nc=2, xlab="")ppp |
177 |
| - |
178 |
| - # adf1 <- summary(ur.df(Canada[, "prod"], type = "trend", lags = 2)) |
179 |
| - # adf1 |
180 |
| - |
181 |
| - # adf2 <- summary(ur.df(diff(Canada[, "prod"]), type = "drift", lags = 1)) |
182 |
| - # adf2 |
183 |
| - |
184 |
| - # VARselect(Canada, lag.max = 8, type = "both") |
185 |
| - |
186 |
| - # Canada <- Canada[, c("prod", "e", "U", "rw")] |
187 |
| - |
188 |
| - # p1ct <- VAR(Canada, p = 1, type = "both") |
189 |
| - # p1ct |
190 |
| - |
191 |
| - # coefs <- coef(p1ct) |
192 |
| - # class(coefs) |
193 |
| - |
194 |
| - # run_module_suite() |
195 | 93 | unittest.main()
|
0 commit comments