# 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(, loc=0, scale=1, size=1) random variates pdf(x, , loc=0, scale=1) probability density function cdf(x, , loc=0, scale=1) cumulative density function sf(x, , loc=0, scale=1) survival function (1-cdf — sometimes more accurate) ppf(q, , loc=0, scale=1) percent point function (inverse of cdf — quantiles) isf(q, , loc=0, scale=1) inverse survival function (inverse of sf) moments(n, ) non-central n-th moment of the standard distribution (oc=0, scale=1) stats(, loc=0, scale=1, moments=’mv’) mean(‘m’), variance(‘v’), skew(‘s’), and/or kurtosis(‘k’) entropy(, loc=0, scale=1) (differential) entropy of the RV. fit(data, , loc=0, scale=1) Parameter estimates for generic data __call__(, 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 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.

#### Previous topic

scipy.stats.gaussian_kde

#### Next topic

scipy.stats.rv_continuous.pdf
{"ft_lang_label":"__label__en","ft_lang_prob":0.65575874,"math_prob":0.92721397,"size":3375,"snap":"2023-14-2023-23","text_gpt3_token_len":921,"char_repetition_ratio":0.14891723,"word_repetition_ratio":0.0,"special_character_ratio":0.2568889,"punctuation_ratio":0.14903846,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98142797,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-05-28T13:53:37Z\",\"WARC-Record-ID\":\"<urn:uuid:8ab1730d-5068-472d-9867-fa1fac7fba8c>\",\"Content-Length\":\"21523\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ae1bc15c-51e2-4a9f-88c3-d9857205e64f>\",\"WARC-Concurrent-To\":\"<urn:uuid:f33eb748-94d5-4f40-beee-77b53b76ee52>\",\"WARC-IP-Address\":\"50.17.248.72\",\"WARC-Target-URI\":\"https://docs.scipy.org/doc/scipy-0.8.x/reference/generated/scipy.stats.rv_continuous.html\",\"WARC-Payload-Digest\":\"sha1:WY3TDGQDAW5OQSX7LQPXJRDAWJY5EARM\",\"WARC-Block-Digest\":\"sha1:YQ2BBG3UOKB7Y6HGN3XT4BP4W4HHS3YY\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224643784.62_warc_CC-MAIN-20230528114832-20230528144832-00501.warc.gz\"}"}