Reputation: 13
I need to plot a QQ graph with the following information:
spcs2k = np.array([[ 49, 524, 16, 87, 157, 58, 4, 41, 110, 90, 2, 41, 136,
495, 249, 40, 48, 3, 72, 294, 49, 28, 163, 61, 89, 2,
168, 286, 23, 67, 19, 11, 63, 4, 246, 130, 2, 378, 176,
251, 78, 138, 97, 34, 33, 183, 12, 209, 82, 87, 9, 33,
19, 77, 54, 28, 59, 88, 202, 12, 53, 86, 146, 26, 112,
176, 35, 94, 180, 93, 8, 32, 26, 5, 145, 13, 5, 138,
205, 42, 17, 134, 19, 54, 133, 134, 10, 173, 3, 59, 223,
109, 175, 266, 314, 68, 283, 71, 77, 147, 32, 70, 131, 112,
32, 29, 19, 28, 85, 25, 57, 16, 130, 157, 13, 167, 29,
2, 442, 10, 150, 185, 95, 57, 63, 150, 41, 22, 72, 59,
2, 8, 5, 156, 51, 161, 243, 152, 289, 93, 34, 140, 74,
34, 37, 9, 121, 138, 94, 67, 65, 202, 67, 13, 240, 209,
2, 296, 6, 61, 2, 134, 196]])
import statsmodels.api as sm
import scipy.stats as stats
from matplotlib import pyplot as plt
fig = sm.qqplot(spcsk2,stats.expon,line="45")
plt.show()
and the idea is get a similar graph like this:
thanks for supporting me
Upvotes: 0
Views: 1222
Reputation: 63
Whoever has this problem should pass fit=True
to the sm.qqplot
method. This will auto-determine parameters such as loc, scale, and distargs. See docs here: https://www.statsmodels.org/dev/generated/statsmodels.graphics.gofplots.qqplot.html .
Upvotes: 2
Reputation: 65
The code works fine, it does what it should. QQ plot show if the data that you pass to it is normally distributed or not. In your case this means that the values are not even vaguely normally distributed in spcs2k.
If you run this code, you can see what it looks like on a dataset that came from normal distribution.
data = np.random.normal(0,1, 1000)
fig = sm.qqplot(data, line='45')
plt.show()
Upvotes: 1