2
$\begingroup$

For example, we have a list of values

data = RandomVariate[NormalDistribution[], 10^3];

then

SmoothHistogram[data]

By default plot the PDF of data like this

enter image description here

But there is also options to plot the Intensity of data using

SmoothHistogram[data, Automatic, "Intensity"]

which gives

enter image description here

This intensity curve is what I want. But I also want the function of this intensity curve, so I can to subtract two such intensity curve function to plot a new one.

I look into the doc, it seems that SmoothKernelDistribution suite the needs. For example, let

dist=SmoothKernelDistribution[data]

then

Plot[PDF[dist, {x}], {x, -3, 3}]

gives

enter image description here

Which is equivalent to SmoothHistogram[data]. But how to get equivalent Intensity plot using SmoothKernelDistribution? Is there a complete list of function that is supported by SmoothKernelDistribution like PDF?

$\endgroup$
4
$\begingroup$
Clear["Global`*"]

SeedRandom[0];
data = RandomVariate[NormalDistribution[], 10^3];

{xmin, xmax} = MinMax@data;

smhist = SmoothHistogram[data, Automatic, "Intensity"]

enter image description here

p[x_] = PDF[SmoothKernelDistribution[data], x];

The factor required to scale the PDF to the intensity curve is

amp = Divide @@
   ((Cases[#, Line[pts_] :> pts, Infinity][[1, All, 2]] // 
        Max) & /@
     {smhist, Plot[p[x], {x, xmin, xmax}]});

intensity[x_] = amp*p[x];

Plot[intensity[x], {x, xmin, xmax}]

enter image description here

EDIT: A more straightforward approach is to use the points from smhist to define an InterpolatingFunction.

int = Interpolation[Cases[smhist, Line[pts_] :> pts, Infinity][[1]]];

Plot[int[x], {x, xmin, xmax}]

enter image description here

$\endgroup$
  • $\begingroup$ Wow, powerful postprocessing. So there is no built in statistic function corresponding to "indensity"? $\endgroup$ – matheorem Apr 23 at 0:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.