/* Wilcoxon rank sum test (two-sample nonparametric) */ /* Normal approximation of test statistic */ /* Hodges-Lehmann estimator of difference between sample means (medians) */ /* HL-like nonparametric confidence interval for same */ #include #include #include #include "statlib.h" #define PROG_DATE "January 31, 2007" #define OUTPUT_NAME "twosamps_ranks.txt" #define MAXMN 500 /* Enough for mm, nn, mm+nn, and mm*nn */ /* First sample */ int mm=9; double xx[20] = { 23, 21, 22, 14, 23, 19, 15, 15, 16 }; /* Second sample */ int nn=14; double yy[20] = { 27, 27, 22, 21, 27, 28, 19, 20, 31, 24, 21, 23, 23, 21 }; /* Arrays for the two samples together */ double ww[MAXMN], mrank[MAXMN], mrankx[MAXMN], mranky[MAXMN]; /* Tie-group sizes */ int tgsize[MAXMN]; /* Which sample and which tiegroup */ char type[MAXMN], tgname[MAXMN]; int main(void) { int i,j,k,n, r,g,nmn, ntiegroups, nmwdifs,degfree; double sum, tiesum,tiecorr, Wval,WExpMean,varnotc,vartc; double wmed, zznotc,zztc, pval,pvalwrs, xbar,ybar,zbar; int cc1,cc2, m1,m2; double w1,w2; double sx1,sy1, sspool,tt, ttstderr,twid; printf ("\nIllustrating nonparametric two-sample methods:\n"); printf ("(Wilcoxon rank sum and allied procedures - %s.)\n", PROG_DATE); printf ("(This is %s on the Ma408 Web site.)\n", OUTPUT_NAME); /* Display the 1st sample */ printf ("\nSample I (m=%d):\n", mm); for (i=0; iww[j]) { char cc; double temp=ww[i]; ww[i]=ww[j]; ww[j]=temp; cc=type[i]; type[i]=type[j]; type[j]=cc; }} /* Now find midranks */ for (g=r=0; r1) n++; printf ("%d tiegroups with more than one tied value\n", n); /* Apportion midranks back to the two samples: */ i=j=0; for (k=0; k0 && (i%16)==0) printf("\n"); printf (" %g%s", ww[i], (starred) ? "(*)" : ""); } printf ("\n"); /* For a comparison, find the Student-t 95% confidence interval: */ /* Find pooled variance estimator */ sum=0.0; for (i=0; i