I'm trying to perform a linear regression on a set of two-dimensional points using scipy. As stated by the documentation here, the appropriate call is
regression_results = scipy.stats.linregress(x_values, y_values)
The documentation states that the regression_results object contains the following values: slope, intercept, rvalue, pvalue, stderr, intercept_stderr. All of these are present except the last.
These values are all present in the dict, but intercept_stderr is simply not. I cannot for the life of me fathom why. Here is the simple code I attempted to run:
from scipy import stats
# given two lists nmeq_x and nmeq_y... 
result = stats.linregress(nmeq_x, nmeq_y)
print(result.intercept, result.intercept_stderr)
I get the error:
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-7df9d260a3bb> in <module>
      1 result = stats.linregress(nmeq_x, nmeq_y)
----> 2 print(result.intercept, result.intercept_stderr)
AttributeError: 'LinregressResult' object has no attribute 'intercept_stderr'
This is about your scipy version; this feature was added in 1.6, released on 2020-12-31.
Note that the documentation says this:
For compatibility with older versions of SciPy, the return value acts like a namedtuple of length 5, with fields slope, intercept, rvalue, pvalue and stderr
You must have one of those older versions, then. The intercept_stderr field was added recently. Update you scipy to 1.6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With