/*
* Chi-square test
*/
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <ctype.h>
#include "config.h"
#include "gsl_types.h"
#include "gsl_rng.h"
#include "gsl_randist.h"
#pragma lib "libsys.a"
#pragma lib "libspecfunc.a"
#pragma lib "librng.a"
#pragma lib "librandist.a"
int chidf;
double chisq, probchisq;
Biobuf bin;
int help=0;
int verbose=0;
int proportions=0;
int help=0;
void intro(void);
int readparams();
void confid_int(void);
void t_test(void);
void t_test2(void);
void chi_square(void);
void results(void);
int
readparams(void)
// reads n1, N1, n2, N2 for two binomial samples, or, if -p, p1, N1, p2, N2
{
char *buf, *av[256], first;
int i, j, n;
Binit(&bin, 0, OREAD);
n=0;
while(n==0){
if((buf = Brdstr(&bin, '\n', 1)) == nil) return 0; // nothing to read
first=buf[0];
// print("first==%c\n", first);
n=tokenize(buf, av, 4);
if(n!=0){
// skip comment lines
if((first=='#') || (first=='>')){
// print("comments\n");
n=0;
}
}
else{
// skip whitespace lines
// print("whitespace\n");
}
} // ends up with n > 0
chisq=atof(av[0]);
chidf=atof(av[1]);
return 0;
} /* readparams */
void
chi_square(void) {
probchisq=gsl_ran_chisq_pdf(chisq, chidf);
} /* chi_square */
void
intro(void) {
print("Chi-square test\n");
print("please, give me chisq, and df, ");
print("whitespace separated on a single line\n");
} /* intro */
void
results(void) {
print("\n\nChi-square test\n\n");
print("chi-square = %f (has chi-squared-distribution with %d degrees of freedom)\n", chisq, chidf);
print("Associated probability P(x, df) = %e \n", probchisq);
} /* results */
void
main(int argc, char *argv[])
{
ARGBEGIN{
case 'h':
help = 1;
break;
case 'v':
verbose = 1;
break;
}ARGEND
if(verbose) intro();
readparams();
chi_square();
results();
} /* main */
|