/* 
   Hypothesys testing routines
   Andrei Zorine,2002 <zoav1@uic.nnov.ru>
*/

/* Stub: ChiSquare's CDF is computed as IncompleteGamma(x,dof/2)/Gamma(dof/2); */

100 # ChiSquareTest( observed'freqs_IsList, expected'freqs_IsList, estimated'params_IsInteger)
  <--
 [
   Local( nominator, chi2, p'value, k, dof);
   k:=Length(observed'freqs);
   nominator:=(observed'freqs-expected'freqs)^2; //threading
   chi2:=Sum(i,1,k,nominator[i]/(expected'freqs[i]));
   dof := k-estimated'params-1; // degrees of freedom
   p'value:=1-N(IncompleteGamma(chi2/2,dof/2)/Gamma(dof/2)); 
   { TestStatistics <- chi2 , P'value <- p'value,Atom("dof") <- dof};

 ];


100 # ChiSquareTest( observed'freqs_IsList, 
	 expected'freqs_IsList) <-- ChiSquareTest( observed'freqs, expected'freqs, 0);

