cdfplot

Empirical cumulative distribution function plot

Syntax

`cdfplot(X)h = cdfplot(X)[h,stats] = cdfplot(X)`

Description

`cdfplot(X)` displays a plot of the empirical cumulative distribution function (cdf) for the data in the vector `X`. The empirical cdf F(x) is defined as the proportion of `X` values less than or equal to x.

This plot is useful for examining the distribution of a sample of data. You can overlay a theoretical cdf on the same plot to compare the empirical distribution of the sample to the theoretical distribution.

The `kstest`, `kstest2`, and `lillietest` functions compute test statistics that are derived from the empirical cdf. You may find the empirical cdf plot produced by `cdfplot` useful in helping you to understand the output from those functions.

`h = cdfplot(X)` returns a handle to the cdf curve.

`[h,stats] = cdfplot(X)` also returns a `stats` structure with the following fields.

FieldDescription

`stats.min`

Minimum value

`stats.max`

Maximum value

`stats.mean`

Sample mean

`stats.median`

Sample median (50th percentile)

`stats.std`

Sample standard deviation

Examples

collapse all

Compare Empirical cdf with Sampling Distribution

This example shows how to plot the empirical cdf of sample data and compare it with a plot of the cdf for the sampling distribution. In practice, the sampling distribution would be unknown, and would be chosen to match the empirical cdf.

Generate random sample data from an extreme value distribution with a location parameter `mu = 0` and scale parameter `sigma = 3`.

```rng default; % For reproducibility y = evrnd(0,3,100,1); ```

Plot the empirical cdf of the sample data on the same figure as the cdf of the sampling distribution.

```cdfplot(y) hold on x = -20:0.1:10; f = evcdf(x,0,3); plot(x,f,'m') legend('Empirical','Theoretical','Location','NW') ```