I have about 200 real numbers spread over the range 0-400. I use HistogramDistribution
to bin them and PDF
to create the resulting step-wise probability distribution. I assumed that CDF
applied to the HistogramDistribution
would yield a continuous, piece-wise linear function, but I keep getting these annoying gaps in the plot of the CDF.
Here's the code I'm using applied to some random data:
data = Table[400*RandomReal[], {200}];
pd = PDF[HistogramDistribution[data, 20]];
Plot[pd[x], {x, 0, 400}]
Plot[CDF[HistogramDistribution[data, 20], x], {x, 0, 400}]
Any idea what's causing the gaps and how to get rid of them?
PlotPoints -> 500
to your final Plot command. $\endgroup$Exclusions -> None
is the better approach in this case. $\endgroup$SmoothKernelDistribution
instead. This gives you a smooth curve for the density rather than a bumpy histogram. You can usePDF
andCDF
with the object produced bySmoothKernelDistribution
just likeHistogramDistribution
. $\endgroup$DiscretePlot[CDF[HistogramDistribution[data, 20], x], {x, 0, 400}, Filling -> None, Joined -> True]
generates this plot. As an aside, your data can be more efficiently generated using:data = RandomReal[{0, 400}, 200]
. $\endgroup$