# [SciPy-user] random variates

Travis E. Oliphant oliphant at ee.byu.edu
Fri Apr 2 18:58:18 CST 2004

```Brian Gue wrote:
> Hi,
>
> Are there examples of usage of the statistics functions? I'm
> specifically looking for samples using scipy.stats.truncnorm and
> scipy.stats.triang.
>

The help should be better now.

ie.

scipy.info(scipy.stats.triang)

Basically,

>>> info(stats.triang)
Instance of class:  triang_gen

triang(*args, **kwds)

Triangular Distribution

up-sloping line from loc to (loc + c*scale) and then downsloping
for (loc + c*scale) to (loc+scale).

standard form is in range [0,1] with c the mode
location parameter shifts the start to loc
scale changes the width from 1 to scale

Triangular distribution

up-sloping line from loc to (loc + c*scale) and then downsloping
for (loc + c*scale) to (loc+scale).

- standard form is in the range [0,1] with c the mode.
- location parameter shifts the start to loc
- scale changes the width from 1 to scale

Docstring still needs work here.  Note that stats.triang  has all the
methods of stats.truncnorm  as well (just enter c instead of a,b)

stats.triang.pdf
stats.triang.rvs

etc.

>>> info(stats.truncnorm)
Instance of class:  truncnorm_gen

truncnorm(*args, **kwds)

A truncated normal continuous random variable.

Continuous random variables are defined from a standard form chosen
for simplicity of representation.  The standard form may require
some shape parameters to complete its specification.  The distributions
also take optional location and scale parameters using loc= and scale=
keywords (defaults: loc=0, scale=1)

These shape, scale, and location parameters can be passed to any of the
methods of the RV object such as the following:

truncnorm.rvs(a,b,loc=0,scale=1)
- random variates

truncnorm.pdf(x,a,b,loc=0,scale=1)
- probability density function

truncnorm.cdf(x,a,b,loc=0,scale=1)
- cumulative density function

truncnorm.sf(x,a,b,loc=0,scale=1)
- survival function (1-cdf --- sometimes more accurate)

truncnorm.ppf(q,a,b,loc=0,scale=1)
- percent point function (inverse of cdf --- percentiles)

truncnorm.isf(q,a,b,loc=0,scale=1)
- inverse survival function (inverse of sf)

truncnorm.stats(a,b,loc=0,scale=1,moments='mv')
- mean('m'), variance('v'), skew('s'), and/or kurtosis('k')

truncnorm.entropy(a,b,loc=0,scale=1)
- (differential) entropy of the RV.

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

myrv = truncnorm(a,b,loc=0,scale=1)
- frozen RV object with the same methods but holding the
given shape, location, and scale fixed

Truncated Normal distribution

```