Kernel probability distribution object
prob.KernelDistribution is an object consisting
of parameters, a model description, and sample data for a nonparametric
kernel-smoothing distribution. Create a
a probability distribution object by fitting a kernel-smoothing distribution
to the data in
pd = fitdist(
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.
pd = fitdist(
x— Input data
Input data to fit with a kernel-smoothing distribution, specified
as a column vector of scalar values.
Specify optional comma-separated pairs of
Name is the argument
Value is the corresponding
Name must appear
inside single quotes (
You can specify several name and value pair
arguments in any order as
'Kernel'— Kernel smoother type
Kernel smoother type, specified as the comma-separated pair
'Kernel' and one of the following
kernel smoothing function types:
'Support'— Kernel density support
'positive'| two-element vector
Kernel density support, specified as the comma-separated pair
'Support' and a character vector
or two-element vector. The character vector must be one of the following.
|Density can extend over the whole real line.|
|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.
'Width'— Bandwidth of kernel smoothing window
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.
Kernel— Kernel smoother type
Kernel function type, stored as a valid kernel function type name.
BandWidth— Bandwidth of kernel smoothing window
Bandwidth of the kernel smoothing window, stored as a positive scalar value.
DistributionName— Probability distribution name
Probability distribution name, stored as a character vector. This property is read-only.
InputData— Data used for distribution fitting
Data used for distribution fitting, stored as a structure containing the following:
data: Data vector used for distribution
cens: Censoring vector, or empty
freq: Frequency vector, or empty
This property is read-only.
IsTruncated— Logical flag for truncated distribution
Logical flag for truncated distribution, stored as a logical
the distribution is not truncated. If
the distribution is truncated. This property is read-only.
Truncation— Truncation interval
Truncation interval for the probability distribution, stored as a vector containing the lower and upper truncation boundaries. This property is read-only.
|mean||Mean of probability distribution object|
|std||Standard deviation of probability distribution object|
|var||Variance of probability distribution object|
|cdf||Cumulative distribution function of probability distribution object|
|icdf||Inverse cumulative distribution function of probability distribution object|
|iqr||Interquartile range of probability distribution object|
|median||Median of probability distribution object|
|Probability density function of probability distribution object|
|random||Generate random numbers from probability distribution object|
|truncate||Truncate probability distribution object|
Load the sample data. Visualize the patient weight data using a histogram.
load hospital histogram(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.
The kernel distribution is a nonparametric estimation of the probability density function (pdf) of a random variable.
The kernel distribution uses the following options.
|Kernel function type|
|Kernel smoothing parameter|
The kernel density estimator is
where n is the sample size, is the kernel function, and h is the bandwidth.