### Navigation

- index
- modules |
- modules |
- next |
- previous |
- SciPy v0.9 Reference Guide (DRAFT) »
- Statistical functions (`scipy.stats`) »

# scipy.stats.rv_continuous

class `scipy.stats.``rv_continuous`(momtype=1, a=None, b=None, xa=-10.0, xb=10.0, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, extradoc=None)

  A generic continuous random variable class meant for subclassing.

  rv_continuous is a base class to construct specific distribution classes and instances from for continuous random variables. It cannot be used directly as a distribution.

  Parameters : | momtype : int, optional The type of generic moment calculation to use (check this). a : float, optional Lower bound of the support of the distribution, default is minus infinity. b : float, optional Upper bound of the support of the distribution, default is plus infinity. xa : float, optional Lower bound for fixed point calculation for generic ppf. xb : float, optional Upper bound for fixed point calculation for generic ppf. xtol : float, optional The tolerance for fixed point calculation for generic ppf. badvalue : object, optional The value in a result arrays that indicates a value that for which some argument restriction is violated, default is np.nan. name : str, optional The name of the instance. This string is used to construct the default example for distributions. longname : str, optional This string is used as part of the first line of the docstring returned when a subclass has no docstring of its own. Note: longname exists for backwards compatibility, do not use for new subclasses. shapes : str, optional The shape of the distribution. For example `"m, n"` for a distribution that takes two integers as the two shape arguments for all its methods. extradoc : str, optional This string is used as the last part of the docstring returned when a subclass has no docstring of its own. Note: extradoc exists for backwards compatibility, do not use for new subclasses.

  Notes

  Frozen Distribution

  Alternatively, the object may be called (as a function) to fix the shape, location, and scale parameters returning a “frozen” continuous RV object:

  rv = generic(<shape(s)>, loc=0, scale=1)
    frozen RV object with the same methods but holding the given shape, location, and scale fixed

  Subclassing

  New random variables can be defined by subclassing rv_continuous class and re-defining at least the

  _pdf or the cdf method which will be given clean arguments (in between a and b) and passing the argument check method

  If postive argument checking is not correct for your RV then you will also need to re-define

      _argcheck

  Correct, but potentially slow defaults exist for the remaining methods but for speed and/or accuracy you can over-ride

      _cdf, _ppf, _rvs, _isf, _sf

  Rarely would you override _isf and _sf but you could.

  Statistics are computed using numerical integration by default. For speed you can redefine this using

  _stats
    - take shape parameters and return mu, mu2, g1, g2
    - If you can’t compute one of these, return it as None
    - Can also be defined with a keyword argument moments=<str> where <str> is a string composed of ‘m’, ‘v’, ‘s’, and/or ‘k’. Only the components appearing in string should be computed and returned in the order ‘m’, ‘v’, ‘s’, or ‘k’ with missing values returned as None

  OR

  You can override

  _munp
    takes n and shape parameters and returns the nth non-central moment of the distribution.

  Examples

  To create a new Gaussian distribution, we would do the following:

      class gaussian_gen(rv_continuous):
          "Gaussian distribution"
          def _pdf:
              ...
          ...

  Methods

  rvs(<shape(s)>, loc=0, scale=1, size=1) |  | random variates
  pdf(x, <shape(s)>, loc=0, scale=1) |  | probability density function
  cdf(x, <shape(s)>, loc=0, scale=1) |  | cumulative density function
  sf(x, <shape(s)>, loc=0, scale=1) |  | survival function (1-cdf — sometimes more accurate)
  ppf(q, <shape(s)>, loc=0, scale=1) |  | percent point function (inverse of cdf — quantiles)
  isf(q, <shape(s)>, loc=0, scale=1) |  | inverse survival function (inverse of sf)
  moments(n, <shape(s)>) |  | non-central n-th moment of the standard distribution (oc=0, scale=1)
  stats(<shape(s)>, loc=0, scale=1, moments=’mv’) |  | mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’)
  entropy(<shape(s)>, loc=0, scale=1) |  | (differential) entropy of the RV.
  fit(data, <shape(s)>, loc=0, scale=1) |  | Parameter estimates for generic data
  __call__(<shape(s)>, loc=0, scale=1) |  | calling a distribution instance creates a frozen RV object with the same methods but holding the given shape, location, and scale fixed. see Notes section
  Parameters for Methods |  |
  x | array-like | quantiles
  q | array-like | lower or upper tail probability
  <shape(s)> | array-like | shape parameters
  loc | array-like, optional | location parameter (default=0)
  scale | array-like, optional | scale parameter (default=1)
  size | int or tuple of ints, optional | shape of random variates (default computed from input arguments )
  moments | string, optional | composed of letters [‘mvsk’] specifying which moments to compute where ‘m’ = mean, ‘v’ = variance, ‘s’ = (Fisher’s) skew and ‘k’ = (Fisher’s) kurtosis. (default=’mv’)
  n | int | order of moment to calculate in method moments
  Methods that can be overwritten by subclasses |  |
  |  | _rvs _pdf _cdf _sf _ppf _isf _stats _munp _entropy _argcheck
  There are additional (internal and private) generic methods that can |  |
  be useful for cross-checking and for debugging, but might work in all |  |
  cases when directly called. |  |

### Navigation

- index
- modules |
- modules |
- next |
- previous |
- SciPy v0.9 Reference Guide (DRAFT) »
- Statistical functions (`scipy.stats`) »