I checked the documentation of scipy.stats.pearsonr but did not find any options to force intercept at origin 0,0.
If it's impossible with scipy.stats.pearsonr does anyone know any alternatives?
I checked the documentation of scipy.stats.pearsonr but did not find any options to force intercept at origin 0,0.
If it's impossible with scipy.stats.pearsonr does anyone know any alternatives?
The Pearson correlation coefficient has the property that you can add any number to either sample, or multiply either number by a non-negative number, and this won't change the calculated R score.
For example, if you compare a sample to the same sample plus 10, it still has a correlation of 1.0 with the original.
I assume what you're asking for is a version of Pearson's correlation coefficient where being wrong by a constant does matter. Scikit-learn has something similar to this.
Example:
In this example, being wrong by a constant does matter, and it gets a R^2 of 0.087.
You should be aware of four gotchas about this:
r2_score()function is affected by both scaling the sample and adding a constant. In other words,r2_score(a, a * 2)will be a score less than 1.0.pearsonr(), -1 does not mean that it is perfectly negatively correlated. Instead, a negative score means that it is worse than predicting the mean, and it can be infinitely negative, because it can be infinitely worse.r2_score(a, b)is not necessarily the same thing asr2_score(b, a).See the documentation for more.