Create Confidence Envelopes about Nonparametric Density Estimates
Use several bandwidth-selection methods to determine a proper bandwidth. Estimate a bootstrapped 95% pointwise confidence band for the kernel density estimate.
data = BlockRandom[SeedRandom[3];
RandomVariate[dist = MixtureDistribution[{1 / 2, 3, 1}, {NormalDistribution[-4, .4], NormalDistribution[0, 2], NormalDistribution[2.5, .6]}], 500]];𝒟 = SmoothKernelDistribution[data];
bSamp = RandomChoice[data, {250, Length[data]}];
Subscript[𝒟, B] = SmoothKernelDistribution[#]& /@ bSamp;pdf = Table[PDF[i, rng = Range[-7., 7, .05]], {i, Subscript[𝒟, B]}];
High = Table[Quantile[i, .975], {i, Transpose[pdf]}];
Low = Table[Quantile[i, .025], {i, Transpose[pdf]}];
p1 = Show[ListLinePlot[{Transpose[{rng, High}], Transpose[{rng, Low}]}, Filling -> {1 -> {{2}, Automatic}}, PlotRange -> {0, .25}, PlotStyle -> Dashed], Plot[PDF[𝒟, x], {x, -7, 7}, PlotStyle -> {Thick, Blue}, PlotRange -> {0, .25}], Frame -> True, Axes -> None, ImageSize -> 570];
dists2 = Table[SmoothKernelDistribution[data, i], {i, {"Oversmooth", "Silverman", "SheatherJones"}}];
p2 = Plot[Evaluate[PDF[#, x]& /@ dists2], {x, -8, 8}, Frame -> True, Axes -> None, ImageSize -> 570];
Grid[{{p2}, {p1}}]