statsmodels/statsmodels — Issue #125: caching pinv_wexog broke iterative fit - GLSAR
Author: josef-pkt
Created: 2011-12-21 21:08:50+00:00
State: open
Labels: comp-regression, prio-high, type-bug

I'm writing a model that estimates the weight array
(heteroscedasticity) for weighted least squares.

I had initially a quick version, then I tried to follow the GLSAR
pattern, but GLSAR imitation never matched the numbers and looked
completely wrong, - excess caching.

before calling fit repeatedly with new weight matrices, we need to
delete the cached pinv_wexog, otherwise it is never recalculated

```
for i in range(maxiter-1):
if hasattr(self, 'pinv_wexog'):
del self.pinv_wexog
self.initialize()
results = self.fit()
```
using examples/example_glsar.py (which is also a refactoring victim)

```
for i in range(5):
print i, model3a.iterative_fit(i).params, model3a.rho

produces

0 [ 0.02263416] [ 0.62094476]
1 [ 0.02263416] [ 0.62094476]
2 [ 0.02263416] [ 0.62094476]
3 [ 0.02263416] [ 0.62094476]
4 [ 0.02263416] [ 0.62094476]
```
GLSAR currently does not update:

I had introduced the pinv_wexog cache to allow fitting of new
y's/endog (without recalculation) in the nipy style, but now we have
to be more careful if we want to fit with new wexog.

I'm working in my mixed branch on cleaning this up.