Contents

prob.KernelDistribution class

Package: prob
Superclasses: prob.TruncatableDistribution

Kernel probability distribution object

Description

prob.KernelDistribution is an object consisting of parameters, a model description, and sample data for a nonparametric kernel-smoothing distribution. Create a prob.KernelDistribution object using fitdist or dfittool.

Construction

pd = fitdist(x,'Kernel') creates a probability distribution object by fitting a kernel-smoothing distribution to the data in x.

pd = fitdist(x,'Kernel',Name,Value) creates a probability distribution object with additional options specified by one or more name-value pair arguments. For example, you can change the kernel function or specify the kernel bandwidth.

Input Arguments

expand all

x — Input datacolumn vector

Input data to fit with a kernel-smoothing distribution, specified as a column vector of scalar values. fitdist ignores NaN values in x.

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

'Kernel' — Kernel smoother type'normal' (default) | 'box' | 'triangle' | 'epanechnikov'

Kernel smoother type, specified as the comma-separated pair consisting of 'Kernel' and one of the following kernel smoothing function types:

  • 'normal'

  • 'box'

  • 'triangle'

  • 'epanechnikov'

'Support' — Kernel density support'unbounded' (default) | 'positive' | two-element vector

Kernel density support, specified as the comma-separated pair consisting of 'Support' and a string or two-element vector. The string must be one of the following.

'unbounded'Density can extend over the whole real line.
'positive'Density is restricted to positive values.

Alternatively, you can specify a two-element vector giving finite lower and upper limits for the support of the density.

Data Types: single | double

'Width' — Bandwidth of kernel smoothing windowscalar value

Bandwidth of the kernel smoothing window, specified as the comma-separated pair consisting of 'Width' and a scalar value. The default value used by fitdist is optimal for estimating normal densities, but you might want to choose a smaller value to reveal features such as multiple modes.

Data Types: single | double

Properties

expand all

KernelKernel smoother type'normal' | 'box' | 'triangle' | 'epanechnikov'

Kernel function type, stored as a valid kernel function type name.

BandWidthBandwidth of kernel smoothing windowpositive scalar value

Bandwidth of the kernel smoothing window, stored as a positive scalar value.

Data Types: single | double

DistributionNameProbability distribution nameprobability distribution name string

Probability distribution name, stored as a valid probability distribution name string. This property is read-only.

Data Types: char

InputDataData used for distribution fittingstructure

Data used for distribution fitting, stored as a structure containing the following:

  • data: Data vector used for distribution fitting.

  • cens: Censoring vector, or empty if none.

  • freq: Frequency vector, or empty if none.

This property is read-only.

Data Types: struct

IsTruncatedLogical flag for truncated distribution0 | 1

Logical flag for truncated distribution, stored as a logical value. If IsTruncated equals 0, the distribution is not truncated. If IsTruncated equals 1, the distribution is truncated. This property is read-only.

Data Types: logical

TruncationTruncation intervalvector of scalar values

Truncation interval for the probability distribution, stored as a vector containing the lower and upper truncation boundaries. This property is read-only.

Data Types: single | double

Methods

meanMean of probability distribution object
negloglikNegative loglikelihood
std Standard deviation of probability distribution object
varVariance of probability distribution object

Inherited Methods

cdf Cumulative distribution function of probability distribution object
icdfInverse cumulative distribution function of probability distribution object
iqrInterquartile range of probability distribution object
median Median of probability distribution object
pdfProbability density function of probability distribution object
randomGenerate random numbers from probability distribution object
truncateTruncate probability distribution object

Definitions

Kernel Distribution

The kernel distribution is a nonparametric estimation of the probability density function (pdf) of a random variable.

The kernel distribution uses the following options.

OptionDescriptionPossible Values
KernelKernel function typenormal, box, triangle, epanechnikov
BandWidthKernel smoothing parameterBandWidth > 0

The kernel density estimator is

f^h(x)=1nhi=1nK(xxih);<x<,

where n is the sample size, K(·) is the kernel function, and h is the bandwidth.

Examples

expand all

Fit a Kernel Distribution Object to Data

Load the sample data. Visualize the patient weight data using a histogram.

load hospital;
hist(hospital.Weight)

The histogram shows that the data has two modes, one for female patients and one for male patients.

Create a probability distribution object by fitting a kernel distribution to the patient weight data.

pd_kernel = fitdist(hospital.Weight,'Kernel')
pd_kernel = 

  KernelDistribution

    Kernel = normal
    Bandwidth = 14.3792
    Support = unbounded

For comparison, create another probability distribution object by fitting a normal distribution to the patient weight data.

pd_normal = fitdist(hospital.Weight,'Normal')
pd_normal = 

  NormalDistribution

  Normal distribution
       mu =     154   [148.728, 159.272]
    sigma = 26.5714   [23.3299, 30.8674]

Define the x values and compute the pdf of each distribution.

x = 50:1:250;
pdf_kernel = pdf(pd_kernel,x);
pdf_normal = pdf(pd_normal,x);

Plot the pdf of each distribution.

plot(x,pdf_kernel,'Color','b','LineWidth',2);
hold on;
plot(x,pdf_normal,'Color','r','LineStyle',':','LineWidth',2);
legend('Kernel Distribution','Normal Distribution','Location','SouthEast');
hold off;

Fitting a kernel distribution instead of a unimodal distribution such as the normal reveals the separate modes for the female and male patients.

Was this topic helpful?