StatBean Name: Distributions

Purpose: Computes probabilities and generates random numbers for many probability distributions.

DataSource: None.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
distributionNameString[nDists]Name of distribution.From list below."Normal"
nDistsintNumber of distributions entered.1-251
parameter1double[nDists]First parameters for the distribution.Valid parameter.0.0
parameter2double[nDists]Second parameters for the distribution.Valid parameter.1.0
parameter3double[nDists]Third parameters for the distribution.Valid parameter.0.0

Other Public Methods
NameDescriptionArgumentsReturn Value
void calculateStatistics()Causes the function to calculate the desired distributions.None.None.
double getCdf(double x,int k)Computes cumulative distribution function.Value of random variable x, distribution number.cdf at x.
double getInverseCdf(double p,int k)Computes inverse cumulative distribution function.Value of cdf p, distribution number.Smallest value of x for which cdf is less than or equal to p.
double getMean(int k)Returns the mean of the distribution.Distribution number.Mean.
double getPdf(double x,int k)Computes probability density or mass function.Value of random variable x, distribution number.pdf or pmf at x.
boolean getRandomNumbers(double x[],int n,int k)Generates n random numbers from the distribution, distribution number.Output array,number of random numbers to be generated.true if success
double getVariance(int k)Returns the variance of the distribution.Distribution number.Variance.

Available Discrete Distributions
NameRange of XParametersRestrictionsMean
Bernoulli0,1probability p0<=p<=1p
Binomial0,1,...,nprobability p,
sample size n
n>=1,
0<=p<=1
np
Discrete Uniforma,a+1,...,blower limit a,
upper limit b
a<=b(a+b)/2
Geometric0,1,2,...probability p1>=p>0(1-p)/p
Hypergeometric0,1,...,min(m,n)number of successes m,
sample size n,
population size N
N>=m>=0,
N>=n>=1
mn/N
Negative Binomialk,k+1,...probability p,
number of successes k
1>=p>0,
k>0
k/p
Poisson0,1,2,...mean lambdalambda>0lambda

Available Continuous Distributions
NameRange of XParametersRestrictionsMean
Beta0<=X<=1shape alpha1,
shape alpha2
alpha1>0,
alpha2>0
alpha1/(alpha1+alpha2)
Cauchyall real Xmedian theta,
shape beta
beta>0not defined
Chi-SquareX>=0degrees of freedom vv>0v
ErlangX>=0shape alpha,
scale lambda
integer alpha>=1,
lambda>0
alpha/lambda
ExponentialX>=0scale lambdalambda>01/lambda
Extreme Valueall real Xshape alpha,
scale beta
beta>0alpha-0.57721*beta
FX>=0num. d.f. v,
den. d.f. w
integer v>=1,
integer w>=1
w/(w-2)
GammaX>=0shape alpha,
scale lambda
alpha>0,
lambda>0
alpha/lambda
Laplaceall real Xmean mu,
scale lambda
lambda>0mu
(note: sigma=sqrt(2)/lambda)
Logisticall real Xmean mu,
std. dev. sigma
sigma>0mu
LognormalX>0mean mu,
std. dev. sigma
sigma>0exp(mu+sigma*sigma/2)
Normalall real Xmean mu,
std. dev. sigma
sigma>0mu
ParetoX>=1scale cc>0c/(c-1)
Student's tall real Xdegrees of freedom vv>=10
Triangulara<=X<=bminimum a,
mode c,
maximum b
a<=c<=b(a+b+c)/3
Uniforma<=X<=bminimum a,
maximum b
a<=b(a+b)/2
WeibullX>=0shape alpha,
scale beta
alpha>0,
beta>0
(beta*gamma(1/alpha))/alpha

Code Sample

//create a calculation bean
Distributions distributions1 = new STATBEANS.Distributions();

//set the number of distributions to be evaluated
distributions1.setNDists(2);

//define each distribution
distributions1.setDistributionName("Normal",0);
distributions1.setParameter1(50.0,0);
distributions1.setParameter2(10.0,0);
distributions1.setDistributionName("Lognormal",1);
distributions1.setParameter1(50.0,1);
distributions1.setParameter2(20.0,1);

//set up a table to display probabilities
DistributionsTable distributionsTable1 = new STATBEANS.DistributionsTable();

//define values for which probabilities are desired
double x[]=new double[6];
x[0]=10.0;
x[1]=20.0;
x[2]=30.0;
x[3]=40.0;
x[4]=50.0;
x[5]=60.0;
distributionsTable1.setValues(x);

//add the table to the display
add(distributionsTable1);

//create a plot bean
DistributionsPlot distributionsPlot1 = new STATBEANS.DistributionsPlot();

//add the plot to the display
add(distributionsPlot1);

//make the table and plot beans listeners for changes in the calculation bean
distributions1.addDataChangeListener(distributionsTable1.listenerForDataChange);
distributions1.addDataChangeListener(distributionsPlot1.listenerForDataChange);

//instruct the calculation bean to compute the probabilities
distributions1.calculateStatistics();