Skip to content

Commit ae63ebf

Browse files
committed
BUG: fix WLS r-squared to match statsmodels post 10/2012
1 parent 88c9ef5 commit ae63ebf

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ pandas 0.9.1
3131

3232
- Improve HTML display of DataFrame objects with hierarchical columns
3333

34+
**Bug fixes**
35+
36+
- Make WLS r-squared match statsmodels 0.5.0 fixed value
37+
3438
pandas 0.9.0
3539
============
3640

pandas/core/frame.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ def icol(self, i):
16471647
return self.reindex(columns=label)
16481648

16491649
values = self._data.iget(i)
1650-
return Series(values, index=self.index, name=label)
1650+
return Series.from_array(values, index=self.index, name=label)
16511651

16521652
def _ixs(self, i, axis=0):
16531653
if axis == 0:

pandas/stats/ols.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,10 @@ def _resid_stats(self):
970970
sst = []
971971
sse = []
972972

973+
Yreg = self._y
973974
Y = self._y_trans
974975
X = self._x_trans
976+
weights = self._weights
975977

976978
dates = self._index
977979
window = self._window
@@ -989,8 +991,16 @@ def _resid_stats(self):
989991

990992
resid = Y_slice - np.dot(X_slice, beta)
991993

994+
if weights is not None:
995+
Y_slice = _y_converter(Yreg.truncate(before=prior_date,
996+
after=date))
997+
weights_slice = weights.truncate(prior_date, date)
998+
demeaned = Y_slice - np.average(Y_slice, weights=weights_slice)
999+
SS_total = (weights_slice*demeaned**2).sum()
1000+
else:
1001+
SS_total = ((Y_slice - Y_slice.mean()) ** 2).sum()
1002+
9921003
SS_err = (resid ** 2).sum()
993-
SS_total = ((Y_slice - Y_slice.mean()) ** 2).sum()
9941004
SST_uncentered = (Y_slice ** 2).sum()
9951005

9961006
sse.append(SS_err)

pandas/stats/tests/test_ols.py

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def testOLSWithDatasets(self):
8181
# self.checkDataSet(datasets.ccard.load(), 39, 49) # one col in X all 0s
8282

8383
def testWLS(self):
84+
# WLS centered SS changed (fixed) in 0.5.0
85+
if sm.version.version < '0.5.0':
86+
raise nose.SkipTest
87+
8488
X = DataFrame(np.random.randn(30, 4), columns=['A', 'B', 'C', 'D'])
8589
Y = Series(np.random.randn(30))
8690
weights = X.std(1)

scripts/count_code.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
cloc pandas --force-lang=Python,pyx --not-match-f="tseries.c|sandbox.c|engines.c|sparse.c|generated.c|plib.c"
1+
cloc pandas --force-lang=Python,pyx --not-match-f="parser.c|tseries.c|sandbox.c|engines.c|sparse.c|generated.c|plib.c"

0 commit comments

Comments
 (0)