Description

pd = fitdist(x,distname,Name,Value) creates
the probability distribution object with additional options specified
by one or more name-value pair arguments. For example, you can indicate
censored data or specify control parameters for the iterative fitting
algorithm.

[pdca,gn,gl]
= fitdist(x,distname,'By',groupvar) creates
probability distribution objects by fitting the distribution specified
by distname to the data in x based
on the grouping variable groupvar. It returns
a cell array of fitted probability distribution objects, pdca,
a cell array of group labels, gn, and a cell
array of grouping variable levels, gl.

[pdca,gn,gl]
= fitdist(x,distname,'By',groupvar,Name,Value) returns
the above output arguments using additional options specified by one
or more name-value pair arguments. For example, you can indicate censored
data or specify control parameters for the iterative fitting algorithm.

The cell array pdca contains two probability distribution objects, one for each gender group. The cell array gn contains two strings of the group labels. The cell array gl contains two strings of the group levels.

View each distribution in the cell array pdca to compare the mean, mu, and the standard deviation, sigma, grouped by patient gender.

Grouping variable, specified as a categorical array, logical
or numeric vector, or cell array of strings. Each unique value in
a grouping variable defines a group.

For example, if Gender is a cell array of
strings with values 'Male' and 'Female',
you can use Gender as a grouping variable to fit
a distribution to your data by gender.

More than one grouping variable can be used by specifying a
cell array of grouping variable names. Observations are placed in
the same group if they have common values of all specified grouping
variables.

For example, if Smoker is a logical vector
with values 0 for nonsmokers and 1 for
smokers, then specifying the cell array {Gender,Smoker} divides
observations into four groups: Male Smoker, Male Nonsmoker, Female
Smoker, and Female Nonsmoker.

Example: {Gender,Smoker}

Data Types: single | double | logical | cell | char

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.

Example: fitdist(x,'Kernel','Kernel','triangle') fits
a kernel distribution object to the data in x using
a triangular kernel function.

Logical flag for censored data, specified as the comma-separated
pair consisting of 'Censoring' and a vector of
logical values that is the same size as input vector x.
The value is 1 when the corresponding element in x is
a right-censored observation and 0 when the corresponding
elements is an exact observation. The default is a vector of 0s,
indicating that all observations are exact.

fitdist ignores any NaN values
in this censoring vector. Additionally, any NaN values
in x or the frequency vector causes fitdist to
ignore the corresponding values in the censoring vector.

Observation frequency, specified as the comma-separated pair
consisting of 'Frequency' and a vector of nonnegative
integer values that is the same size as input vector x.
Each element of the frequency vector specifies the frequencies for
the corresponding elements in x. The default
is a vector of 1s, indicating that each value in x only
appears once.

fitdist ignores any NaN values
in this frequency vector are ignored by the fitting calculations.
Additionally, any NaN values in x or
the censoring vector causes fitdist to ignore the
corresponding values in the frequency vector.

Threshold parameter for the generalized Pareto distribution,
specified as the comma-separated pair consisting of 'Theta' and
a scalar value. You must specify distname as 'GeneralizedPareto' to
use this option.

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. You must specify distname as 'Kernel' to
use this option.

Grouping variable levels, returned as a cell array of strings
containing one column for each grouping variable.

Alternative Functionality

App

The Distribution Fitting app opens a graphical user interface
for you to import data from the workspace and interactively fit a
probability distribution to that data. You can then save the distribution
to the workspace as a probability distribution object. Open the Distribution
Fitting app using dfittool, or
click Distribution Fitting on the Apps tab.