Stata 11 help for uniform

help random-number functions -------------------------------------------------------------------------------

Title

[D] functions -- Functions

Description

This is a quick reference on functions for generating pseudorandom variates. For help on all functions, see [D] functions. See [R] set seed for setting the random-number seed.

Random-number functions

runiform() Range: 0 to nearly 1 (0 to 1 - 2^(-32)) Description: returns uniform random variates.

runiform() returns uniformly distributed random variates on the interval [0,1). runiform() takes no arguments, but the parentheses must be typed. runiform() can be seeded with the set seed command. (See matrix functions for the related matuniform() matrix function.)

To generate random variates over the interval [a,b), use a+(b-a)*runiform().

To generate random integers over [a,b], use a+int((b-a+1)*runiform()).

rbeta(a, b) Domain a: 0.05 to 1e+5 Domain b: 0.15 to 1e+5 Range: 0 to 1 (exclusive) Description: returns beta(a,b) random variates, where a and b are the beta distribution shape parameters.

Besides the standard methodology for generating random variates from a given distribution, rbeta() uses the specialized algorithms of Johnk (Gentle 2003), Atkinson and Wittaker (1970, 1976), Devroye (1986), and Schmeiser and Babu (1980).

rbinomial(n, p) Domain n: 1 to 1e+11 Domain p: 1e-8 to 1-1e-8 Range: 0 to n Description: returns binomial(n,p) random variates, where n is the number of trials and p is the success probability.

Besides the standard methodology for generating random variates from a given distribution, rbinomial() uses the specialized algorithms of Kachitvichyanukul (1982), Kachitvichyanukul and Schmeiser (1988), and Kemp (1986).

rchi2(df) Domain df: 2e-4 to 2e+8 Range: 0 to c(maxdouble) Description: returns chi-squared, with df degrees of freedom, random variates.

rgamma(a, b) Domain a: 1e-4 to 1e+8 Domain b: c(smallestdouble) to c(maxdouble) Range: 0 to c(maxdouble) Description: returns gamma(a,b) random variates, where a is the gamma shape parameter and b is the scale parameter.

Methods for generating gamma variates are taken from Ahrens and Dieter (1974), Best (1983), and Schmeiser and Lal (1980).

rhypergeometric(N, K, n) Domain N: 2 to 1e+6 Domain K: 1 to N-1 Domain n: 1 to N-1 Range: max(0,n-N+K) to min(K,n) Description: returns hypergeometric random variates. The distribution parameters are integer valued, where N is the population size, K is the number of elements in the population that have the attribute of interest, and n is the sample size.

Besides the standard methodology for generating random variates from a given distribution, rhypergeometric() uses the specialized algorithms of Kachitvichyanukul (1982) and Kachitvichyanukul and Schmeiser (1985).

rnbinomial(n, p) Domain n: 0.1 to 1e+5 Domain p: 1e-4 to 1-1e-4 Range: 0 to 2^53-1 Description: returns negative binomial random variates. If n is integer valued, rnbinomial() returns the number of failures before the nth success, where the probability of success on a single trial is p. n can also be nonintegral.

rnormal() Range: c(mindouble) to c(maxdouble) Description: returns standard normal (Gaussian) random variates, i.e., variates from a normal distribution with a mean of 0 and a standard deviation of 1.

rnormal(m) Domain m: c(mindouble) to c(maxdouble) Range: c(mindouble) to c(maxdouble) Description: returns normal(m,1) (Gaussian) random variates, where m is the mean and the standard deviation is 1.

rnormal(m, s) Domain m: c(mindouble) to c(maxdouble) Domain s: c(smallestdouble) to c(maxdouble) Range: c(mindouble) to c(maxdouble) Description: returns normal(m,s) (Gaussian) random variates, where m is the mean and s is the standard deviation.

The methods for generating normal (Gaussian) random variates are taken from Knuth (1998, 122-128); Marsaglia, MacLaren, and Bray (1964); and Walker (1977).

rpoisson(m) Domain m: 1e-6 to 1e+11 Range: 0 to 2^53-1 Description: returns Poisson(m) random variates, where m is the distribution mean.

Poisson variates are generated using the probability integral transform methods of Kemp and Kemp (1990, 1991), as well as the method of Kachitvichyanukul (1982).

rt(df) Domain df: 1 to 2^53-1 Range: c(mindouble) to c(maxdouble) Description: returns Student's t random variates, where df is the degrees of freedom.

Student's t variates are generated using the method of Kinderman and Monahan (1977, 1980).

References

Ahrens, J. H., and U. Dieter. 1974. Computer methods for sampling from gamma, beta, Poisson, and binomial distributions. Computing 12: 223-246.

Atkinson, A. C., and J. Whittaker. 1976. A switching algorithm for the generation of beta random variables with at least one parameter less than 1. Journal of the Royal Statistical Society, Series A 139: 462-467.

------. 1970. Algorithm AS 134: The generation of beta random variables with one parameter greater than and one parameter less than 1. Applied Statistics 28: 90-93.

Best, D. J. 1983. A note on gamma variate generators with shape parameters less than unity. Computing 30: 185-188.

Devroye, L. 1986. Non-uniform Random Variate Generation. New York: Springer.

Gentle, J. E. 2003. Random Number Generation and Monte Carlo Methods. 2nd ed. New York: Springer.

Kachitvichyanukul, V. 1982. Computer Generation of Poisson, Binomial, and Hypergeometric Random Variables. PhD thesis, Purdue University.

Kachitvichyanukul, V., and B. Schmeiser. 1985. Computer generation of hypergeometric random variates. Journal of Statistical Computation and Simulation 22: 127-145.

------. 1988. Binomial random variate generation. Communications of the Association for Computing Machinery 31: 216-222.

Kemp, C. D. 1986. A modal method for generating binomial variates. Communications in Statistics: Theory and Methods 15: 805-813.

Kemp, A. W., and C. D. Kemp. 1990. A composition-search algorithm for low-parameter Poisson generation. Journal of Statistical Computation and Simulation 35: 239-244.

Kemp, C. D., and A. W. Kemp. 1991. Poisson random variate generation. Applied Statistics 40: 143-158.

Kinderman, A. J., and J. F. Monahan. 1977. Computer generation of random variables using the ratio of uniform deviates. Association for Computing Machinery Transactions on Mathematical Software 3: 257-260.

------. 1980. New methods for generating Student's t and gamma variables. Computing 25: 369-377.

Knuth, D. 1998. The Art of Computer Programming, Volume 2: Seminumerical Algorithms. 3rd ed. Reading, MA: Addison Wesley.

Marsaglia, G., M. D. MacLaren, and T. A. Bray. 1964. A fast procedure for generating normal random variables. Communications of the ACM 7: 4-10.

Schmeiser, B. W., and A. J. G. Babu. 1980. Beta variate generation via exponential majorizing functions. Operations Research 28: 917-926.

Schmeiser, B. W., and R. Lal. 1980. Squeeze methods for generating gamma variates. Journal of the American Statistical Association 75: 679-682.

Walker, A. J. 1977. An efficient method for generating discrete random variables with general distributions. ACM Transactions on Mathematical Software 3: 253-256.

Also see

Manual: [D] functions

Help: [D] drawnorm, [D] egen


© Copyright 1996–2009 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index