SampleData = RandomVariate[RayleighDistribution[3], 5000];
Histogram[SampleData]
This creates a histogram that (in my case) looks something like this:
I want to fit this histogram with a curve. The documentation of RandomVariate shows something similar to what I had in mind:
(However the blue line isn't actually a fitted curve; the documentation is simply plotting the [known] analytical formula.)
How can I fit the histogram? The obvious way is to use Interpolation
, but the naive attempt to Interpolation[Histogram[SampleData]]
doesn't work; Mathematica complains that the histogram is not a list of data and coordinates.
Edit: My raw data contains about 6000 points and looks like this:
This isn't what I'm trying to fit however; I want to fit the histogram, which looks like this:
Ideally the defined "NewFunction" would be able to take input such as NewFunction[3]
and return about 70. A normalized NewFunction would be even better.
SmoothKernelDistribution
, e.g.,Show[Histogram[SampleData, Automatic, PDF], Plot[Evaluate@PDF[SmoothKernelDistribution[SampleData]][x], {x, 0, 15}, PlotStyle -> Directive[Red, Thick]]]
? $\endgroup$NonlinearModelFit
, for example). With the large amount of data you have, usingSmoothKernelDistribution
as @kglr shows you is what you want. If you have a particular probability distribution in mind, then you should considerEstimatedDistribution
. $\endgroup$