Accelerating the pace of engineering and science

# Documentation Center

• Trial Software

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

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

 x Data values at which the cumulative distribution function (cdf) changes slope, stored as a vector of scalar values. Fx cdf value at each value in x, stored as a vector of scalar values. DistributionName Name of the probability distribution, stored as a valid probability distribution name string. This property is read-only. IsTruncated 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. NumParameters Number of parameters for the probability distribution, stored as a positive integer value. This property is read-only. ParameterDescription Descriptions of distribution parameters, stored as a cell array of strings. Each cell contains a short description of one distribution parameter. This property is read-only. ParameterNames Names of distribution parameters, stored as a cell array of strings. This property is read-only. ParameterValues Values of distribution parameters, stored as a vector. This property is read-only. Truncation Truncation interval for the probability distribution, stored as a vector containing the lower and upper truncation boundaries. This property is read-only.

## Methods

### 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
 mean Mean of probability distribution object std Standard deviation of probability distribution object var Variance 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.