randomStudentT¶
Generates pseudorandom numbers from a Student’s t distribution.
Synopsis¶
randomStudentT (nRandom, df)
Required Arguments¶
- int
nRandom
(Input) - Number of random numbers to generate.
- float
df
(Input) - Degrees of freedom. Parameter
df
must be positive.
Return Value¶
An array of length nRandom
containing the random deviates of a Student’s
t distribution.
Optional Arguments¶
mean
, float (Input)- Mean of the Student’s t distribution.Default:
mean
= 0.0 variance
, float (Input)- Variance of the Student’s t distribution.Default:
variance
= 1.0
Description¶
Function randomStudentT
generates pseudorandom numbers from a Student’s
t distribution with df
degrees of freedom, using a method suggested by
Kinderman et al. (1977). The method (“TMX” in the reference) involves a
representation of the t density as the sum of a triangular density over
(−2, 2) and the difference of this and the t density. The mixing
probabilities depend on the degrees of freedom of the t distribution. If
the triangular density is chosen, the variate is generated as the sum of two
uniforms; otherwise, an acceptance/rejection method is used to generate the
difference density.
Example¶
In this example, randomStudentT
generates five pseudorandom deviates
from a Student’s t distribution with 12 degrees of freedom.
from numpy import *
from pyimsl.stat.randomStudentT import randomStudentT
from pyimsl.stat.randomSeedSet import randomSeedSet
from pyimsl.stat.writeMatrix import writeMatrix
n_random = 5
df = 5.0
randomSeedSet(123457)
r = randomStudentT(n_random, df)
writeMatrix("StudentT random deviates", r, noColLabels=True)
Output¶
StudentT random deviates
0.615 1.189 0.091 1.377 -0.965