Reputation: 33
According to the docs, I can find the standard error of the regression by using the scale() class method on a RegressionResults instance.
However, I cannot obtain a RegressionResults instance.
This is what I did:
y = foo; X = bar
model = sm.OLS(y, X)
results = model.fit()
Looking into object type...
print type(results)
...returns a RegressionResultsWrapper
<class 'statsmodels.regression.linear_model.RegressionResultsWrapper'>
This "RegressionResultsWrapper" is undocumented, and I cannot find a way to manipulate it. results.scale() fails, and I cannot obtain the information I want.
Further, the docs state that .fit() is supposed to return a RegressionResults class instance, but what is returned is the RegressionResultsWrapper as seen above.
Any idea how I can obtain the information on the "standard error of the regression" for this regression model?
Upvotes: 2
Views: 3430
Reputation: 131580
This is Python's "duck typing" convention at work. When the documentation says that fit()
should return a RegressionResults
instance, it really means it will return something that is compatible with the public interface of RegressionResults
. Any of the documented attributes and methods of RegressionResults
should be accessible from the returned object, in accordance with how they are described in the documentation. And indeed that seems to be the case: if you access results.scale
, you will get a number. Note that it's not a method; it's an attribute. The error message you get when trying to call it as a method tells you that, if you missed it in the documentation.
It's true that technically they should say that the method returns something compatible with RegressionResults
rather than a RegressionResults
instance itself, but it's understood by most Python programmers that under normal circumstances, you shouldn't be actually checking the type of the objects you're given.
Upvotes: 2