# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# 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

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`.

expand all

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'`

Kernel density support, specified as the comma-separated pair consisting of `'Support'` and a character vector or two-element vector. The character vector 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`

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

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

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

Data Types: `single` | `double`

Probability distribution name, stored as a character vector. This property is read-only.

Data Types: `char`

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.

Data Types: `struct`

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`

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

 mean Mean of probability distribution object negloglik Negative loglikelihood std Standard deviation of probability distribution object var Variance of probability distribution object

### Inherited Methods

 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 pdf Probability density function of probability distribution object random Generate random numbers from probability distribution object truncate Truncate 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
`Kernel`Kernel function type`normal`, `box`, `triangle`, `epanechnikov`
`BandWidth`Kernel smoothing parameter`BandWidth > 0`

The kernel density estimator is

`${\stackrel{^}{f}}_{h}\left(x\right)=\frac{1}{nh}\sum _{i=1}^{n}K\left(\frac{x-{x}_{i}}{h}\right)\text{ };\text{ }-\infty `

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

## Examples

expand all

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.