StatBean Name: FitDistribution

Purpose: Fits distributions to a column of data, computes probabilities, and generates random numbers.

DataSource: None.

Read/Write Properties
NameTypeDescriptionPossible ValuesDefault Value
origindoubleOrigin of distribution (subtracted from data before fitting distribution).Any double.0.0
distributionNameString[nDists]Name of distribution.From list below."Normal"
minimumFrequencydoubleMinimum class frequency for chi-squared test.>05.0
nDistsintNumber of distributions entered.1-251
numberOfSuccessesintNumber of successes for negative binomial distribution.1+10
populationSizeintSize of population for hypergeometric distribution.1+1000
sizeOfSamplesintSample size for binomial and hypergeometric distributions.1+100
xVariableNameString[nDists]The name of the column containing data to be fit, if any.Any string."X"

Other Public Methods
NameDescriptionArgumentsReturn Value
double getCdf(double x,int k)Computes cumulative distribution function.Value of random variable x, distribution number.cdf at x.
double getChiSquared(int k)Returns computed chi-squared test statistic.Distribution number.Calculated statistic.
double getChiSquaredDF(int k)Returns degrees of freedom for chi-squared test statistic.Distribution number.Degrees of freedom.
double getChiSquaredPValue(int k)Returns P-value for chi-squared test statistic.Distribution number.P-value.
double getKolmogorovSmirnovD(int k)Returns computed overall KS test statistic.Distribution number.Calculated statistic.
double getKolmogorovSmirnovDMinus(int k)Returns computed lower KS test statistic.Distribution number.Calculated statistic.
double getKolmogorovSmirnovDPlus(int k)Returns computed upper KS test statistic.Distribution number.Calculated statistic.
double getKolmogorovSmirnovPValue(int k)Returns P-value for overall KS test.Distribution number.P-value.
double getShapiroWilksPValue(int k)Returns P-value for Shapiro-Wilks test (for normal distribution only).Distribution number.P-value.
double getShapiroWilksW(int k)Returns computed Shpario-Wilks statictic (for normal distribution only).Distribution number.Calculated statistic.
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
int getSampleSize(int k)Returns the sample size used to fit the distribution.Distribution number.Sample size n, or 0 if no data supplied.
double getVariance(int k)Returns the variance of the distribution.Distribution number.Variance.

Available Distributions - see Distributions.

Code Sample

//create a datasource bean
FileDataSource fileDataSource1 = new STATBEANS.FileDataSource();

//set the file name to be read
fileDataSource1.setFileName("c:\\statbeans\\samples\\cardata.txt");

//create a calculation bean
FitDistribution fitdistribution1 = new STATBEANS.FitDistribution();

//set the column to be fit
fitdistribution1.setXVariableName("mpg");

//set the number and type of distributions to be fit
fitdistribution1.setNDists(3);
fitdistribution1.setDistributionName("Normal",0);
fitdistribution1.setDistributionName("Lognormal",1);
fitdistribution1.setDistributionName("Weibull",2);

//create a table bean
FitDistributionTable fitdistributiontable1 = new STATBEANS.FitDistributionTable();

//create a plot bean
FitDistributionPlot fitdistributionplot1 = new STATBEANS.FitDistributionPlot();

//add the beans to the display
add(fitdistributiontable1);
add(fitdistributionplot1);

//make the tabulation bean a listener for changes in the FileDataSource bean
fileDataSource1.addDataChangeListener(fitdistribution1.listenerForDataChange);

//make the other beans listeners for changes in the tabulation bean
fitdistribution1.addDataChangeListener(fitdistributiontable1.listenerForDataChange);
fitdistribution1.addDataChangeListener(fitdistributionplot1.listenerForDataChange);

//instruct the fileDataSource bean to read the file
fileDataSource1.readData();