#include #include #include #include #include double chi(nsam,gams,na,freq,nlocs, config, ran_ind, expected) int nsam, *gams, na, *freq, *config, *ran_ind, nlocs ; double **expected; { int *freq1, i,j,loc, jstart ; double sum=0., dif; if( na < 2 ) return( 0.0 ); freq1 = (int *) malloc( (size_t)na*sizeof(int) ); for( loc=jstart=0; loc 0.0 ) sum += (double)(dif*dif)/expected[loc][i] ; } } free( freq1 ); return( sum ) ; } double permchi(nperms,nsam,nlocs,ni,dij,pnum,pht,pchi) int nperms,nlocs,nsam, *ni, *pnum ; double **dij, *pht, *pchi ; { int i, count, countks, loc, start, zero=0, numalleles ; double ht, hetero(), chio, chir, **expected, chi(), eps = 1.0e-8, calcexp() ; int *ran_ind, *gams, *frequ ; if( ( gams = (int *) malloc( (size_t)nsam*sizeof(int) ) ) == NULL) perror( "malloc error5\n") ; if( ( frequ = (int *) malloc( (size_t)nsam*sizeof(int) ) ) == NULL) perror( "malloc error5\n") ; if( (ran_ind = (int *) malloc( (size_t)nsam*sizeof(int) )) == NULL) perror( "malloc error9\n") ; for(i=0;i= chio ) countks++ ; } free( ran_ind); free( gams ) ; free( frequ ) ; for( i=0; i 2 ){ if( (tdij = (double **)malloc((size_t)nsam*sizeof( double * ) ) ) == NULL) perror( "malloc error2\n") ; for(i=0;i 0 ; i--){ j = ran1()*(i + 1) ; temp = ran_vect[j]; ran_vect[j] = ran_vect[i] ; ran_vect[i] = temp ; } } double ran1() { double drand48(); return( drand48() ); }