View source: R/CompBetaVariate.R
CompBetaVariate | R Documentation |
This subroutine generates a beta random variable.
CompBetaVariate(Alpha, Beta)
Alpha |
alpha parameter of gamma |
Beta |
beta parameter of gamma |
EEH for testing purposes the original VB code was duplicated. This could have been replaced with rbeta(alpha,beta).
Original VB codes creates beta r.v. by using the gamma distribution Mean = alpha/(alpha+beta) Variance = (a*b)/((a+b)^2*(a+b+1)) TAB: not sure this is correct way of getting beta distr since Beta(a,b) = (Gamma(a)*Gamma(b))/(Gamma(a+b)) *********************************************** Function CompBetaVariate(Alpha As Double, Beta As Double) Dim G1 As Double Dim G2 As Double
If CONSTRUN = True Then CompBetaVariate = Alpha / (Alpha + Beta) 'expected value Else If Alpha <= 1 Then 'TAB: changed ALP to Alpha in this line G1 = Gam1(Alpha, 1) Else G1 = Gam2(Alpha, 1) End If
If Beta <= 1 Then 'TAB: changed BET to Beta in this line G2 = Gam1(Beta, 1) Else G2 = Gam2(Beta, 1) End If
CompBetaVariate = G1 / (G1 + G2) End If End Function
Beta distributed random variable (scalar)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.