PyNGL Home > Functions > General applied math

Ngl.betainc

Evaluates the incomplete beta function.

Available in version 1.3.0 or later.

Prototype

alpha = Ngl.betainc(x, a, b)

Arguments

x

Numpy or masked array representing upper limit of integration. x must be [0,1].

a

First beta distribution parameter; must be > 0.0, and the same dimensionality as x.

b

Second beta distribution parameter; must be > 0.0, and the same dimensionality as x.

Return value

alpha

An numpy or masked array is returned (depending on type of x), of the same size as x. If x is a masked array, then alpha will contain missing values in the same locations.

Description

Ngl.betainc calculates the incomplete beta function. The incomplete beta function ratio is the probability that a random variable from a beta distribution having parameters a and b will be less than or equal to x. The code used is from SLATEC (http://www.netlib.org/slatec/fnlib/). This returns the same answers as the Numerical Recipes [Cambridge Univ. Press, 1986] function betai.

This function is often used to determine probabilities.

Examples

Example 1

 
import Ngl

a = 0.5
b = 5.0
x = 0.2

alpha = Ngl.betainc(x,a,b) 
print "alpha(x,a,b) = ",alpha

x = 0.5
alpha = Ngl.betainc(x,a,b) 
print "alpha(x,a,b) = ",alpha
The result is:
alpha(x,a,b) =  [ 0.85507239]
alpha(x,a,b) =  [ 0.98988044]

Example 2

This function can be used as a p-Value calculator for the Student t-test. Let's say a calculation has been made where the degrees-of-freedom (df=20) and a Student-t value of 2.08 has been determined. A probability level may be determined via:

import Ngl

df   = 20 
tval = 2.08  
prob = Ngl.betainc( df/(df+tval^2), df/2.0, 0.5)
print "prob=",prob

The result is prob = 0.0506. This is a two-tailed probability. The one-tailed probability is 0.5*prob = 0.0253.

For plotting, users often prefer to plot the quantity:

prob = (1.-Ngl.betainc(x,a,b))*100.  ; probability in %