Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scipy linear regression does not include `intercept_stderr` property

Tags:

python

scipy

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'
like image 771
Joseph Avatar asked Oct 28 '25 14:10

Joseph


1 Answers

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.

like image 87
Arya McCarthy Avatar answered Oct 30 '25 10:10

Arya McCarthy