Created
October 16, 2022 15:24
-
-
Save galenseilis/d2ffb4cfe4e05c6789870c4a676d8f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import stats | |
import matplotlib.pyplot as plt | |
import numpy as np | |
x = np.linspace(-1, 1, num=150) | |
y = 10*x + np.random.normal(size=x.size) | |
y[11:15] += 10 | |
y[-5:] -= 7 | |
res = stats.theilslopes(y, x, 0.90, method='separate') | |
lsq_res = stats.linregress(x, y) | |
fig = plt.figure() | |
ax = fig.add_subplot(111) | |
ax.plot(x, y, 'k.') | |
ax.plot(x, res[1] + res[0] * x, 'y-', label='Theil-Sen') | |
ax.plot(x, lsq_res[1] + lsq_res[0] * x, 'm-', label='Least Squares') | |
plt.legend() | |
plt.xlabel('X') | |
plt.ylabel('Y') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment