Cumulative Beta Distribution Function Help

#1
Hi everyone,

I was wondering if someone could help me figure out how this function works. My problem is not that I need homework help, it's that I've never done any stats homework! So, I'm absolutely clueless.

My problem is that I've been using the BETADIST function in a Microsoft Excel worksheet, and now I'm creating an application program in another programming language that doesn't have access to the BETADIST function, so I, in essence, need to recreate that function. And, in order to do that, I need to know what it's doing behind the scenes.

So, in Excel, I type in the function "=BETADIST(0.2, 1.57, 2, 0, 1)", and it gives me the value 0.1803. From reading about this function in Excel, the BETADIST function returns the cumulative beta probability density function, and is in the following format:

=BETADIST (x, alpha, beta, lower bound to x, upper bound to x), where, in my example, x = 0.2, alpha = 1.57, beta = 2, lower bound = 0, and upper bound = 1.

So, assuming I have my values of x, alpha, beta, and lower bound is always 0 and upper bound is always 1, how can I derive that value of 0.1803?

I've looked on wikipedia at the formulas, and they are absolute greek to me, so I need a good lesson, if anybody would be willing to give me one. Can anyone help illustrate for me how that BETADIST function derived the value of 0.1803, given x = 0.2, alpha = 1.57, and beta = 2?

Many thanks in advance,
Mark
 

Dragan

Super Moderator
#2
Hi everyone,

how that BETADIST function derived the value of 0.1803, given x = 0.2, alpha = 1.57, and beta = 2?

Many thanks in advance,
Mark

Like this:

\(f\left ( x \right )=\frac{\left ( 1-x \right )^{\beta -1}x^{\alpha -1}\Gamma \left ( \alpha +\beta \right )}{\Gamma \left ( \alpha \right )\Gamma \left ( \beta \right )}\)

and then integrate:

\(\int_{0}^{0.2}f\left ( x \right )dx=0.180283...\).
 
#3
Hi Dragan,

Thank you so much for your reply with the appropriate formulas to use. I’m trying to work it out, but I haven’t done calculus, trig, algebra, or whatever that is in 15 years… ha ha!

And to further illustrate how little I know about that formula, I had to look up what the “half T” was and found that it was the symbol for the Greek letter Gamma, which I assume represents the gamma function?

Please bear with me, as I really have no idea how to do an integral or any of this stuff. So, if you could help walk me through it, I’d really appreciate it. Here’s how far I’ve been able to get:

\(
f\left ( 0.2\right )=\frac{\left (0.8\right )1.4845 \Gamma \left (3.57 \right )}{\Gamma \left (1.57 \right ) \Gamma \left (2 \right )}
\)

First off, is that correct so far? And if so, what steps should I take next? Sorry my response took so long, but it took me awhile to figure out how to write the equation in a postable format... then I discovered the \( tags. I'm learning all kinds of new things!

Thanks again for your help.\)
 

Dason

Ambassador to the humans
#4
It's great that you want to program this yourself and all. However it's not the easiest task. You mention that you're using another programming language but you don't mention which one. It's very likely that there is already a library you could call that would give you what you're looking for already.

No use in reinventing the wheel.
 
#5
Sorry about that, I'll be happy to provide some additional details about my application and would certainly be up for using a library or some other method to get the right answer if I can find one or if you know of one I can use. Problem is, I haven't been able to find one yet.

My application is developed using Oracle Application Express 4.0.0.00.46 and uses an Oracle 10g database (10.2.0.4.0), which uses PL/SQL as its programming language. I think the BETADIST libraries are accessible using VB, C++, C#, or some other Microsoft programming language, but I haven't been able to find out how to access anything like those with Oracle. The two don't usually play well together.

And, the only Oracle function I've found that remotely comes close is the CUME_DIST() function, which calculates the cumulative distribution of a value in a group of values. It gives me results like the following, which I'm not sure if it relates to what I'm trying to find:

Code:
Year - Value - Cume_Dist
5       300    1.000
6       170    0.833
2       150    0.667
3       130    0.500
1       100    0.333
4       70     0.167
If you know of anything out there I can use, please let me know.

Thanks!
 

Dason

Ambassador to the humans
#6
I guess I can't help you there. If it was a different language I might be to help. Is there a built in numerical integration function or would you have to program that yourself? Does it have the Gamma function available to you?
 
#7
Just wanted to provide an update to this thread. Someone was able to provide me with some Visual Basic code on an Excel message board that replicated the BETADIST() function in Excel, and I was able to convert that code into Oracle PL/SQL, and it works perfectly!

Thanks again for everyone's help,
Mark
 

Dason

Ambassador to the humans
#10
Looks like you have to implement the numeric integration yourself then eh? It's not that big of a pain but that's why I was asking about it before because it's basically all integration.
 
#11
Yep, to answer your question from before... There aren't any built-in integration or Gamma functions in Oracle, so the whole thing had to basically be written. Although, I did find some Java libraries that could have been called from Oracle and might have helped. But, that was after I got this working... So, I think I'll just use this... ha ha! I like having it this way, anyway. Seeing the entire function helps me understand it better, and I can tweak whatever I want, if the need arises.
 
#13
Sorry, but I have not written a solution for MS SQL Server 2008. In one of my posts below, you'll find a link to the MrExcel forum where I posted the approximate solution in Oracle PL/SQL. There is also an approximate solution in that forum for MS VBA. You can derive the logic from each of those and translate into SQL Server.

Or, also in the MrExcel forum, there's a link to an Oracle forum where a Java library is available that computes this function. I actually ended up installing that Java library and using it. Although I don't know how to set it up, I'm pretty sure Java can be utilized by MS SQL Server 2008 as well, so I would suggest installing that Java library and calling the function from there.

Thanks.
 
#14
Hi idkstats14,

Your post could be a saver for me...can you pls help me with the code you came up with for the Oracle PL/SQL code for the calculus equivalent? I am having a tough time since I need to implement the P value formula in an Oracle/ Pl-sql solution.

P Value = [ 1/ ( (√df) Β(1/2,df/2) ) ] lt->-t to t ∫ ( 1+ x²/df)(-(v+1)/2) .dx
Where df = degrees of freedom x = T-Value

Your help is MOST APPRECIATED!
Thanks