Re: How to compute Beta variates
Hi ! Thanks a lot for all your help, folks. I solved the problem with all your help. Was surprised to get so much answers. Again, thank you Bye Michael Bals = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ =
RE: How to compute Beta variates
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of MIchael Bals Sent: Friday, January 11, 2002 7:15 AM To: [EMAIL PROTECTED] Subject: How to compute Beta variates Hi ! I am new to this group, so I hope you haven't been bothered too often with such questions. I looked in the group but didn't really find anything. I want to compute the inverse of the beta distribution in VB. I know that there is no closed form for it. I tried to translate the AS109 Algo. from StatLib but don't know how to get the log of the complete beta distribution that is needed for it. perhaps someone can help me out here. Are there any other ways to get variates from beta distribution for ONE specific x~U(0,1)? I need them for Latin Hypercube sampling and as far as I understood I need the inverse of any distribution I am sampling in order to use LHS. I am also looking for inverse methods for the gamma, possion, binomial distributions or any approximation to them A lot of questions...hope someone can help. Bye Michael Bals - I was waiting for all the experts who know a lot more than me about doing this. 1. The basic distributions in mathematical form are given in Abramowitz. Just about everybody who provides packaged programs to calculate distributions, relies on this source. There are also a number of approximation (polynomials) methods developed in Fortran from the 60's on, when computers were large and slow. With the advent of small fast computers, the solutions using infinite series (i.e. Abramowitz) are fast enough to give accurate results, if special algorithms are used for p values close to zero or one. It is the tails of these distributions that present underflow/overflow/error problems using IEEE 64 bit double precision floating point numbers. Fortran 90 has a method of doing computations in 128 bit floating point numbers, but this is in software, and as a result is very slow. The 128 bit machine language arithmetic functions were never incorporated in VB, even up to the .NET version. I tried building some 128 bit arithmetic functions, but did not get anywhere. One of the problems was that VB does not have the "assembly level" building capability that C++ has. Fortran programs can be easily translated to VB, if you know enough about both languages. 2. The inverse has traditionally been computed by looping, using Newton's method, since the density of the distribution is the derivative of the cumulative function. It is fast and works if the density if "smooth". Some of the software packages use different infinite series (or approximations) depending on the values of the parameters. When these are combined, the discontinuities will give closure problems and inaccurate results. The beta distribution in EXCEL is like this. 3. A common element in these distributions is the factorial function. The general approach is to use an infinite series to calculate the log of the factorial function. Equations 6.1.34 and 6.1.48 in Abramowitz are examples. Equation 6.2.2 defines the Beta function, and the log(Beta) can be directly calculated from the logs of the factorials. These equations work for real, floating point numbers. To obtain the beta function, test the log values for the allowable exponential range and do an EXP(logBeta). This will give you values within the 10^+308 to 10^-308 range of a double precision number. 4. In general, random numbers from these distributions are obtained by getting a good random number from a generator (that passes the die-hard tests), computing the inverse of the cumulative distribution for a "true" random deviate. This is slow, and there have been several approaches to directly calculate a random deviate that is a close approximation to a "true" random deviate. Methods for the normal and gamma distribution have been developed, to give fast values suitable for Monte Carlo studies. 5. I did most of my work on distributions and inverses in tha mid 1980's, starting on a Honeywell mainframe back in the late 70's, so I may not be familiar with recent developments in this century. DAHeiser = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ = = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ =
Re: How to compute Beta variates
In article <[EMAIL PROTECTED]>, MIchael Bals <[EMAIL PROTECTED]> wrote: >Hi ! >I am new to this group, so I hope you haven't been bothered too often >with such questions. I looked in the group but didn't really find >anything. >I want to compute the inverse of the beta distribution in VB. I know >that there is no closed form for it. I tried to translate the AS109 >Algo. from StatLib but don't know how to get the log of the complete >beta distribution that is needed for it. perhaps someone can help me >out here. >Are there any other ways to get variates from beta distribution for >ONE specific x~U(0,1)? I need them for Latin Hypercube sampling and as >far as I understood I need the inverse of any distribution I am >sampling in order to use LHS. >I am also looking for inverse methods for the gamma, possion, binomial >distributions or any approximation to them >A lot of questions...hope someone can help. It is rare that one generates uniform random variables by inverting the cdf; one place where this should be done, although one can still do better, if when using what are called quasi-random numbers, which have excellent approaches to the cdf, but no independence. These methods do not get one output variable for one input variable, but are usually fairly simple. There are lots of books, articles, and computer programs for such generation. Most of the major packages have them available, although they may not be very good, mainly because the uniform input is likely to have poor independence properties. -- This address is for information only. I do not claim that these views are those of the Statistics Department or of Purdue University. Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399 [EMAIL PROTECTED] Phone: (765)494-6054 FAX: (765)494-0558 = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ =
Re: How to compute Beta variates
MIchael Bals wrote in message ... >Hi ! > >I am new to this group, so I hope you haven't been bothered too often >with such questions. I looked in the group but didn't really find >anything. > >I want to compute the inverse of the beta distribution in VB. I know >that there is no closed form for it. I tried to translate the AS109 >Algo. from StatLib but don't know how to get the log of the complete >beta distribution that is needed for it. perhaps someone can help me >out here. > >Are there any other ways to get variates from beta distribution for >ONE specific x~U(0,1)? I need them for Latin Hypercube sampling and as >far as I understood I need the inverse of any distribution I am >sampling in order to use LHS. > >I am also looking for inverse methods for the gamma, possion, binomial >distributions or any approximation to them > >A lot of questions...hope someone can help. > >Bye >Michael Bals Take random_beta from my package random.f90 at my ozemail web site. It is fairly short, and in Fortran, but it should be easy to understand and translate into any language of your choice. Cheers P.S. There is a similar package in both Fortran & C from the University of Austin, Texas, USA. There are links to it from both my web site and statlib. My package is also available in Delphi. -- Alan Miller (Honorary Research Fellow, CSIRO Mathematical & Information Sciences) http://www.ozemail.com.au/~milleraj http://users.bigpond.net.au/amiller/ = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ =
Re: How to compute Beta variates
If I understand your question correctly, you can get what you want using SPSS. The distributions you mention are available. There are also many others. new file. * this program generates 200 cases for each of 3 distributions. * for each distribution it computes * a random value, x * the value associated with .05 probability (critical value), q * the probability associated with the random value p * the two parameters for the beta distribution must be greater than 0. input program. loop #i = 1 to 200. compute x_uni = rv.uniform(0,1). compute q_x_uni = idf.uniform(.05,0,1). compute p_x_uni = cdf.uniform(x_uni, 0, 1). compute x_nor = rv.normal(0,1). compute q_x_nor = idf.normal(.05,0,1). compute p_x_nor = cdf.normal(x_nor, 0, 1). compute x_bet = rv.beta(1,1). compute q_x_bet = idf.beta(.05,1,1). compute p_x_bet = cdf.beta(x_bet, 1, 1). end case. end loop. end file. end input program. formats x_uni q_x_uni p_x_uni x_nor q_x_nor p_x_nor x_bet q_x_bet p_x_bet (f6.3). execute. cache. MIchael Bals wrote: > Hi ! > > I am new to this group, so I hope you haven't been bothered too often > with such questions. I looked in the group but didn't really find > anything. > > I want to compute the inverse of the beta distribution in VB. I know > that there is no closed form for it. I tried to translate the AS109 > Algo. from StatLib but don't know how to get the log of the complete > beta distribution that is needed for it. perhaps someone can help me > out here. > > Are there any other ways to get variates from beta distribution for > ONE specific x~U(0,1)? I need them for Latin Hypercube sampling and as > far as I understood I need the inverse of any distribution I am > sampling in order to use LHS. > > I am also looking for inverse methods for the gamma, possion, binomial > distributions or any approximation to them > > A lot of questions...hope someone can help. > > Bye > Michael Bals = Instructions for joining and leaving this list, remarks about the problem of INAPPROPRIATE MESSAGES, and archives are available at http://jse.stat.ncsu.edu/ =