GPB
GPB

Reputation: 2495

Plot of normal curve not...normal

I am plotting both a distribution of test scores and a fitted curve to these test scores:

h = sorted(data['Baseline'])  #sorted
fit = stats.norm.pdf(h, np.mean(h), np.std(h))
plt.plot(h,fit,'-o')
plt.hist(h,normed=True)      #use this to draw histogram of your data
plt.show()

The plot of the pdf, however, does not look normal (see kink in curve near x=60). See output:

enter image description here

I'm not sure what is going on here...any help appreciated. Is this because the normal line is being drawn between supplied observations? Can provide you with the actual data if needed, there are only 60 observations.

Upvotes: 0

Views: 417

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339660

Yes, you evaluate the norm-pdf on the overservation. You would instead want to create some other data like

h = sorted(data['Baseline'])  #sorted
x = np.linspace(h.min(), h.max(), 151)

fit = stats.norm.pdf(x, np.mean(h), np.std(h))

plt.plot(x,fit,'-')
plt.hist(h,normed=True) 
plt.show()

Note however, that the data does not look normally distributed at all. So potentially you would rather fit a different distribution, or maybe perform a kernel density estimate.

Upvotes: 1

Related Questions