
SSJ V. 1.2.5. 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object umontreal.iro.lecuyer.gof.GofStat
public class GofStat
This class provides methods to compute several types of EDF goodnessoffit test statistics and to apply certain transformations to a set of observations. This includes the probability integral transformation U_{i} = F(X_{i}), as well as the power ratio and iterated spacings transformations. Here, U_{(0)},..., U_{(N1)} stand for N observations U_{0},..., U_{N1} sorted by increasing order, where 0 <= U_{i} <= 1.
Note: This class uses the Colt library.
Nested Class Summary  

static class 
GofStat.OutcomeCategoriesChi2
This class helps managing the partitions of possible outcomes into categories for applying chisquare tests. 
Field Summary  

static double 
EPSILONAD

Method Summary  

static double 
andersonDarling(DoubleArrayList sortedData)
Computes and returns the AndersonDarling statistic A_{N}^{2}. 
static double 
chi2(double[] nbExp,
int[] count,
int smin,
int smax)
Computes and returns the chisquare statistic for the observations o_{i} in count[smin...smax], for which the corresponding expected values e_{i} are in nbExp[smin...smax]. 
static double 
chi2(IntArrayList data,
DiscreteDistributionInt dist,
int smin,
int smax,
double minExp,
int[] m)
Computes and returns the chisquare statistic for the observations stored in data, assuming that these observations follow the discrete distribution dist. 
static double 
chi2Equal(DoubleArrayList data)
Equivalent to chi2Equal (data, 10). 
static double 
chi2Equal(DoubleArrayList data,
double minExp)
Computes the chisquare statistic for a continuous distribution. 
static double 
chi2Equal(double nbExp,
int[] count,
int smin,
int smax)
Similar to chi2 ,
except that the expected
number of observations per category is assumed to be the same for
all categories, and equal to nbExp. 
static double 
cramerVonMises(DoubleArrayList sortedData)
Computes and returns the Cramérvon Mises statistic W_{N}^{2}. 
static void 
diff(DoubleArrayList sortedData,
DoubleArrayList spacings,
int n1,
int n2,
double a,
double b)
Same as diff
for the continuous case. 
static void 
diff(IntArrayList sortedData,
IntArrayList spacings,
int n1,
int n2,
int a,
int b)
Assumes that the realvalued observations U_{0},..., U_{N1} contained in sortedData are already sorted in increasing order and computes the differences between the successive observations. 
static void 
iterateSpacings(DoubleArrayList data,
DoubleArrayList spacings)
Applies one iteration of the iterated spacings transformation. 
static double[] 
kolmogorovSmirnov(DoubleArrayList sortedData)
Computes the KolmogorovSmirnov (KS) test statistics D_{N}^{+}, D_{N}^{}, and D_{N}. 
static double[] 
kolmogorovSmirnovJumpOne(DoubleArrayList sortedData,
double a)
Compute the KS statistics D_{N}^{+}(a) and D_{N}^{}(a) defined in the description of the method FDist.kolmogorovSmirnovPlusJumpOne , assuming that F is the
uniform distribution over [0, 1] and that
U_{(1)},..., U_{(N)} are in sortedData. 
static double 
pDisc(double pL,
double pR)
Computes a variant of the pvalue p whenever a test statistic has a discrete probability distribution. 
static void 
powerRatios(DoubleArrayList sortedData)
Applies the power ratios transformation W. 
static int 
scan(DoubleArrayList sortedData,
double d)
Computes and returns the scan statistic S_{N}(d ), defined in FBar.scan . 
static DoubleArrayList 
unifTransform(DoubleArrayList data,
ContinuousDistribution dist)
Applies the transformation U_{i} = F(V_{i}) for 0 <= i < N, where F is a continuous distribution function, and returns the result as an array of length N. 
static DoubleArrayList 
unifTransform(DoubleArrayList data,
DiscreteDistribution dist)
Applies the transformation U_{i} = F(V_{i}) for 0 <= i < N, where F is a discrete distribution function, and returns the result as an array of length N. 
static double 
watsonG(DoubleArrayList sortedData)
Computes and returns the Watson statistic G_{N}. 
static double 
watsonU(DoubleArrayList sortedData)
Computes and returns the Watson statistic U_{N}^{2}. 
Methods inherited from class java.lang.Object 

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 

public static double EPSILONAD
Method Detail 

public static DoubleArrayList unifTransform(DoubleArrayList data, ContinuousDistribution dist)
data
 array of observations to be transformeddist
 assumed distribution of the observations
public static DoubleArrayList unifTransform(DoubleArrayList data, DiscreteDistribution dist)
Note: If V are the values of random variables with distribution function dist, then the result will contain the values of discrete random variables distributed over the set of values taken by dist, not uniform random variables over [0, 1].
data
 array of observations to be transformeddist
 assumed distribution of the observations
public static void diff(DoubleArrayList sortedData, DoubleArrayList spacings, int n1, int n2, double a, double b)
diff
for the continuous case.
sortedData
 array of sorted observationsspacings
 pointer to an array object that will be filled with spacingsn1
 starting index, in sortedData, of the processed observationsn2
 ending index, in sortedData of the processed observationsa
 minimum value of the observationsb
 maximum value of the observationspublic static void diff(IntArrayList sortedData, IntArrayList spacings, int n1, int n2, int a, int b)
The number of observations must be greater or equal than n2, we must have n1 < n2, and n1 and n2 are greater than 0. The size of spacings will be at least N + 1 after the call returns.
sortedData
 array of sorted observationsspacings
 pointer to an array object that will be filled with spacingsn1
 starting index, in sortedData, of the processed observationsn2
 ending index, in sortedData of the processed observationsa
 minimum value of the observationsb
 maximum value of the observationspublic static void iterateSpacings(DoubleArrayList data, DoubleArrayList spacings)
diff
.
This method transforms the spacings into new
spacings:
it sorts
S_{0},..., S_{N} to obtain
S_{(0)} <= S_{(1)} <= S_{(2)} <= ^{ ... } <= S_{(N)},
computes the weighted differences
S_{0}  =  (N + 1)S_{(0)},  
S_{1}  =  N(S_{(1)}  S_{(0)}),  
S_{2}  =  (N  1)(S_{(2)}  S_{(1)}),  
...  
S_{N}  =  S_{(N)}  S_{(N1)}, 
Under the assumption that the U_{i} are i.i.d. U(0, 1), the new S_{i} can be considered as a new set of spacings having the same distribution as the original spacings, and the V_{i} are a new sample of i.i.d. U(0, 1) random variables, sorted by increasing order.
This transformation is useful to detect clustering in a data set: A pair of observations that are close to each other is transformed into an observation close to zero. A data set with unusually clustered observations is thus transformed to a data set with an accumulation of observations near zero, which is easily detected by the AndersonDarling GOF test.
data
 array of observationsspacings
 spacings between the observations, will be filled with the new spacingspublic static void powerRatios(DoubleArrayList sortedData)
This transformation is useful to detect clustering, as explained in
iterateSpacings
,
except that here a pair of
observations close to each other is transformed
into an observation close to 1.
An accumulation of observations near 1 is also easily detected by
the AndersonDarling GOF test.
sortedData
 sorted array of realvalued observations in the interval [0, 1]
that will be overwritten with the transformed observationspublic static double chi2(double[] nbExp, int[] count, int smin, int smax)
nbExp
 number of expected observations in each category (or interval)count
 number of counted observations in each categorysmin
 index of the first valid data in count and nbExpsmax
 index of the last valid data in count and nbExp
public static double chi2(IntArrayList data, DiscreteDistributionInt dist, int smin, int smax, double minExp, int[] m)
Generally, it is not possible to divide the integers in intervals satisfying
nP(a_{0} <= s < a_{1}) = nP(a_{1} <= s < a_{2}) = ^{ ... } = nP(a_{j1} <= s < a_{j})
for a discrete distribution, where n is the sample size, i.e.,
the number of
observations stored into data.
To perform a general chisquare test, the method starts
from smin and finds the first nonnegligible
probability
p(s) >= ε, where
ε = DiscreteDistributionInt.EPSILON
.
It uses smax to allocate an array storing the
number of expected observations (np(s)) for each s >= smin.
Starting from s = smin, the np(s) terms are computed and
the allocated array grows if required until a negligible probability
term is found.
This gives the number of expected elements for
each category, where an outcome category corresponds here to
an interval in which sample observations could lie.
The categories are regrouped to have at least
minExp observations per category. If m is not
null, the first element of the array will be
set to the number of categories after regrouping.
The method then counts
the number of samples in each categories and calls
chi2
to get the chisquare test
statistic. We usually choose minExp = 10.
data
 observations, not necessarily sorteddist
 assumed probability distributionsmin
 estimated minimum value of s for which p(s) > 0smax
 estimated maximum value of s for which p(s) > 0minExp
 minimum number of expected observations in each
intervalm
 oneelement array that will be filled with the number of
categories after regrouping
public static double chi2Equal(double nbExp, int[] count, int smin, int smax)
chi2
,
except that the expected
number of observations per category is assumed to be the same for
all categories, and equal to nbExp.
nbExp
 number of expected observations in each category (or interval)count
 number of counted observations in each categorysmin
 index of the first valid data in count and nbExpsmax
 index of the last valid data in count and nbExp
public static double chi2Equal(DoubleArrayList data, double minExp)
chi2Equal
.
We usually choose minExp = 10.
data
 array of observations in [0, 1)minExp
 minimum number of expected observations in each subintervals
public static double chi2Equal(DoubleArrayList data)
data
 array of observations in [0, 1)
public static int scan(DoubleArrayList sortedData, double d)
FBar.scan
.
Let U be the N observations contained into sortedData.
The N observations in U[0..N  1] must be real numbers
in the interval [0, 1], sorted in increasing order.
(See FBar.scan
for the distribution function of S_{N}(d )).
sortedData
 sorted array of realvalued observations in the interval [0, 1]d
 length of the test interval (∈(0, 1))
public static double cramerVonMises(DoubleArrayList sortedData)
sortedData
 array of sorted realvalued observations in the interval [0, 1]
public static double watsonG(DoubleArrayList sortedData)
G_{N}  =  (N)^{1/2}max_{0 <= j <= N1}{(j + 1)/N  U_{(j)} + bar(U)_{N} 1/2}  
=  (N)^{1/2}(D_{N}^{+} + bar(U)_{N}  1/2), 
sortedData
 array of sorted realvalued observations in the interval [0, 1]
public static double watsonU(DoubleArrayList sortedData)
W_{N}^{2}  =  1/(12N) + ∑_{j=0}^{N1}{U_{(j)}  (j + 0.5)/N}^{2},  
U_{N}^{2}  =  W_{N}^{2}  N(bar(U)_{N} 1/2)^{2}. 
sortedData
 array of sorted realvalued observations in the interval [0, 1]
public static double andersonDarling(DoubleArrayList sortedData)
A_{N}^{2}  =   N  1/N ∑_{j=0}^{N1}{(2j + 1)ln(U_{(j)}) + (2N  1  2j)ln(1  U_{(j)})}, 
sortedData
 array of sorted realvalued observations in the interval [0, 1]
public static double[] kolmogorovSmirnov(DoubleArrayList sortedData)
D_{N}^{+}  =  max_{0 <= j <= N1}((j + 1)/N  U_{(j)}),  
D_{N}^{}  =  max_{0 <= j <= N1}(U_{(j)}  j/N),  
D_{N}  =  max (D_{N}^{+}, D_{N}^{}). 
These statistics compare the empirical distribution of U_{(1)},..., U_{(N)}, which are assumed to be in sortedData, with the uniform distribution.
sortedData
 array of sorted realvalued observations in the interval [0, 1]
public static double[] kolmogorovSmirnovJumpOne(DoubleArrayList sortedData, double a)
FDist.kolmogorovSmirnovPlusJumpOne
, assuming that F is the
uniform distribution over [0, 1] and that
U_{(1)},..., U_{(N)} are in sortedData.
Returns an array of length 2 that contains their values at positions
0 and 1, respectively.
sortedData
 array of sorted realvalued observations in the interval [0, 1]a
 size of the jump
public static double pDisc(double pL, double pR)
p_{L}  =  P[Y <= y]  
p_{R}  =  P[Y >= y] 
p =  p_{R},  if p_{R} < p_{L}, 
p =  1  p_{L},  if p_{R} >= p_{L} and p_{L} < 0.5, 
p =  0.5  otherwise. 
pL
 left pvaluepR
 right pvalue

SSJ V. 1.2.5. 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 