Contenido principal

unidcdf

Discrete uniform cumulative distribution function

Description

p = unidcdf(x,n) returns the cumulative distribution function (cdf) of the discrete uniform distribution with the maximum value n, evaluated at the values in x.

example

p = unidcdf(x,n,"upper") returns the complement of the cdf, evaluated at the values in x, using an algorithm that more accurately computes the extreme upper-tail probabilities as compared to subtracting the lower-tail value from 1.

Examples

collapse all

Compute the cumulative distribution function (cdf) of the discrete uniform distribution with the maximum value n=10, for values between 0 and 10.

x = 0:0.01:10;
n = 10;
p = unidcdf(x,n);

Plot the cdf.

plot(x,p)
grid on
xlabel("x")
ylabel("p")

Figure contains an axes object. The axes object with xlabel x, ylabel p contains an object of type line.

Use the discrete uniform distribution to estimate the size n of a collection of items that have serial numbers from 1 to n, based on a sample of observed serial numbers. This example is based on the famous German tank problem [1].

Suppose you observe k=5 items at random from the collection, and the highest observed serial number maxSerial is 40.

k = 5;  % Number of observed items
maxSerial = 40;  % Highest observed serial number

Compute the probability p of observing the highest serial number maxSerial in a sample of k items drawn without replacement from a population of size nmaxSerial.

n = maxSerial:1:100;
p = 1 - unidcdf(maxSerial,n).^k;

Plot the probability as a function of n, and add a red dashed line corresponding to p=0.95.

plot(n,p)
grid on
yline(0.95,"r--")
xlabel("n")
ylabel("p")

Figure contains an axes object. The axes object with xlabel n, ylabel p contains 2 objects of type line, constantline.

As shown in the plot, the 95% confidence upper bound for the size of the collection is 73.

Input Arguments

collapse all

Values at which to evaluate the discrete uniform cdf, specified as a nonnegative scalar or an array of nonnegative scalars. The values of x do not need to be integers.

To evaluate the cdf at multiple values, specify x as an array. To evaluate the cdfs of multiple distributions, specify n as an array. If x and n are both arrays, they must have the same size. If only x or n is an array, unidcdf expands the other input argument into a constant array of the same size as the array input. Each element in p is the cdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

Data Types: single | double

Maximum value in the discrete uniform distribution, specified as a positive integer or an array of positive integers.

To evaluate the cdf at multiple values, specify x as an array. To evaluate the cdfs of multiple distributions, specify n as an array. If x and n are both arrays, they must have the same size. If only x or n is an array, unidcdf expands the other input argument into a constant array of the same size as the array input. Each element in p is the cdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

Data Types: single | double

Output Arguments

collapse all

Discrete uniform cdf values, returned as a numeric scalar or array. p is the same size as x and n after any necessary scalar expansion. Each element in p is the cdf value of the distribution specified by the corresponding element in n, evaluated at the corresponding element in x.

More About

collapse all

Alternative Functionality

  • unidcdf is a function specific to the discrete uniform distribution. Statistics and Machine Learning Toolbox™ also offers the generic function cdf, which supports various probability distributions. To use cdf, specify the probability distribution name and its parameters. Note that the distribution-specific function unidcdf is faster than the generic function cdf.

  • Use the Probability Distribution Function Tool to create an interactive plot of the cumulative distribution function (cdf) or probability density function (pdf) for a probability distribution.

References

[1] Lee, Anthony, and Steven J. Miller. Generalizing the German Tank Problem. arXiv:2210.15339. Preprint, arXiv, October 27, 2022.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a