({{, (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution])[{(Subscript[x, 1]),(Subscript[x, 2]),…}] 
represents a smooth kernel distribution based on the data values (Subscript[x, i]).}, {, (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution])[{{(Subscript[x, 1]),(Subscript[y, 1]),…},{(Subscript[x, 2]),(Subscript[y, 2]),…},…}]
represents a multivariate smooth kernel distribution based on the data values {(Subscript[x, i]),(Subscript[y, i]),…}.}, {, (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution])[…,bw]
represents a smooth kernel distribution with bandwidth bw.}, {, (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution])[…,bw,ker]
represents a smooth kernel distribution with bandwidth bw and smoothing kernel ker.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) returns a (RefLink[DataDistribution, paclet:ref/DataDistribution]) object that can be used like any other probability distribution.

The probability density function for (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) for a value x is given by a linearly interpolated version of (1/(n h))(∑_(i=1)^n)k(((x-(Subscript[x, i]))/h)) for a smoothing kernel k(x) and bandwidth parameter h.

The following bandwidth specifications bw can be given:

For multivariate densities, h can be a positive definite symmetric matrix.

For adaptive bandwidths, the sensitivity s must be a real number between 0 and 1 or (RefLink[Automatic, paclet:ref/Automatic]). If (RefLink[Automatic, paclet:ref/Automatic]) is used, s is set to 1/(2 p), where p is the dimensionality of the data.

Possible named bandwidth selection methods include:

By default, the "Silverman" method is used.

For automatic bandwidth computation, constant arrays are assumed to have unit variance.

The following kernel specifications ker can be given:

In order for (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) to generate a true density estimate, the function fn should be a valid probability density function.

By default, the "Gaussian" kernel is used.

The kernel function ker can be specified to account for known bounding on the underlying density using {"Bounded",c,ker}, where c can be any real number, a list {(Subscript[c, 1]),(Subscript[c, 2])} such that (Subscript[c, 1])<(Subscript[c, 2]), or a list {{(Subscript[c, 11]),(Subscript[c, 12])},{(Subscript[c, 21]),(Subscript[c, 22])},…}, with length equal to the dimension of data.

For multivariate densities, the kernel function ker can be specified as product and radial types using {"Product",ker} and {"Radial",ker}, respectively. Product-type kernels are used if no type is specified.

The precision used for density estimation is the minimum precision given in the bw and data.

The following options can be given:

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) can be used with such functions as (RefLink[Mean, paclet:ref/Mean]), (RefLink[CDF, paclet:ref/CDF]), and (RefLink[RandomVariate, paclet:ref/RandomVariate]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (92)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Create an interpolated version of a kernel density estimate for some univariate data:

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

𝒟=SmoothKernelDistribution[data];

Use the resulting distribution to perform analysis, including visualizing distribution functions:

Table[Plot[f[𝒟,x],{x,-4,4},PlotLabel->f],{f,{PDF,CDF}}]

Compute moments and quantiles:

Moment[𝒟,2]

Quantile[𝒟,0.95]

Create an interpolated version of a kernel density estimate of some bivariate data:

data=RandomVariate[BinormalDistribution[.75],10];

𝒟=SmoothKernelDistribution[data];

Visualize the estimated PDF and CDF:

Table[ContourPlot[f[𝒟,{x,y}],{x,-3,3},{y,-3,3},PlotLabel->f,PlotRange->All],{f,{PDF,CDF}}]

Compute covariance and general moments:

Covariance[𝒟]//MatrixForm

Moment[𝒟,{1,2}]

OpenersExampleSection1(Spacer1)Scope  (37)

OpenersExampleSubsection0(Spacer1)Basic Uses  (7)

Create an interpolated smooth density estimate for some data:

data=RandomVariate[NormalDistribution[],(10^4)];

𝒟=SmoothKernelDistribution[data];

Show[Histogram[data,Automatic,"PDF"],Plot[PDF[𝒟,x],{x,-4,4}]]

Compute probabilities from the distribution:

Probability[x>3,x\[Distributed]𝒟]

Create an interpolated version of a kernel density estimate for data with quantities:

data=QuantityArray[RandomVariate[NormalDistribution[1,2.5],10^4],"Meters"]

𝒟=SmoothKernelDistribution[data]

Find moments:

#[𝒟]&/@{Mean,Variance,Skewness,Kurtosis}

Increase the bandwidth for smoother estimates:

data=RandomVariate[NormalDistribution[],5];

bw={.1,.2,.5,1.0};

Table[Plot[PDF[SmoothKernelDistribution[data,i],x]//Evaluate,{x,-4,4},PlotLabel->Row[{"bandwidth = ",i}],PlotRange->{0,1.6},Filling->Axis],{i,bw}]

Allow the bandwidth to vary adaptively with local density:

data=RandomVariate[𝒹=MixtureDistribution[{1,2},{NormalDistribution[],NormalDistribution[2,1/2]}],(10^4)];

𝒟=SmoothKernelDistribution[data,{"Adaptive",Automatic,.5}];

Plot[{PDF[𝒹,x],PDF[𝒟,x]},{x,-4,4},PlotLegends->{"𝒹","𝒟"}]

Interpolate kernel density estimates in higher dimensions:

data=RandomVariate[NormalDistribution[],{10,3}];

𝒟=SmoothKernelDistribution[data,.5];

Plot the univariate marginal PDFs:

Table[Plot[Evaluate[PDF[MarginalDistribution[𝒟,i],x]],{x,-4,4},PlotLabel->i],{i,{1,2,3}}]

Plot the bivariate marginal PDFs:

Table[Plot3D[Evaluate[PDF[MarginalDistribution[𝒟,i],{x,y}]],{x,-4,4},{y,-4,4},PlotRange->All,PlotLabel->i],{i,Subsets[{1,2,3},{2}]}]

Select from built-in kernel functions or build a custom one:

data=RandomVariate[NormalDistribution[],100];

kerns={"Gaussian","Rectangular","Triangular"};

𝒟s=Table[SmoothKernelDistribution[data,Automatic,k],{k,kerns}];

MapThread[Plot[PDF[#1,x],{x,-4,4},Exclusions->None,PlotLabel->#2]&,{𝒟s,kerns}]

A custom kernel function:

𝒟custom=SmoothKernelDistribution[data,Automatic,PDF[NormalDistribution[],#]&];

Plot[PDF[𝒟custom,x],{x,-4,4}]

Specify radial- or product-type kernels for multivariate estimates:

data=RandomVariate[BinormalDistribution[2/5],250];

kernel=PDF[CauchyDistribution[0,1],#]&;

𝒟=Table[SmoothKernelDistribution[data,{{1,.25},{.25,1}},k],{k,{{"Radial",kernel},{"Product",kernel}}}];

Table[Plot3D[PDF[i,{x,y}]//Evaluate,{x,-5,5},{y,-5,5},PlotRange->All,Exclusions->None,MeshFunctions->(#3&)],{i,𝒟}]

OpenersExampleSubsection1(Spacer1)Distribution Properties  (8)

Estimate distribution functions:

𝒟=SmoothKernelDistribution[RandomVariate[NormalDistribution[],1000]];

Table[Plot[f[𝒟,x],{x,-4,4},Filling->Axis,PlotLabel->f,Exclusions->None],{f,{PDF,CDF,HazardFunction,SurvivalFunction}}]

Compute moments of the distribution:

𝒟=SmoothKernelDistribution[RandomReal[NormalDistribution[],1000]];

Special moments:

{Mean[𝒟],Variance[𝒟],Skewness[𝒟],Kurtosis[𝒟]}

General moments:

Table[Moment[𝒟,k],{k,4}]

Table[CentralMoment[𝒟,k],{k,4}]

Table[Cumulant[𝒟,k],{k,4}]

Table[FactorialMoment[𝒟,k],{k,4}]

Quantile function:

𝒟=SmoothKernelDistribution[RandomReal[NormalDistribution[],1000]];

Plot[Quantile[𝒟,p],{p,0,1},Filling->Axis,Exclusions->None]

Special quantile values:

Quartiles[𝒟]

InterquartileRange[𝒟]

Quantile[𝒟,{0.05,0.95}]

Median[𝒟]

Generate random numbers:

𝒟=SmoothKernelDistribution[RandomVariate[NormalDistribution[],1000]];

RandomVariate[𝒟,10]

Compare with (RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]):

Show[Histogram[RandomVariate[𝒟,(10^4)],Automatic,"PDF"],
Plot[PDF[𝒟,x],{x,-4,4}]]

Compute probabilities and expectations:

data= RandomReal[NormalDistribution[],1000];

𝒟=SmoothKernelDistribution[data];

NProbability[x>2,x\[Distributed]𝒟]

NExpectation[x^2+3x +5,x\[Distributed]𝒟]

Estimate bivariate distribution functions:

𝒟=SmoothKernelDistribution[RandomVariate[BinormalDistribution[.75],100]];

Table[DiscretePlot3D[Evaluate[f[𝒟,{x,y}]],{x,-4,4,.5},{y,-4,4,.5},PlotLabel->f,
ExtentSize->1/2],{f,{PDF,CDF,HazardFunction,SurvivalFunction}}]

Compute moments of a bivariate distribution:

𝒟=SmoothKernelDistribution[RandomReal[BinormalDistribution[.75],1000]];

Special moments:

{Mean[𝒟],Variance[𝒟]}

Covariance[𝒟]//MatrixForm

Correlation[𝒟]//MatrixForm

General moments:

Moment[𝒟,{1,2}]

CentralMoment[𝒟,{1,2}]

Cumulant[𝒟,{1,2}]

FactorialMoment[𝒟,{1,2}]

Generate random numbers:

𝒟=SmoothKernelDistribution[RandomReal[BinormalDistribution[.5],10^2]];

RandomVariate[𝒟,6]

Show the point distribution:

ListPlot[RandomVariate[𝒟,(10^4)],PlotRange->{{-4,4},{-4,4}}]

OpenersExampleSubsection2(Spacer1)Bandwidth Selection  (12)

Automatically select the bandwidth to use:

data1=RandomVariate[𝒹=NormalDistribution[],10];
data2=RandomVariate[𝒹,10^4];

𝒟1=SmoothKernelDistribution[data1];
𝒟2=SmoothKernelDistribution[data2];

More data yields better approximations to the underlying distribution:

Table[Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Explicitly specify the bandwidth to use:

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

Use bandwidths of 0.1 and 1:

𝒟1=SmoothKernelDistribution[data,0.1];
𝒟2=SmoothKernelDistribution[data,1.0];

Larger bandwidths yield smoother estimates:

Table[Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Specify bandwidths in units of standard deviation:

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

Use bandwidths of (1/2) and (1/8) the standard deviation:

𝒟1=SmoothKernelDistribution[data,{"Standardized",1/2}];
𝒟2=SmoothKernelDistribution[data,{"Standardized",1/8}];

Table[Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Allow the bandwidth to vary adaptively with local density:

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

Vary the local sensitivity from 0 (none) to 1 (full):

Table[Plot[Evaluate[PDF[SmoothKernelDistribution[data,{"Adaptive",Automatic,s}],x]],{x,-4,4},PlotLabel->Row[{"s = ",s}]],{s,{0,.25,.75,1}}]

Vary the initial bandwidth for an adaptive estimate:

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

Specify an initial bandwidth of 1.0 and 0.1, respectively:

𝒟1=SmoothKernelDistribution[data,{"Adaptive",1.0,.5}];
𝒟2=SmoothKernelDistribution[data,{"Adaptive",0.1,.5}];

Table[Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Use any of several automatic bandwidth selection methods:

data=RandomVariate[NormalDistribution[],100];

Table[Plot[Evaluate[PDF[SmoothKernelDistribution[data,name],x]],{x,-4,4},Filling->Axis,Exclusions->None,PlotLabel->name],{name,{"LeastSquaresCrossValidation","Oversmooth","Scott","SheatherJones","StandardDeviation","StandardGaussian"}}]

Silverman's method is used by default:

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

𝒟1=SmoothKernelDistribution[data,"Silverman"];
𝒟2=SmoothKernelDistribution[data,Automatic];

The PDFs are equivalent:

Table[Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

By default, Silverman's method is used to independently select bandwidths in each dimension:

data=RandomVariate[BinormalDistribution[.75],25];

Table[Plot3D[Evaluate[PDF[SmoothKernelDistribution[data,name],{x,y}]],{x,-3,3},{y,-3,3},PlotRange->All,PlotLabel->name,Exclusions->None],{name,{Automatic,"Silverman"}}]

Any automated method can be used to independently select diagonal bandwidth elements:

data=RandomVariate[BinormalDistribution[.75],25];

Table[Plot3D[Evaluate[PDF[SmoothKernelDistribution[data,name],{x,y}]],{x,-3,3},{y,-3,3},PlotRange->All,PlotLabel->name,Exclusions->None],{name,{"LeastSquaresCrossValidation","Oversmooth","Scott","SheatherJones","StandardDeviation","StandardGaussian"}}]

Methods used to estimate the bandwidth diagonal need not be the same:

BlockRandom[SeedRandom[6];data=RandomVariate[NormalDistribution[],{10,3}]];

Use adaptive, oversmoothed, and constant bandwidths in the respective dimensions:

𝒟=SmoothKernelDistribution[data,{{"Adaptive",.05,1},"Silverman",2}];

Plot the univariate marginal PDFs:

Table[Plot[Evaluate[PDF[MarginalDistribution[𝒟,i],x]],{x,-4,4},PlotRange->All,PlotLabel->i],{i,{1,2,3}}]

Give a scalar value to use the same bandwidth in all dimensions:

data=RandomVariate[BinormalDistribution[.75],25];

bands={.25,.5,1.0};

Table[Plot3D[Evaluate[PDF[SmoothKernelDistribution[data,bw],{x,y}]],{x,-3,3},{y,-3,3},PlotRange->All,PlotLabel->Row[{"bandwidth = ",bw*IdentityMatrix[2]}],Exclusions->None],{bw,bands}]

To use nonzero off-diagonal elements, give a fully specified bandwidth matrix:

bw={{1/2,1/4},{1/4,1/2}};

𝒟=SmoothKernelDistribution[RandomVariate[NormalDistribution[],{100,2}],bw];

ContourPlot[Evaluate[PDF[𝒟,{x,y}]],{x,-3,3},{y,-3,3},PlotRange->All]

OpenersExampleSubsection3(Spacer1)Kernel Functions  (6)

Specify any one of several kernel functions:

data=RandomVariate[NormalDistribution[],100];

Table[Plot[Evaluate[PDF[SmoothKernelDistribution[data,Automatic,i],x]],{x,-4,4},Filling->Axis,Ticks->None,PlotLabel->i,Exclusions->None],{i,{"Biweight","Cosine","Epanechnikov","Gaussian","Rectangular","SemiCircle","Triangular","Triweight"}}]

Define the kernel function as a pure function:

data=RandomVariate[NormalDistribution[],10];

𝒟1=SmoothKernelDistribution[data,Automatic];
𝒟2=SmoothKernelDistribution[data,Automatic,(1/(π (1+((#1)^2))))&];

Table[Plot[Evaluate[PDF[𝒟,x]],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

By default, the Gaussian kernel is used:

data=RandomVariate[NormalDistribution[],10];

𝒟1=SmoothKernelDistribution[data,Automatic];
𝒟2=SmoothKernelDistribution[data,Automatic,"Gaussian"];

Table[Plot[Evaluate[PDF[𝒟,x]],{x,-4,4},Filling->Axis,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

This is equivalent to using the PDF of a (RefLink[NormalDistribution, paclet:ref/NormalDistribution])[0,1]:

𝒟3=SmoothKernelDistribution[data,Automatic,PDF[NormalDistribution[],#]&];

Plot[PDF[𝒟3,x],{x,-4,4},Filling->Axis,Exclusions->None]

Shapes of some univariate kernel functions:

kernels={"Biweight","Cosine","Epanechnikov","Gaussian","Rectangular","SemiCircle","Triangular","Custom"};

dists=Table[SmoothKernelDistribution[{0},1,i],{i,(kernels/.{"Custom"->(PDF[CauchyDistribution[0,1],#]&)})}];

Table[Plot[Evaluate[PDF[dists[[i]],x]],{x,-3,3},PlotRange->All,PlotLabel->kernels[[i]],Filling->Axis,Ticks->None],{i,Length[kernels]}]

Specify any one of several kernel functions for multivariate data:

data=RandomVariate[BinormalDistribution[.75],10];

Table[Plot3D[Evaluate[PDF[SmoothKernelDistribution[data,Automatic,i],{x,y}]],{x,-4,4},{y,-4,4},Ticks->None,PlotLabel->i,PlotRange->All,MeshFunctions->(#3&)],{i,{"Biweight","Cosine","Epanechnikov","Gaussian","Rectangular","SemiCircle","Triangular","Triweight"}}]

Choose between product- and radial-type kernel functions for multivariate data:

data={{0,0}};

kerns={{"Product","Biweight"},{"Radial","Biweight"}};

Table[Plot3D[Evaluate[PDF[ SmoothKernelDistribution[data,1,i],{x,y}]],{x,-1.5,1.5},{y,-1.5,1.5},Ticks->None,PlotLabel->i,PlotRange->All,MeshFunctions->(#3 &),Boxed->False],{i,kerns}]

OpenersExampleSubsection4(Spacer1)Estimation with Fixed Domain  (4)

Use bounding to stay within the domain:

data=RandomVariate[BetaDistribution[2,3],10^4];

Define the smooth kernel distribution with a Gaussian kernel:

𝒟1=SmoothKernelDistribution[data,Automatic,"Gaussian"];

The support for PDF extends beyond the data support:

Plot[PDF[𝒟1,x]//Evaluate,{x,-0.1,1.1}]

Impose bounds:

𝒟2=SmoothKernelDistribution[data,Automatic,{"Bounded",{0,1},"Gaussian"}];

Plot[PDF[𝒟2,x]//Evaluate,{x,-.1,1.1}]

Compare to the original (RefLink[BetaDistribution, paclet:ref/BetaDistribution]):

Plot[{PDF[𝒟2,x],PDF[BetaDistribution[2,3],x]}//Evaluate,{x,-.1,1.1},PlotLegends->{"Bounded smooth kernel density estimate","Beta distribution density"}]

Compare smooth kernel distributions with a bounded Epanechnikov kernel:

sample=RandomReal[{-8,8},512];

skd[c_]:=SmoothKernelDistribution[sample,.25,{"Bounded",{-c,c},"Epanechnikov"}]

Table[Plot[Evaluate[PDF[skd[c],x]],{x,-10,10},Filling->Axis,PlotRange->{0,.2},PlotLabel->{-c,c}],{c,{∞,8}}]

The bounded smooth kernel density estimate is more accurate at the boundaries:

QuantilePlot[{skd[Infinity],skd[8]},UniformDistribution[{-8,8}],PlotRange->{{-8.5,-5},{-8.5,-5}},PlotLegends->{"Unbounded","Bounded to (-8,8)"}]

Use a bounded cosine kernel for two-dimensional data:

cpd=CopulaDistribution[{"Binormal",.75},{TriangularDistribution[{0,1}],WignerSemicircleDistribution[1]}];

data=RandomVariate[cpd,10^4];

skd=SmoothKernelDistribution[data,.2,{"Bounded",{{0,1},{-1,1}},"Cosine"}]

Compare the estimated density to the population distribution density:

Table[Plot3D[pdf,{x,-0.5,1.5},{y,-1.5,1.5},PlotRange->All,AxesLabel->Automatic,ImageSize->220,PlotTheme->"CoolColors",Exclusions->{{(1-y^2),0<x<1},{x(1-x)==0,-1<y<1}}],{pdf,{PDF[skd,{x,y}],PDF[cpd,{x,y}]}}]

Bounded Gaussian kernel:

data=RandomReal[{-3,5},10^3];

𝒟=SmoothKernelDistribution[data,.5,{"Bounded",{-3,5},"Gaussian"}];

Truncating the ordinary smooth kernel distribution yields a different result:

𝒟2=TruncatedDistribution[{-3,5},SmoothKernelDistribution[data,.5,"Gaussian"]];

Plot[{PDF[𝒟,x],PDF[𝒟2,x]}//Evaluate,{x,-4,6},PlotLegends->{"Bounded","Truncated"}]

OpenersExampleSection2(Spacer1)Options  (25)

OpenersExampleSubsection5(Spacer1)InterpolationPoints  (6)

By default, nonuniform interpolation is used to create a smooth estimate:

data=RandomVariate[𝒹=CauchyDistribution[0,1],10^3];

𝒟=SmoothKernelDistribution[data,InterpolationPoints->Automatic];

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-10,10},PlotRange->All,PlotLegends->{"𝒟","𝒹"}]

Specify the initial number of sample points to use:

data=RandomVariate[NormalDistribution[],10];

Use 4 interpolation points:

𝒟=SmoothKernelDistribution[data,InterpolationPoints->4];

Plot[PDF[𝒟,x],{x,-6,6},Filling->Axis,PlotRange->All]

A larger number of points yields a smoother estimate:

data=RandomVariate[NormalDistribution[],10];

estimates=Table[SmoothKernelDistribution[data,InterpolationPoints->i,MaxRecursion->3],{i,{2,4,6,8}}];

Table[Plot[PDF[i,x],{x,-4,4},Filling->Axis],{i,estimates}]

Specify the number of interpolating points to use for bivariate data:

data=RandomVariate[BinormalDistribution[.8],100];

Use 5 and 50 interpolation points in each dimension:

estimates=Table[SmoothKernelDistribution[data,InterpolationPoints->i],{i,{5,50}}];

Table[ContourPlot[PDF[i,{x,y}]//Evaluate,{x,-3,3},{y,-3,3},PlotRange->All],{i,estimates}]

Use different numbers of interpolation points in each dimension:

data=RandomVariate[BinormalDistribution[.8],100];

Specify 3 and 30 points or 30 and 3:

estimates=Table[SmoothKernelDistribution[data,InterpolationPoints->i,MaxRecursion->3],{i,{{3,30},{30,3}}}];

Table[ContourPlot[PDF[i,{x,y}]//Evaluate,{x,-4,4},{y,-4,4},PlotRange->All],{i,estimates}]

A smooth result does not imply a high-quality estimate:

𝒟h=HistogramDistribution[RandomVariate[NormalDistribution[],100],5];

Using 1000 interpolation points creates a very smooth estimate in this case:

𝒟s=SmoothKernelDistribution[RandomVariate[𝒟h,100],InterpolationPoints->1000];

Plot[{PDF[𝒟s,x],PDF[𝒟h,x]},{x,-4,4},PlotRange->All,Exclusions->None,PlotLegends->{"𝒟s","𝒟h"}]

OpenersExampleSubsection6(Spacer1)MaxExtraBandwidths  (6)

By default, the estimate extends at most 12 bandwidths beyond the data:

data=RandomVariate[𝒹=ParetoDistribution[1,2],10^3];

𝒟1=SmoothKernelDistribution[data,MaxExtraBandwidths->12];
𝒟2=SmoothKernelDistribution[data,MaxExtraBandwidths->Automatic];

Table[Plot[PDF[𝒟,x],{x,0,10},PlotRange->All],{𝒟,{𝒟1,𝒟2}}]

Set the maximum number of bandwidths to use:

data=RandomVariate[𝒹=ParetoDistribution[1,2],10^3];

𝒟1=SmoothKernelDistribution[data,MaxExtraBandwidths->0];
𝒟2=SmoothKernelDistribution[data,MaxExtraBandwidths->12];

Use 0 and 12 bandwidths, respectively:

Table[Plot[PDF[𝒟,x],{x,0,10},PlotRange->All,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Set a different number for each endpoint:

data=RandomVariate[NormalDistribution[],10];

mebw={{0,0},{0,12},{12,0},{12,12}};

𝒟=Table[SmoothKernelDistribution[data,MaxExtraBandwidths->i],
{i,mebw}];

Table[Plot[PDF[𝒟[[i]],x],{x,-6,6},PlotRange->All,Filling->Axis,PlotLabel->mebw[[i]],Ticks->None],{i,4}]

Specify the number of extra bandwidths to use for multivariate data:

data=RandomVariate[BinormalDistribution[.5],10];

𝒟1=SmoothKernelDistribution[data,MaxExtraBandwidths->0];
𝒟2=SmoothKernelDistribution[data,MaxExtraBandwidths->12];

Use 0 and 12 bandwidths, respectively:

Table[ContourPlot[PDF[𝒟,{x,y}],{x,-4,4},{y,-4,4},PlotRange->All,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Specify the number of extra bandwidths to use in each dimension:

data=RandomVariate[BinormalDistribution[.5],10];

𝒟1=SmoothKernelDistribution[data,MaxExtraBandwidths->{0,12}];
𝒟2=SmoothKernelDistribution[data,MaxExtraBandwidths->{12,0}];

Use 0 and 12 bandwidths or 12 and 0 bandwidths, respectively:

Table[ContourPlot[PDF[𝒟,{x,y}],{x,-4,4},{y,-4,4},PlotRange->All,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

Set a different number for each endpoint in each dimension:

data=RandomVariate[BinormalDistribution[.5],10];

𝒟1=SmoothKernelDistribution[data,MaxExtraBandwidths->{{0,12},{12,0}}];
𝒟2=SmoothKernelDistribution[data,MaxExtraBandwidths->{{12,0},{0,12}}];

Table[ContourPlot[PDF[𝒟,{x,y}],{x,-4,4},{y,-4,4},PlotRange->All,Exclusions->None],{𝒟,{𝒟1,𝒟2}}]

OpenersExampleSubsection7(Spacer1)MaxMixtureKernels  (6)

By default, the number of kernels is generally optimal:

data=RandomVariate[𝒹=ParetoDistribution[1,2],10^4];

𝒟=SmoothKernelDistribution[data,MaxMixtureKernels->Automatic];

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,0,6},PlotRange->{0,1.3},PlotLegends->{"𝒟","𝒹"}]

Specify the maximum number of kernels to use in the estimate:

data=RandomVariate[NormalDistribution[],10];

Place at most 5 kernels:

𝒟=SmoothKernelDistribution[data,MaxMixtureKernels->5];

Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis,PlotRange->All]

A larger number of kernels gives a better estimate of the underlying distribution:

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

estimates=Table[SmoothKernelDistribution[data,MaxMixtureKernels->i],{i,{10,15,25,100}}];

Table[Plot[{PDF[i,x],PDF[NormalDistribution[],x]},{x,-4,4},Filling->Axis,PlotRange->All],{i,estimates}]

Place a kernel at each data point:

data={-2,0,2};

𝒟=SmoothKernelDistribution[data,.25,MaxMixtureKernels->All];

Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis]

Vary the bandwidth used for the same number of kernels:

Table[Plot[PDF[SmoothKernelDistribution[data,bw,MaxMixtureKernels->All],x]//Evaluate,{x,-4,4},Filling->Axis,PlotRange->{0,.6},PlotLabel->Row[{"bandwidth = ",bw}]],{bw,{0.25,0.5,0.75,1.0}}]

Specify the maximum number of kernels to use in each dimension for bivariate data:

data=RandomVariate[BinormalDistribution[.8],100];

Place at most 10 and 100 kernels, respectively:

estimates = Table[SmoothKernelDistribution[data,.2,MaxMixtureKernels->i],{i,{10,100}}];

Table[DensityPlot[PDF[i,{x,y}]//Evaluate,{x,-4,4},{y,-4,4},PlotPoints->100,PlotRange->All,ColorFunction->"TemperatureMap"],{i,estimates}]

Set the maximum number of kernels in each dimension:

data=RandomVariate[BinormalDistribution[.8],100];

Specify a maximum of 5 and 50 kernels or 50 and 5:

estimates=Table[SmoothKernelDistribution[data,MaxMixtureKernels->i],{i,{{5,50},{50,5}}}];

Table[Plot3D[Evaluate[PDF[i,{x,y}]],{x,-4,4},{y,-4,4},PlotPoints->50,PlotRange->All],{i,estimates}]

OpenersExampleSubsection8(Spacer1)MaxRecursion  (4)

A smooth estimate will usually be returned by default:

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

𝒟=SmoothKernelDistribution[data,MaxRecursion->Automatic];

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-5,5},PlotLegends->{"𝒟","𝒹"}]

Specify the maximum number of recursive subdivisions to use:

data=RandomVariate[NormalDistribution[],10];

𝒟=Table[SmoothKernelDistribution[data,InterpolationPoints->3,MaxRecursion->i],{i,{0,2,4,6}}];

Table[Plot[PDF[i,x],{x,-5,5},Filling->Axis,PlotRange->All],{i,𝒟}]

Give the maximum number of recursive subdivisions for bivariate data:

data=RandomVariate[BinormalDistribution[.8],100];

Use at most 2 and 6 subdivisions, respectively:

estimates = Table[SmoothKernelDistribution[data,MaxRecursion->i,InterpolationPoints->3],{i,{2,6}}];

Table[Plot3D[PDF[i,{x,y}]//Evaluate,{x,-4,4},{y,-4,4},PlotRange->All,ColorFunction->"TemperatureMap"],{i,estimates}]

Set the maximum number of recursive subdivisions in each dimension:

data=RandomVariate[BinormalDistribution[.8],100];

Specify a maximum of 0 and 3 subdivisions or 3 and 0:

estimates=Table[SmoothKernelDistribution[data,MaxRecursion->i,InterpolationPoints->6],{i,{{0,3},{3,0}}}];

Table[Plot3D[PDF[i,{x,y}]//Evaluate,{x,-4,4},{y,-4,4},PlotRange->All],{i,estimates}]

OpenersExampleSubsection9(Spacer1)PerformanceGoal  (3)

By default, estimates are optimized for a balance between speed and quality:

data=RandomVariate[𝒹=NormalDistribution[],10^5];

(𝒟=SmoothKernelDistribution[data,PerformanceGoal->Automatic])//Timing

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-5,5},PlotLegends->{"𝒟","𝒹"}]

Set (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]) for speed or quality or use (RefLink[Automatic, paclet:ref/Automatic]) to balance the two:

data=RandomVariate[𝒹=MixtureDistribution[{1,1},{MultinormalDistribution[{-1,-1},IdentityMatrix[2]],MultinormalDistribution[{1,1},.5IdentityMatrix[2]]}],10^2];

More time is spent with (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]) set to "Quality":

𝒟1=SmoothKernelDistribution[data,PerformanceGoal->"Speed"];//Timing

𝒟2=SmoothKernelDistribution[data,PerformanceGoal->Automatic];//Timing

𝒟3=SmoothKernelDistribution[data,PerformanceGoal->"Quality"];//Timing

Table[ContourPlot[Evaluate[PDF[𝒟,{x,y}]],{x,-4,4},{y,-4,4},PlotPoints->35,PlotRange->All],{𝒟,{𝒟1,𝒟2,𝒟3}}]

Use with (RefLink[ControlActive, paclet:ref/ControlActive]) to vary (RefLink[PerformanceGoal, paclet:ref/PerformanceGoal]) dynamically:

data=RandomVariate[MixtureDistribution[{1/2,1/10,1/10,1/10,1/10,1/10},Join[{NormalDistribution[]},Table[NormalDistribution[i/2 - 1, 1/10],{i,0,4}]]],3*10^3];

Manipulate[Plot[PDF[SmoothKernelDistribution[data,PerformanceGoal->ControlActive["Speed","Quality"]],x]//Evaluate,{x,a,b},PlotRange->{Automatic,{0,.55}}],{a,-3,0.1},{b,3,0,-.1},SaveDefinitions->True]

OpenersExampleSection3(Spacer1)Applications  (14)

Compare an estimated density to a theoretical model:

𝒹=MixtureDistribution[{1/2,1/10,1/10,1/10,1/10,1/10},Join[{NormalDistribution[]},Table[NormalDistribution[i/2 - 1, 1/10],{i,0,4}]]];

data=RandomVariate[𝒹,10^5];

Use adaptive bandwidths for highly oscillatory densities:

𝒟=SmoothKernelDistribution[data,{"Adaptive",Automatic,.25},PerformanceGoal->"Quality"];

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-4,4},PlotLegends->{"𝒟","𝒹"}]

The moments of the model and the estimate are similar:

{Mean[𝒹],Variance[𝒹],Skewness[𝒹],Kurtosis[𝒹]}//N

{Mean[𝒟],Variance[𝒟],Skewness[𝒟],Kurtosis[𝒟]}

Use (RefLink[TruncatedDistribution, paclet:ref/TruncatedDistribution]) to restrict the domain after smoothing:

data=RandomVariate[ExponentialDistribution[2],10^4];

dist=SmoothKernelDistribution[data];

𝒟=TruncatedDistribution[{0,Infinity},dist];

The estimate is restricted to positive values:

Plot[PDF[𝒟,x]//Evaluate,{x,-1,5},PlotRange->All,Filling->Axis]

Verify that the distribution is bound by the truncation region:

NProbability[x<0,x\[Distributed]𝒟]

Use with (RefLink[Cases, paclet:ref/Cases]) to restrict the data domain before smoothing:

data=Cases[RandomVariate[NormalDistribution[],10^5],x_/;x>0];

𝒟=SmoothKernelDistribution[data];

The estimate goes beyond the data on the left, but the data is restricted to positive values:

Plot[PDF[𝒟,x],{x,-1,5},PlotRange->All,Filling->Axis]

The probability that the data falls below zero is not zero:

NProbability[x<0,x\[Distributed]𝒟]

Use (RefLink[MaxExtraBandwidths, paclet:ref/MaxExtraBandwidths]) to restrict the domain without dropping data:

data=RandomVariate[ExponentialDistribution[2],10^6];

𝒟=SmoothKernelDistribution[data,MaxExtraBandwidths->{0,12}];

The estimate stops at the minimum data value, which is restricted to positive values:

Plot[PDF[𝒟,x],{x,-3,3},PlotRange->All,Filling->Axis]

NProbability[x<0,x\[Distributed]𝒟]

Estimate the distribution of the lengths of human chromosomes:

𝒟=SmoothKernelDistribution[ N[Log[Table[GenomeData[i,"SequenceLength"],{i,41}] ]]];

Plot[PDF[𝒟,x],{x,0,30},Filling->Axis,Frame->True]

The expected chromosome length, given that the length is greater than the mean:

NExpectation[x\[Conditioned]x>Mean[𝒟],x\[Distributed]𝒟]

Smooth the discrete distribution of the differences of successive primes:

data=Table[Prime[i]-Prime[i-1],{i,2,10^4}];

𝒟=SmoothKernelDistribution[data];

Plot[PDF[𝒟,x],{x,-10,50},Filling->Axis,Frame->True,PlotRange->All,Axes->False]

NExpectation[13+x,x\[Distributed]𝒟]

Investigate the distribution of differenced daily returns on the S&P 500 during the 1990s:

sp500=ExampleData[{"Statistics","SP500"}];

(Subscript[𝒟, SP500])=SmoothKernelDistribution[sp500,{"Adaptive",Automatic,.25}];

Compare the smoothed distribution to a fitted model:

dfit=EstimatedDistribution[sp500,LaplaceDistribution[μ,β]];

Plot[{PDF[dfit,x],PDF[(Subscript[𝒟, SP500]),x]},{x,-5,5},PlotRange->All,AxesOrigin->{-5,0},PlotLegends->{"dfit","(Subscript[𝒟, SP500])"}]

Compare the distribution of salaries from two university departments:

ExampleData[{"Statistics","UniversitySalaries"},"ColumnDescriptions"]

fullData=ExampleData[{"Statistics","UniversitySalaries"}][[All,{1,3}]];

Select salaries for two departments and attach currency units:

statSalaries=Cases[fullData,{"Statistics",salary_}:>salary];
chemSalaries=Cases[fullData,{"Chemistry",salary_}:>salary];

(Subscript[𝒟, Stat])=SmoothKernelDistribution[QuantityArray[statSalaries,"USDollars"]];
(Subscript[𝒟, Chem])=SmoothKernelDistribution[QuantityArray[chemSalaries,"USDollars"]];

Table[Plot[PDF[𝒟,Quantity[x,"USDollars"]],{x,0,250000},Ticks->{{{70000,"70K"},{125000,"125K"},{200000,"200K"}},None},PlotRange->All,Filling->Axis,AxesLabel->{"$"}],{𝒟,{(Subscript[𝒟, Stat]),(Subscript[𝒟, Chem])}}]

Estimate the joint distribution of Old Faithful eruption durations and waiting times:

oldF=QuantityArray[ExampleData[{"Statistics","OldFaithful"}],"Minutes"];

(Subscript[𝒟, OldF])=SmoothKernelDistribution[oldF,"SheatherJones"];

Plot3D[PDF[(Subscript[𝒟, OldF]),Quantity[{x,y},"Minutes"]]//Evaluate,{x,1,6},{y,35,105},PlotRange->All,Exclusions->None,AspectRatio->1,PlotPoints->50,AxesLabel->{"Duration","Waiting",None}]

Probability an eruption lasts more than two minutes and the waiting time is less than one hour:

NProbability[x>(Quantity[2, "min", minutes, "Minutes"])&&y<(Quantity[60, "min", minutes, "Minutes"]),{x,y}\[Distributed](Subscript[𝒟, OldF]),PrecisionGoal->3]

Smooth a histogram:

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

hist=HistogramDistribution[data];

Generate random numbers from the histogram for smoothing:

samples=RandomVariate[hist,10^5];

{DiscretePlot[PDF[hist,x],{x,-4,4,.05}],Plot[PDF[SmoothKernelDistribution[samples,"Oversmooth"],x]//Evaluate,{x,-4,4},Filling->Axis]}

Smooth an estimate returned from (RefLink[SurvivalDistribution, paclet:ref/SurvivalDistribution]):

data=RandomInteger[{10,40},50];

censoring=RandomInteger[{0,1},50];

𝒟=SurvivalDistribution[EventData[data,censoring]];

samples=RandomVariate[𝒟,10^4];

Show[DiscretePlot[SurvivalFunction[𝒟,x],{x,data}],Plot[SurvivalFunction[𝒹=SmoothKernelDistribution[samples],x]//Evaluate,{x,0,50},PlotStyle->,PlotRange->All],PlotRange->{{5,45},All},Axes->False,Frame->True]

Compute the probability of survival beyond 25, given that the survival time is greater than 10:

NProbability[x>25\[Conditioned]x>10,x\[Distributed]𝒹]

Create a confidence band for the PDF of snowfall accumulations in Buffalo, New York:

ExampleData[{"Statistics","BuffaloSnow"},"Description"]

data=QuantityArray[ExampleData[{"Statistics","BuffaloSnow"}]//N,"Inches"];

𝒟=SmoothKernelDistribution[data];

bSamp=RandomChoice[Normal[data],{250,Length[data]}];

Smooth over each bootstrapped sample and obtain the confidence estimates:

(Subscript[𝒟, B])=SmoothKernelDistribution[#]&/@bSamp;

rng=Range[10.,150];
pdf=Table[PDF[i,Quantity[rng,"Inches"]],{i,(Subscript[𝒟, B])}];
High=Table[Quantile[i,.975],{i,Transpose[pdf]}];
Low = Table[Quantile[i,.025],{i,Transpose[pdf]}];

Visualize the estimate of the PDF with the 95% confidence band:

Show[Plot[PDF[𝒟,Quantity[x,"Inches"]],{x,0,150},PlotRange->All,AxesLabel->{"in"}],ListLinePlot[{Transpose[{rng,High}],Transpose[{rng,Low}]},PlotStyle->{{Dashed,Gray}},Filling->{1->{2}}]]

Confirm that the Mahalanobis distance has an asymptotic (RefLink[ChiSquareDistribution, paclet:ref/ChiSquareDistribution])[p], given p-dimensional multivariate normal data:

data=Table[RandomVariate[MultinormalDistribution[ConstantArray[0,i],IdentityMatrix[i]],(10^3)],{i,rng=Range[2,5]}];

MahalanobisDistance[data_]:=Block[{m=Mean[data],cov=Inverse[Covariance[data]],temp},temp=(#1-m&)/@data;Diagonal[temp.cov.Transpose[temp]]]

𝒟s=Table[SmoothKernelDistribution[MahalanobisDistance[i]],{i,data}];

Table[Plot[{PDF[ChiSquareDistribution[rng[[i]]],x],PDF[𝒟s[[i]],x]},{x,0,30},PlotRange->All,PlotLabel->Row[{"Dimension: ",rng[[i]]}]],{i,Length[rng]}]

The probability that the Mahalanobis distance will exceed 10, given four-dimensional normal data:

NProbability[x>10,x\[Distributed]𝒟s[[3]]]

Estimate a heavy-tailed density using parametric tail models:

data=BlockRandom[SeedRandom[11];RandomVariate[𝒹=CauchyDistribution[0,.1],10^3]];

The body is estimated well, but the tails are undersmoothed due to lack of data:

Show[SmoothHistogram[data,PlotRange->All],Plot[PDF[𝒹,x],{x,-10,10},PlotStyle->{Dashed,},PlotRange->All],PlotRange->{{-10,10},{0,.3}}]

Create a mixture of the kernel density estimate and estimated tail models:

q10=Quantile[data,.1];q90=Quantile[data,.9];

left=EstimatedDistribution[Select[data,#<q10&],TruncatedDistribution[{-∞,q10},CauchyDistribution[a,b]]];

right=EstimatedDistribution[Select[data,#>q90&],TruncatedDistribution[{q90,∞},CauchyDistribution[a,b]]];

body=TruncatedDistribution[{q10,q90},SmoothKernelDistribution[Select[data,q10-1≤#≤q90+1&]]];

𝒟=MixtureDistribution[{.1,.8,.1},{left,body,right}];

The entire estimate is smooth:

Plot[{PDF[𝒟,x],PDF[𝒹,x]},{x,-20,20},PlotStyle->{Automatic,{Dashed,}},Exclusions->None,PlotRange->{0,.1},PlotLegends->{"𝒟","𝒹"}]

OpenersExampleSection4(Spacer1)Properties & Relations  (8)

The resulting density estimate integrates to unity:

data=RandomVariate[NormalDistribution[],100];

𝒟=SmoothKernelDistribution[data];

Integrate[PDF[𝒟,x],{x,-Infinity,Infinity}]

By default, machine estimates are used:

data=Range[10];

𝒟=SmoothKernelDistribution[data,1];

Precision[𝒟]

Use high-precision data to get high-precision estimates:

data=N[Range[10],100];

𝒟=SmoothKernelDistribution[data,1];

Precision[𝒟]

The PDF is piecewise linear:

𝒟=SmoothKernelDistribution[RandomVariate[NormalDistribution[],100],InterpolationPoints->20,MaxRecursion->0];

Plot[PDF[𝒟,x],{x,-4,4}]

The CDF and (RefLink[SurvivalFunction, paclet:ref/SurvivalFunction]) are piecewise quadratic:

{Plot[CDF[𝒟,x],{x,-4,4}],Plot[SurvivalFunction[𝒟,x],{x,-4,4}]}

The (RefLink[HazardFunction, paclet:ref/HazardFunction]) is piecewise rational with linear over quadratic:

Plot[HazardFunction[𝒟,x],{x,-4,4}]

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) is a consistent estimator of the underlying distribution:

data=Table[RandomVariate[NormalDistribution[],(10^i)],{i,Range[4]}];

𝒟l=Table[SmoothKernelDistribution[i],{i,data}];

Table[Plot[{PDF[𝒟l[[i]],x],PDF[NormalDistribution[],x]},{x,-5,5},PlotRange->All,Exclusions->None,PlotLabel->Row[{"n=",Superscript[10,i]}]],{i,Range[4]}]

As the bandwidth approaches infinity, the estimate approaches the shape of the kernel:

data={-.5,0,.5};

𝒦={"Gaussian","Epanechnikov","Biweight","Triweight","Rectangular","Triangular","Cosine","SemiCircle"};

Table[Plot[PDF[SmoothKernelDistribution[data,200,i],x]//Evaluate,{x,-500,500},PlotRange->All,Ticks->None,AxesOrigin->{0,0},PlotLabel->i],{i,𝒦}]

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) is a linear interpolation of (RefLink[KernelMixtureDistribution, paclet:ref/KernelMixtureDistribution]):

data={-1.5,-1.0,-.2,-.1,0.,1.5};

pts=Table[{i,PDF[KernelMixtureDistribution[data],i]},{i,Range[-4,4,.1]}];

{ListLinePlot[pts],Plot[PDF[SmoothKernelDistribution[data],x]//Evaluate,{x,-4,4}]}

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) works on the values only when the input is a (RefLink[TimeSeries, paclet:ref/TimeSeries]) or an (RefLink[EventSeries, paclet:ref/EventSeries]):

ts=TimeSeries[];

SmoothKernelDistribution[ts]

The same as:

SmoothKernelDistribution[ts["Values"]]

%==%%

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) works with all the values together when the input is a (RefLink[TemporalData, paclet:ref/TemporalData]):

td=TemporalData[];

SmoothKernelDistribution[td]

The same as:

SmoothKernelDistribution[td["ValueList"]//Flatten]

%%==%

OpenersExampleSection5(Spacer1)Possible Issues  (4)

The kernel function needs to be a PDF:

data = {-1.5,-1.0,-.2,-.1,0.,1.5};

𝒟 = SmoothKernelDistribution[data,1,Cos[#]&];

The resulting density estimate is not a PDF:

Plot[PDF[𝒟,x],{x,-4,4},Filling->Axis]

Automatic adaptive bandwidths may be too small with large samples:

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

dist=SmoothKernelDistribution[data,{"Adaptive",Automatic,1}];

Plot[PDF[dist,x]//Evaluate,{x,-4,4},PlotRange->All]

Try increasing the initial bandwidth, (RefLink[MaxMixtureKernels, paclet:ref/MaxMixtureKernels]), or decreasing the sensitivity:

dist2= SmoothKernelDistribution[data,{"Adaptive",1.5,1}];

Plot[PDF[dist2,x]//Evaluate,{x,-4,4},PlotRange->All]

(RefLink[SmoothKernelDistribution, paclet:ref/SmoothKernelDistribution]) does not know the domain of the underlying distribution:

data=RandomVariate[𝒹=BinomialDistribution[30,.5],10^4];

The estimated PDF is continuous, although the underlying distribution is discrete:

{DiscretePlot[PDF[𝒹,x],{x,5,25}],Plot[PDF[SmoothKernelDistribution[data],x]//Evaluate,{x,5,25}]}

data2=RandomVariate[𝒹2=TruncatedDistribution[{-1,1},NormalDistribution[]],10^4];

The estimated PDF is not bound on [-1,1]:

{Plot[PDF[𝒹2,x],{x,-2,2},Exclusions->None],Plot[PDF[SmoothKernelDistribution[data2],x]//Evaluate,{x,-2,2}]}

With heavily adaptive bandwidths, these issues may be less obvious:

data3=RandomVariate[𝒹,10^4];
data4=RandomVariate[𝒹2,10^4];

{Plot[PDF[SmoothKernelDistribution[data3,{"Adaptive",Automatic,1}],x]//Evaluate,{x,5,25},PlotRange->All],
Plot[PDF[SmoothKernelDistribution[data4,{"Adaptive",Automatic,1}],x]//Evaluate,{x,-2,2}]}

The tails of some distributions are too heavy to interpolate effectively:

SeedRandom[1];data=RandomVariate[𝒹=StableDistribution[0,1/9,1/15,1/15,1],10^3];

𝒟=SmoothKernelDistribution[data,10^-5];

{Plot[PDF[𝒹,x],{x,.054,.056},PlotRange->All],Plot[PDF[𝒟,x],{x,.054,.056},PlotRange->All,Exclusions->None]}

(RefLink[KernelMixtureDistribution, paclet:ref/KernelMixtureDistribution]) uses symbolic methods that do not rely on interpolation:

𝒟=KernelMixtureDistribution[data,10^-5,MaxMixtureKernels->All]//Quiet;

{Plot[PDF[𝒹,x],{x,.054,.056},PlotRange->All],Plot[PDF[𝒟,x],{x,.054,.056},PlotRange->All,Exclusions->None]}

OpenersExampleSection6(Spacer1)Neat Examples  (2)

Compute the distribution of temperature readings near your location:

data=WeatherData[loc=FindGeoLocation[],"Temperature",{{2001,1,1},{2009,1,1}},"NonMetricValue"];

data=Extract[data,Position[data,x_/;NumericQ[x]]];

𝒟=SmoothKernelDistribution[data]

Show[Plot[PDF[𝒟,x],{x,-10,110},Frame->True,Filling->Axis,PlotLabel->Row[{"Temperature Distribution: Lat ",Latitude[loc]," Lon ",Longitude[loc]}],FrameLabel->{"°F","Density"},Axes->False,PlotRange->All,ColorFunction->Function[{x,y},ColorData["TemperatureMap"][x]]],Plot[PDF[𝒟,x],{x,-10,110},PlotStyle->Black]]

Estimate the density of volcanic craters in western Uganda:

dat=ExampleData[{"Statistics","UgandaVolcanoes"}];
poly=ExampleData[{"Statistics","WesternUgandaBorder"}];

𝒟=SmoothKernelDistribution[dat,"SheatherJones"];

A region function for a bounding polygon using winding numbers:

inPolyQ=Compile[{{poly,_Real,2},{x,_Real},{y,_Real}},Block[{Xi,Yi,Xip1,Yip1,u,v,w},{Xi,Yi}=Transpose[poly];
Xip1=RotateLeft[Xi];
Yip1=RotateLeft[Yi];
u=UnitStep[y-Yi];
v=RotateLeft[u];
w=UnitStep[-((Xip1-Xi) (y-Yi)-(x-Xi) (Yip1-Yi))];
Total[(u (1-v) (1-w)-(1-u) v w)]≠0]];;

dens=ContourPlot[PDF[𝒟,{x,y}]//Evaluate,{x,0,3000},{y,550,4500},PlotRange->All,PlotPoints->50,Contours->15,ColorFunction->"TemperatureMap",RegionFunction->(inPolyQ[poly,#1,#2]&)];

Show[dens,ListLinePlot[poly,PlotStyle->Thick],ListPlot[dat,PlotMarkers->{Automatic,8},PlotStyle->Black],PlotLabel->Text[Style["Volcanic Crater Density",{Bold,18}]]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[KernelMixtureDistribution, paclet:ref/KernelMixtureDistribution])  ▪  (RefLink[HistogramDistribution, paclet:ref/HistogramDistribution])  ▪  (RefLink[EmpiricalDistribution, paclet:ref/EmpiricalDistribution])  ▪  (RefLink[SurvivalDistribution, paclet:ref/SurvivalDistribution])  ▪  (RefLink[EstimatedDistribution, paclet:ref/EstimatedDistribution])  ▪  (RefLink[FindDistribution, paclet:ref/FindDistribution])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Nonparametric Statistical Distributions, paclet:guide/NonparametricStatisticalDistributions])}, {▪(RefLinkPlain[Probability & Statistics, paclet:guide/ProbabilityAndStatistics])}, {▪(RefLinkPlain[Random Variables, paclet:guide/RandomVariables])}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}, {▪(RefLinkPlain[Survival Analysis, paclet:guide/SurvivalAnalysis])}, {▪(RefLinkPlain[Probability & Statistics with Quantities, paclet:guide/ProbabilityWithQuantities])}})}})