Documentation Center

  • Trial Software
  • Product Updates

Contents

prob.PiecewiseLinearDistribution class

Package: prob
Superclasses: prob.ParametricTruncatableDistribution

Piecewise linear probability distribution object

Description

prob.PiecewiseLinearDistribution is an object consisting of a model description for a piecewise linear probability distribution. Create a probability distribution object with specified parameters using makedist.

Construction

pd = makedist('PiecewiseLinear') creates a piecewise linear probability distribution object using the default parameter values.

pd = makedist('PiecewiseLinear','x',x,'Fx',Fx) creates a piecewise linear probability distribution object using the specified values.

Input Arguments

expand all

x — Data values1 (default) | vector of scalar values

Data values at which the cumulative distribution function (cdf) changes slope, specified as a vector of scalar values.

Data Types: single | double

Fx — cdf value1 (default) | vector of scalar values

cdf value at each value in x, specified as a vector of scalar values. x and Fx must be the same size. The first value in the vector Fx must be 0, and the last element must be 1. Fx increases linearly between x(j) and x(j+1), for all j.

Data Types: single | double

Properties

expand all

x — Data valuesvector of scalar values

Data values at which the cumulative distribution function (cdf) changes slope, stored as a vector of scalar values.

Data Types: single | double

Fx — cdf valuevector of scalar values

cdf value at each value in x, stored as a vector of scalar values.

Data Types: single | double

DistributionName — Probability distribution nameprobability distribution name string

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

Data Types: char

IsTruncated — Logical 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

NumParameters — Number of parameterspositive integer value

Number of parameters for the probability distribution, stored as a positive integer value. This property is read-only.

Data Types: single | double

ParameterDescription — Distribution parameter descriptionscell array of strings

Distribution parameter descriptions, stored as a cell array of strings. Each cell contains a short description of one distribution parameter. This property is read-only.

Data Types: char

ParameterNames — Distribution parameter namescell array of strings

Distribution parameter names, stored as a cell array of strings. This property is read-only.

Data Types: char

ParameterValues — Distribution parameter valuesvector of scalar values

Distribution parameter values, stored as a vector. This property is read-only.

Data Types: single | double

Truncation — Truncation 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

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
meanMean of probability distribution object
std Standard deviation of probability distribution object
varVariance of probability distribution object

Definitions

Piecewise Linear Distribution

The piecewise linear distribution is a nonparametric probability distribution created using a piecewise linear representation of the cumulative distribution function (cdf). The options specified for the piecewise linear distribution specify the form of the cdf. The probability density function (pdf) is a step function.

Examples

expand all

Create a Piecewise Linear Distribution Object Using Default Parameters

Create a piecewise linear distribution object using the default parameter values.

pd = makedist('PiecewiseLinear')
pd = 

  PiecewiseLinearDistribution

F(0) = 0
F(1) = 1

Create a Piecewise Linear Distribution Object Using Specified Parameters

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.

Compute the empirical cumulative distribution function (ecdf) for the data.

[f,x] = ecdf(hospital.Weight);

Construct a piecewise linear approximation to the ecdf and plot both functions.

f = f(1:5:end); % keep a less dense grid of points
x = x(1:5:end);

figure;
ecdf(hospital.Weight)
hold on
plot(x,f,'ro','MarkerFace','r') % overlay grid
plot(x,f,'k') % show interpolation

Create a piecewise linear probability distribution object using the piecewise approximation of the ecdf.

pd = makedist('PiecewiseLinear','x',x,'Fx',f)
pd = 

  PiecewiseLinearDistribution

F(111) = 0
F(118) = 0.05
F(124) = 0.13
F(130) = 0.25
F(135) = 0.37
F(142) = 0.5
F(163) = 0.55
F(171) = 0.61
F(178) = 0.7
F(183) = 0.82
F(189) = 0.94
F(202) = 1

Generate 100 random numbers from the distribution.

rw = random(pd,100,1);

Plot the random numbers to visually compare their distribution to the original data.

figure;
hist(rw)

The random numbers generated from the piecewise linear distribution have the same bimodal distribution as the original data.

See Also

More About

Was this topic helpful?