2
$\begingroup$

When I normalize the weights I use for fitting a line with weighted least squares, the parameters of the fitted line and the 'normal' standard errors stay exactly the same, as I would expect. The HC3 standard error estimates, however, change completely.

I get the feeling that I am missing something quite important here, but... well, I am missing it...

Here is some test code in Python:

import statsmodels.api as sm
import numpy as np

myData = np.array([1, 1, 2, 2, 3, 3, 4, 4], dtype=float)
myIndex = sm.add_constant(range(len(myData)))

myWeights = np.array([100,10,100,10,100,10,100,10], dtype=float)

fit1 = sm.WLS(myData, myIndex, weights=myWeights).fit()

print "Parameters: %s" % fit1.params
print "Normal standard errors: %s" % fit1.bse
print "HC3 estimates: %s" % fit1.HC3_se

# Normalise the weights
myWeights /= myWeights.sum()

fit2 = sm.WLS(myData, myIndex, weights=myWeights).fit()

print "Parameters: %s" % fit2.params
print "Normal standard errors: %s" % fit2.bse
print "HC3 estimates: %s" % fit2.HC3_se

Which produces:

Parameters: [ 0.9796748   0.49186992]
Normal standard errors: [ 0.09876738  0.02581648]
HC3 estimates: [ 0.00976334  0.00314918]
Parameters: [ 0.9796748   0.49186992]
Normal standard errors: [ 0.09876738  0.02581648]
HC3 estimates: [ 44.54587593   0.75750668]
$\endgroup$
3
  • $\begingroup$ This looks strange to me. Have you tried with some other data or software? I don't read python but I've tried to reproduce this result in R and cannot do so. $\endgroup$
    – KOE
    Jan 27, 2014 at 20:58
  • $\begingroup$ Stackoverflow won't let me post as an answer for some reason, but I cannot reproduce this with current master. What version of statsmodels are you using? $\endgroup$
    – jseabold
    Jan 28, 2014 at 13:30
  • $\begingroup$ This is not supported in statsmodels 0.5. HCCM matrices are only appropriate for OLS documentation for HCxxx statsmodels.sourceforge.net/stable/generated/… $\endgroup$
    – Josef
    Jan 28, 2014 at 15:31

1 Answer 1

1
$\begingroup$

Different browser let's me post an answer now...

What version are you using? I can't reproduce this with current master. Probably best to post these kinds of issues to github in the future.

https://github.com/statsmodels/statsmodels/issues

Parameters: [ 0.9796748   0.49186992]
Normal standard errors: [ 0.09876738  0.02581648]
HC3 estimates: [ 0.06187963  0.02651504]                                        
Parameters: [ 0.9796748   0.49186992]                                           
Normal standard errors: [ 0.09876738  0.02581648]                               
HC3 estimates: [ 0.06187963  0.02651504]  

Version

[~/]
[3]: sm.version.full_version
[3]: '0.6.0.dev-3396b98'
$\endgroup$
7
  • $\begingroup$ OK, thanks! I've got version 0.5.0. Seems like quite a serious bug if this is really it. Anyway, thanks again, I'll check! $\endgroup$
    – Tom
    Jan 28, 2014 at 14:56
  • $\begingroup$ Indeed, upgrading to '0.6.0.dev-c65f584' solves it. $\endgroup$
    – Tom
    Jan 28, 2014 at 15:26
  • $\begingroup$ From the docs "HCCM matrices are only appropriate for OLS." Granted, we should've at least raised a warning for use after WLS. We need to update the docs now that they're right for weights. $\endgroup$
    – jseabold
    Jan 28, 2014 at 15:32
  • $\begingroup$ Do you mean that HCx estimates actually do not work at all for WLS? Or just not in statsmodels 0.5.0? As in: the ones returned for the WLS fit in 0.6.0 do make sense?? $\endgroup$
    – Tom
    Jan 28, 2014 at 17:41
  • $\begingroup$ Just in statsmodels 0.5.0. The ones in the development branch should be correct, but I'd double-check yourself until there's an official release. They're almost certainly correct, but we need to do a bit more testing before the next release. $\endgroup$
    – jseabold
    Jan 29, 2014 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.