PoissonDistribution
statistics: PoissonDistribution
Poisson probability distribution object.
A PoissonDistribution
object consists of parameters, a model
description, and sample data for a Poisson probability distribution.
The Poisson distribution is a discrete probability distribution that models the number of events occurring in a fixed interval of time or space, given a constant average rate of occurrence. It is defined by the rate parameter lambda.
There are several ways to create a PoissonDistribution
object.
fitdist
function.
makedist
function.
PoissonDistribution (lambda)
to create a Poisson distribution with fixed parameter value lambda.
PoissonDistribution.fit (x,
freq)
to fit a distribution to the data in x using
the same input arguments as the poissfit
function.
It is highly recommended to use fitdist
and makedist
functions to create probability distribution objects, instead of the class
constructor or the aforementioned static method.
Further information about the Poisson distribution can be found at https://en.wikipedia.org/wiki/Poisson_distribution
See also: fitdist, makedist, poisscdf, poissinv, poisspdf, poissrnd, poissfit, poisslike, poisstat
Source Code: PoissonDistribution
A positive scalar value characterizing the rate of the
Poisson distribution. You can access the lambda
property using dot name assignment.
## Create a Poisson distribution from data rand ("seed", 21); data = poissrnd (5, 100, 1); pd = fitdist (data, "Poisson"); ## Query parameter 'lambda' (rate parameter) pd.lambda ## Set parameter 'lambda' pd.lambda = 10 ## Use this to initialize or modify the rate parameter of a Poisson distribution. ## The rate parameter must be a positive real scalar, representing both the mean ## and variance, ideal for count data modeling. ans = 4.9100 pd = PoissonDistribution Poisson distribution lambda = 10 |
## Create a Poisson distribution object by calling its constructor pd = PoissonDistribution (7.5) ## Query parameter 'lambda' pd.lambda ## This shows direct construction with a specific rate parameter, useful for ## theoretical analysis or when lambda is estimated from prior knowledge. pd = PoissonDistribution Poisson distribution lambda = 7.5 ans = 7.5000 |
A character vector specifying the name of the probability distribution object. This property is read-only.
A scalar integer value specifying the number of parameters characterizing the probability distribution. This property is read-only.
A cell array of character vectors with each element containing the name of a distribution parameter. This property is read-only.
A cell array of character vectors with each element containing a short description of a distribution parameter. This property is read-only.
A numeric vector containing the values of the distribution
parameters. This property is read-only. You can change the distribution
parameters by assigning new values to the lambda
property.
A numeric matrix containing the variance of the parameter estimate. This matrix is only meaningful when the distribution was fitted to data. If the distribution object was created with fixed parameters, or a parameter of a fitted distribution is modified, then the variance is zero. This property is read-only.
A logical scalar specifying whether the parameter is fixed or estimated.
A true
value corresponds to a fixed parameter, a false
value corresponds to a parameter estimate. This property is read-only.
A numeric vector specifying the truncation interval for the
probability distribution. The first element contains the lower boundary,
the second element contains the upper boundary. This property is read-only.
You can only truncate a probability distribution with the
truncate
method.
A logical scalar value specifying whether a probability distribution is truncated or not. This property is read-only.
A scalar structure containing the following fields:
data
: a numeric vector containing the data used for
distribution fitting.
cens
: a numeric vector of logical values indicating
censoring information corresponding to the elements of the data used for
distribution fitting. If no censoring vector was used for distribution
fitting, then this field defaults to an empty array.
freq
: a numeric vector of non-negative integer values
containing the frequency information corresponding to the elements of the
data used for distribution fitting. If no frequency vector was used for
distribution fitting, then this field defaults to an empty array.
PoissonDistribution: p = cdf (pd, x)
PoissonDistribution: p = cdf (pd, x, "upper"
)
p = cdf (pd, x)
computes the CDF of the
probability distribution object, pd, evaluated at the values in
x.
p = cdf (…,
returns the complement of
the CDF of the probability distribution object, pd, evaluated at
the values in x.
"upper"
)
## Plot various CDFs from the Poisson distribution x = 0:20; data1 = poissrnd (2, 10000, 1); data2 = poissrnd (5, 10000, 1); data3 = poissrnd (10, 10000, 1); pd1 = fitdist (data1, "Poisson"); pd2 = fitdist (data2, "Poisson"); pd3 = fitdist (data3, "Poisson"); p1 = cdf (pd1, x); p2 = cdf (pd2, x); p3 = cdf (pd3, x); plot (x, p1, "-b", x, p2, "-g", x, p3, "-r") grid on legend ({"lambda = 2", "lambda = 5", "lambda = 10"}, "location", "southeast") title ("Poisson CDF") xlabel ("values in x (non-negative integers)") ylabel ("Cumulative probability") ## Use this to compute and visualize the cumulative distribution function ## for different Poisson distributions, showing the probability of observing ## at most k events, useful in risk assessment or queueing theory. |
PoissonDistribution: x = icdf (pd, p)
x = icdf (pd, p)
computes the quantile (the
inverse of the CDF) of the probability distribution object, pd,
evaluated at the values in p.
## Plot various iCDFs from the Poisson distribution p = 0.001:0.001:0.999; data1 = poissrnd (2, 10000, 1); data2 = poissrnd (5, 10000, 1); data3 = poissrnd (10, 10000, 1); pd1 = fitdist (data1, "Poisson"); pd2 = fitdist (data2, "Poisson"); pd3 = fitdist (data3, "Poisson"); x1 = icdf (pd1, p); x2 = icdf (pd2, p); x3 = icdf (pd3, p); plot (p, x1, "-b", p, x2, "-g", p, x3, "-r") grid on legend ({"lambda = 2", "lambda = 5", "lambda = 10"}, "location", "northwest") title ("Poisson iCDF") xlabel ("Probability") ylabel ("values in x (non-negative integers)") ## This demonstrates the inverse CDF (quantiles) for Poisson distributions, ## useful for finding the number of events corresponding to a given probability, ## such as in inventory management for stock levels. |
PoissonDistribution: r = iqr (pd)
r = iqr (pd)
computes the interquartile range of the
probability distribution object, pd.
## Compute the interquartile range for a Poisson distribution data = poissrnd (5, 10000, 1); pd = fitdist (data, "Poisson"); iqr_value = iqr (pd) ## Use this to calculate the interquartile range, measuring the spread of the ## middle 50% of the distribution, helpful for understanding variability in count data. iqr_value = 3 |
PoissonDistribution: m = mean (pd)
m = mean (pd)
computes the mean of the probability
distribution object, pd.
## Compute the mean for different Poisson distributions data1 = poissrnd (2, 10000, 1); data2 = poissrnd (5, 10000, 1); pd1 = fitdist (data1, "Poisson"); pd2 = fitdist (data2, "Poisson"); mean1 = mean (pd1) mean2 = mean (pd2) ## This shows how to compute the expected value for Poisson distributions, ## which equals lambda, representing the average number of events. mean1 = 2.0276 mean2 = 5.0409 |
PoissonDistribution: m = median (pd)
m = median (pd)
computes the median of the probability
distribution object, pd.
## Compute the median for different Poisson distributions data1 = poissrnd (2, 10000, 1); data2 = poissrnd (5, 10000, 1); pd1 = fitdist (data1, "Poisson"); pd2 = fitdist (data2, "Poisson"); median1 = median (pd1) median2 = median (pd2) ## Use this to find the median count, which splits the distribution into ## two equal probability halves, robust for skewed count data. median1 = 2 median2 = 5 |
PoissonDistribution: nlogL = negloglik (pd)
nlogL = negloglik (pd)
computes the negative
loglikelihood of the probability distribution object, pd.
## Compute the negative loglikelihood for a fitted Poisson distribution rand ("seed", 21); data = poissrnd (5, 100, 1); pd_fitted = fitdist (data, "Poisson"); nlogL = negloglik (pd_fitted) ## This is useful for assessing the fit of a Poisson distribution to data, ## with lower values indicating better fit, often used in model selection. nlogL = -209.83 |
PoissonDistribution: ci = paramci (pd)
PoissonDistribution: ci = paramci (pd, Name, Value)
ci = paramci (pd)
computes the lower and upper
boundaries of the 95% confidence interval for each parameter of the
probability distribution object, pd.
ci = paramci (pd, Name, Value)
computes
the confidence intervals with additional options specified by
Name-Value
pair arguments listed below.
Name | Value | |
---|---|---|
"Alpha" | A scalar value in the range specifying the significance level for the confidence interval. The default value 0.05 corresponds to a 95% confidence interval. | |
"Parameter" | A character vector or a cell array of
character vectors specifying the parameter names for which to compute
confidence intervals. By default, paramci computes confidence
intervals for all distribution parameters. |
paramci
is meaningful only when pd is fitted to data,
otherwise an empty array, []
, is returned.
## Compute confidence intervals for parameters of a fitted Poisson distribution rand ("seed", 21); data = poissrnd (5, 1000, 1); pd_fitted = fitdist (data, "Poisson"); ci = paramci (pd_fitted, "Alpha", 0.05) ## Use this to obtain confidence intervals for the estimated parameter (lambda), ## providing a range of plausible values based on the data. ci = 4.8239 5.1001 |
PoissonDistribution: y = pdf (pd, x)
y = pdf (pd, x)
computes the PDF of the
probability distribution object, pd, evaluated at the values in
x.
## Plot various PDFs from the Poisson distribution x = 0:20; data1 = poissrnd (2, 10000, 1); data2 = poissrnd (5, 10000, 1); data3 = poissrnd (10, 10000, 1); pd1 = fitdist (data1, "Poisson"); pd2 = fitdist (data2, "Poisson"); pd3 = fitdist (data3, "Poisson"); y1 = pdf (pd1, x); y2 = pdf (pd2, x); y3 = pdf (pd3, x); plot (x, y1, "-b", x, y2, "-g", x, y3, "-r") grid on legend ({"lambda = 2", "lambda = 5", "lambda = 10"}, "location", "northeast") title ("Poisson PDF") xlabel ("values in x (non-negative integers)") ylabel ("Probability") ## This visualizes the probability mass function for Poisson distributions, ## showing the likelihood of exact count values. |
PoissonDistribution: plot (pd)
PoissonDistribution: plot (pd, Name, Value)
PoissonDistribution: h = plot (…)
plot (pd)
plots a probability density function (PDF) of the
probability distribution object pd. If pd contains data,
which have been fitted by fitdist
, the PDF is superimposed over a
histogram of the data.
plot (pd, Name, Value)
specifies additional
options with the Name-Value
pair arguments listed below.
Name | Value | |
---|---|---|
"PlotType" | A character vector specifying the plot
type. "pdf" plots the probability density function (PDF). When
pd is fit to data, the PDF is superimposed on a histogram of the
data. "cdf" plots the cumulative density function (CDF). When
pd is fit to data, the CDF is superimposed over an empirical CDF.
"probability" plots a probability plot using a CDF of the data
and a CDF of the fitted probability distribution. This option is
available only when pd is fitted to data. | |
"Discrete" | A logical scalar to specify whether to
plot the PDF or CDF of a discrete distribution object as a line plot or a
stem plot, by specifying false or true , respectively. By
default, it is true for discrete distributions and false
for continuous distributions. | |
"Parent" | An axes graphics object for the plot. If
not specified, the plot function plots into the current axes or
creates a new axes object if one does not exist. |
h = plot (…)
returns a graphics handle to the plotted
objects.
## Create a Poisson distribution with fixed parameter lambda=5 and plot its PDF. data = poissrnd (5, 10000, 1); pd = fitdist (data, "Poisson"); plot (pd) title ("Fixed Poisson distribution with lambda = 5") |
## Generate a data set of 100 random samples from a Poisson distribution with ## lambda=5. Fit a Poisson distribution to this data and plot its CDF superimposed ## over an empirical CDF. rand ("seed", 21); data = poissrnd (5, 100, 1); pd_fitted = fitdist (data, "Poisson"); plot (pd_fitted, "PlotType", "cdf") txt = "Fitted Poisson distribution with lambda = %0.2f"; title (sprintf (txt, pd_fitted.lambda)) legend ({"empirical CDF", "fitted CDF"}, "location", "southeast") ## Use this to visualize the fitted CDF compared to the empirical CDF of the data, ## useful for assessing model fit in count data. |
## Generate a data set of 200 random samples from a Poisson distribution with ## lambda=5. Display a probability plot for the Poisson distribution fit to the data. rand ("seed", 21); data = poissrnd (5, 200, 1); pd_fitted = fitdist (data, "Poisson"); plot (pd_fitted, "PlotType", "probability") txt = strcat ("Probability plot of fitted Poisson distribution with lambda = %0.2f"); title (sprintf (txt, pd_fitted.lambda)) legend ({"empirical CDF", "fitted CDF"}, "location", "southeast") ## This creates a probability plot to compare the fitted distribution to the data, ## useful for checking if the Poisson model is appropriate for count data. |
PoissonDistribution: [nlogL, param] = proflik (pd, pnum)
PoissonDistribution: [nlogL, param] = proflik (pd, pnum, "Display"
, display)
PoissonDistribution: [nlogL, param] = proflik (pd, pnum, setparam)
PoissonDistribution: [nlogL, param] = proflik (pd, pnum, setparam, "Display"
, display)
[nlogL, param] = proflik (pd, pnum)
returns a vector nlogL of negative loglikelihood values and a
vector param of corresponding parameter values for the parameter in
the position indicated by pnum. By default, proflik
uses
the lower and upper bounds of the 95% confidence interval and computes
100 equispaced values for the selected parameter. pd must be
fitted to data.
[nlogL, param] = proflik (pd, pnum,
also plots the profile likelihood
against the default range of the selected parameter.
"Display"
, "on"
)
[nlogL, param] = proflik (pd, pnum,
setparam)
defines a user-defined range of the selected parameter.
[nlogL, param] = proflik (pd, pnum,
setparam,
also plots the profile
likelihood against the user-defined range of the selected parameter.
"Display"
, "on"
)
For the Poisson distribution, pnum = 1
selects the
parameter lambda
.
When opted to display the profile likelihood plot, proflik
also
plots the baseline loglikelihood computed at the lower bound of the 95%
confidence interval and estimated maximum likelihood. The latter might
not be observable if it is outside of the user-defined range of parameter
values.
## Compute and plot the profile likelihood for the rate parameter of a fitted ## Poisson distribution rand ("seed", 21); data = poissrnd (5, 1000, 1); pd_fitted = fitdist (data, "Poisson"); [nlogL, param] = proflik (pd_fitted, 1, "Display", "on"); ## Use this to analyze the profile likelihood of the rate parameter (lambda), ## helping to understand uncertainty in parameter estimates for count models. |
PoissonDistribution: r = random (pd)
PoissonDistribution: r = random (pd, rows)
PoissonDistribution: r = random (pd, rows, cols, …)
PoissonDistribution: r = random (pd, [sz])
r = random (pd)
returns a random number from the
distribution object pd.
When called with a single size argument, poissrnd
returns a square
matrix with the dimension specified. When called with more than one
scalar argument, the first two arguments are taken as the number of rows
and columns and any further arguments specify additional matrix
dimensions. The size may also be specified with a row vector of
dimensions, sz.
## Generate random samples from a Poisson distribution rand ("seed", 21); samples = poissrnd (5, 500, 1); hist (samples, 20) title ("Histogram of 500 random samples from Poisson(lambda=5)") xlabel ("values in x (non-negative integers)") ylabel ("Frequency") ## This generates random count samples from a Poisson distribution, useful ## for simulating event occurrences like defect counts or traffic arrivals. |
PoissonDistribution: s = std (pd)
s = std (pd)
computes the standard deviation of the
probability distribution object, pd.
## Compute the standard deviation for a Poisson distribution data = poissrnd (5, 10000, 1); pd = fitdist (data, "Poisson"); std_value = std (pd) ## Use this to calculate the standard deviation, which equals sqrt(lambda), ## measuring variability in event counts. std_value = 2.2371 |
PoissonDistribution: t = truncate (pd, lower, upper)
t = truncate (pd, lower, upper)
returns a
probability distribution t, which is the probability distribution
pd truncated to the specified interval with lower limit,
lower, and upper limit, upper. If pd is fitted to data
with fitdist
, the returned probability distribution t is not
fitted, does not contain any data or estimated values, and it is as it
has been created with the makedist function, but it includes the
truncation interval.
## Plot the PDF of a Poisson distribution, with lambda=5, truncated at [2, 10] ## intervals. Generate 10000 random samples from this truncated distribution and ## superimpose a histogram scaled accordingly rand ("seed", 21); data_all = poissrnd (5, 20000, 1); data = data_all(data_all >= 2 & data_all <= 10); data = data(1:10000); pd = fitdist (data, "Poisson"); t = truncate (pd, 2, 10); ## Plot histogram and truncated PDF plot (t) hold on [counts, centers] = hist (data, 20); bin_width = centers(2) - centers(1); counts_norm = counts / (sum (counts) * bin_width); bar (centers, counts_norm, 1); title ("Poisson distribution (lambda=5) truncated at [2, 10]") legend ("Truncated PDF", "Histogram") ## This demonstrates truncating a Poisson distribution to a specific range ## and visualizing the result with random samples, useful for bounded count data. |
PoissonDistribution: v = var (pd)
v = var (pd)
computes the variance of the
probability distribution object, pd.
## Compute the variance for a Poisson distribution data = poissrnd (5, 10000, 1); pd = fitdist (data, "Poisson"); var_value = var (pd) ## Use this to calculate the variance, which equals lambda, quantifying the ## spread in count data. var_value = 4.9747 |
pd_fixed = makedist ("Poisson", "lambda", 5) rand ("seed", 2); data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, "Poisson") plot (pd_fitted) msg = "Fitted Poisson distribution with lambda = %0.2f"; title (sprintf (msg, pd_fitted.lambda)) |
pd_fixed = PoissonDistribution Poisson distribution lambda = 5 pd_fitted = PoissonDistribution Poisson distribution lambda = 4.9748 [4.91298, 5.03662] |