To calculate the probability of a negative binomial distribution in Matlab, you can use the nbinpdf
function. The nbinpdf
function calculates the probability density function (PDF) for the negative binomial distribution with parameters r
(number of failures) and p
(probability of success on each trial) at the values in x
.
Here's an example code block that generates a random sample from a negative binomial distribution with r = 5
and p = 0.3
, calculates the PDF of this distribution at the value x = 10
, and displays the result:
main.m439 chars14 lines
This code block generates a random sample of 1000 values from a negative binomial distribution with r = 5
and p = 0.3
. It then calculates the PDF of this distribution at the value x = 10
. Finally, it displays the result as a formatted string.
Note that the nbinpdf
function requires the Statistics and Machine Learning Toolbox. If you do not have this toolbox installed, you can use the nbincdf
function instead to calculate the cumulative distribution function (CDF) of the negative binomial distribution.
gistlibby LogSnag