1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
.. _discrete-random-variables:
==================================
Discrete Statistical Distributions
==================================
Discrete random variables take on only a countable number of values.
The commonly used distributions are included in SciPy and described in
this document. Each discrete distribution can take one extra integer
parameter: :math:`L.` The relationship between the general distribution
:math:`p` and the standard distribution :math:`p_{0}` is
.. math::
:nowrap:
p\left(x\right) = p_{0}\left(x-L\right)
which allows for shifting of the input. When a distribution generator
is initialized, the discrete distribution can either specify the
beginning and ending (integer) values :math:`a` and :math:`b` which must be such that
.. math::
:nowrap:
p_{0}\left(x\right) = 0\quad x < a \textrm{ or } x > b
in which case, it is assumed that the pdf function is specified on the
integers :math:`a+mk\leq b` where :math:`k` is a non-negative integer ( :math:`0,1,2,\ldots` ) and :math:`m` is a positive integer multiplier. Alternatively, the two lists :math:`x_{k}` and :math:`p\left(x_{k}\right)` can be provided directly in which case a dictionary is set up
internally to evaluate probabilities and generate random variates.
Probability Mass Function (PMF)
-------------------------------
The probability mass function of a random variable X is defined as the
probability that the random variable takes on a particular value.
.. math::
:nowrap:
p\left(x_{k}\right)=P\left[X=x_{k}\right]
This is also sometimes called the probability density function,
although technically
.. math::
:nowrap:
f\left(x\right)=\sum_{k}p\left(x_{k}\right)\delta\left(x-x_{k}\right)
is the probability density function for a discrete distribution [#]_ .
.. [#]
XXX: Unknown layout Plain Layout: Note that we will be using :math:`p` to represent the probability mass function and a parameter (a
XXX: probability). The usage should be obvious from context.
Cumulative Distribution Function (CDF)
--------------------------------------
The cumulative distribution function is
.. math::
:nowrap:
F\left(x\right)=P\left[X\leq x\right]=\sum_{x_{k}\leq x}p\left(x_{k}\right)
and is also useful to be able to compute. Note that
.. math::
:nowrap:
F\left(x_{k}\right)-F\left(x_{k-1}\right)=p\left(x_{k}\right)
Survival Function
-----------------
The survival function is just
.. math::
:nowrap:
S\left(x\right)=1-F\left(x\right)=P\left[X>k\right]
the probability that the random variable is strictly larger than :math:`k` .
.. _discrete-ppf:
Percent Point Function (Inverse CDF)
------------------------------------
The percent point function is the inverse of the cumulative
distribution function and is
.. math::
:nowrap:
G\left(q\right)=F^{-1}\left(q\right)
for discrete distributions, this must be modified for cases where
there is no :math:`x_{k}` such that :math:`F\left(x_{k}\right)=q.` In these cases we choose :math:`G\left(q\right)` to be the smallest value :math:`x_{k}=G\left(q\right)` for which :math:`F\left(x_{k}\right)\geq q` . If :math:`q=0` then we define :math:`G\left(0\right)=a-1` . This definition allows random variates to be defined in the same way
as with continuous rv's using the inverse cdf on a uniform
distribution to generate random variates.
Inverse survival function
-------------------------
The inverse survival function is the inverse of the survival function
.. math::
:nowrap:
Z\left(\alpha\right)=S^{-1}\left(\alpha\right)=G\left(1-\alpha\right)
and is thus the smallest non-negative integer :math:`k` for which :math:`F\left(k\right)\geq1-\alpha` or the smallest non-negative integer :math:`k` for which :math:`S\left(k\right)\leq\alpha.`
Hazard functions
----------------
If desired, the hazard function and the cumulative hazard function
could be defined as
.. math::
:nowrap:
h\left(x_{k}\right)=\frac{p\left(x_{k}\right)}{1-F\left(x_{k}\right)}
and
.. math::
:nowrap:
H\left(x\right)=\sum_{x_{k}\leq x}h\left(x_{k}\right)=\sum_{x_{k}\leq x}\frac{F\left(x_{k}\right)-F\left(x_{k-1}\right)}{1-F\left(x_{k}\right)}.
Moments
-------
Non-central moments are defined using the PDF
.. math::
:nowrap:
\mu_{m}^{\prime}=E\left[X^{m}\right]=\sum_{k}x_{k}^{m}p\left(x_{k}\right).
Central moments are computed similarly :math:`\mu=\mu_{1}^{\prime}`
.. math::
:nowrap:
\begin{eqnarray*} \mu_{m}=E\left[\left(X-\mu\right)^{m}\right] & = & \sum_{k}\left(x_{k}-\mu\right)^{m}p\left(x_{k}\right)\\ & = & \sum_{k=0}^{m}\left(-1\right)^{m-k}\left(\begin{array}{c} m\\ k\end{array}\right)\mu^{m-k}\mu_{k}^{\prime}\end{eqnarray*}
The mean is the first moment
.. math::
:nowrap:
\mu=\mu_{1}^{\prime}=E\left[X\right]=\sum_{k}x_{k}p\left(x_{k}\right)
the variance is the second central moment
.. math::
:nowrap:
\mu_{2}=E\left[\left(X-\mu\right)^{2}\right]=\sum_{x_{k}}x_{k}^{2}p\left(x_{k}\right)-\mu^{2}.
Skewness is defined as
.. math::
:nowrap:
\gamma_{1}=\frac{\mu_{3}}{\mu_{2}^{3/2}}
while (Fisher) kurtosis is
.. math::
:nowrap:
\gamma_{2}=\frac{\mu_{4}}{\mu_{2}^{2}}-3,
so that a normal distribution has a kurtosis of zero.
Moment generating function
--------------------------
The moment generating function is defined as
.. math::
:nowrap:
M_{X}\left(t\right)=E\left[e^{Xt}\right]=\sum_{x_{k}}e^{x_{k}t}p\left(x_{k}\right)
Moments are found as the derivatives of the moment generating function
evaluated at :math:`0.`
Fitting data
------------
To fit data to a distribution, maximizing the likelihood function is
common. Alternatively, some distributions have well-known minimum
variance unbiased estimators. These will be chosen by default, but the
likelihood function will always be available for minimizing.
If :math:`f_{i}\left(k;\boldsymbol{\theta}\right)` is the PDF of a random-variable where :math:`\boldsymbol{\theta}` is a vector of parameters ( *e.g.* :math:`L` and :math:`S` ), then for a collection of :math:`N` independent samples from this distribution, the joint distribution the
random vector :math:`\mathbf{k}` is
.. math::
:nowrap:
f\left(\mathbf{k};\boldsymbol{\theta}\right)=\prod_{i=1}^{N}f_{i}\left(k_{i};\boldsymbol{\theta}\right).
The maximum likelihood estimate of the parameters :math:`\boldsymbol{\theta}` are the parameters which maximize this function with :math:`\mathbf{x}` fixed and given by the data:
.. math::
:nowrap:
\begin{eqnarray*} \hat{\boldsymbol{\theta}} & = & \arg\max_{\boldsymbol{\theta}}f\left(\mathbf{k};\boldsymbol{\theta}\right)\\ & = & \arg\min_{\boldsymbol{\theta}}l_{\mathbf{k}}\left(\boldsymbol{\theta}\right).\end{eqnarray*}
Where
.. math::
:nowrap:
\begin{eqnarray*} l_{\mathbf{k}}\left(\boldsymbol{\theta}\right) & = & -\sum_{i=1}^{N}\log f\left(k_{i};\boldsymbol{\theta}\right)\\ & = & -N\overline{\log f\left(k_{i};\boldsymbol{\theta}\right)}\end{eqnarray*}
Standard notation for mean
--------------------------
We will use
.. math::
:nowrap:
\overline{y\left(\mathbf{x}\right)}=\frac{1}{N}\sum_{i=1}^{N}y\left(x_{i}\right)
where :math:`N` should be clear from context.
Combinations
------------
Note that
.. math::
:nowrap:
k!=k\cdot\left(k-1\right)\cdot\left(k-2\right)\cdot\cdots\cdot1=\Gamma\left(k+1\right)
and has special cases of
.. math::
:nowrap:
\begin{eqnarray*} 0! & \equiv & 1\\ k! & \equiv & 0\quad k<0\end{eqnarray*}
and
.. math::
:nowrap:
\left(\begin{array}{c} n\\ k\end{array}\right)=\frac{n!}{\left(n-k\right)!k!}.
If :math:`n<0` or :math:`k<0` or :math:`k>n` we define :math:`\left(\begin{array}{c} n\\ k\end{array}\right)=0`
Discrete Distributions in `scipy.stats`
---------------------------------------
.. toctree::
:maxdepth: 1
discrete_bernoulli
discrete_binom
discrete_boltzmann
discrete_planck
discrete_poisson
discrete_geom
discrete_nbinom
discrete_hypergeom
discrete_zipf
discrete_logser
discrete_randint
discrete_dlaplace
|