AllenDowney / ThinkStats2

Text and supporting code for Think Stats, 2nd Edition
http://allendowney.github.io/ThinkStats2/
GNU General Public License v3.0
4.03k stars 11.31k forks source link

Unexpected PDF plot for exponential distribution #98

Closed gmrwvu closed 6 years ago

gmrwvu commented 6 years ago

When I plot a randomly generated exponential distribution, the CDF plots as expected but the PDF only plots as expected once the x value hits the rate. Before that is has a parabolic up trace. I am using Anaconda Python 2.7.17. Here is the code and the resulting graph import random import thinkstats2 import thinkplot sample = [random.expovariate(1.0/50) for i in range(500)] thinkplot.PrePlot(rows=1, cols=2) thinkplot.SubPlot(1) cdf = thinkstats2.Cdf(sample) thinkplot.Cdf(cdf) thinkplot.SubPlot(2) sample_pdf = thinkstats2.EstimatedPdf(sample) thinkplot.Pdf(sample_pdf) thinkplot.Show() expo_cdf_pdf Why is there an initial hook to the pdf? Am I doing something wrong?

AllenDowney commented 6 years ago

EstimatePdf uses KDE to approximate the PDF based on a sample. It's not a great idea, because the expo distribution is positive valued, and KDE doesn't know that. The result you got is consistent with what I would expect.

gmrwvu commented 6 years ago

Thanks