home *** CD-ROM | disk | FTP | other *** search
- # include <math.h>
- # include <stdlib.h>
-
- void SortSumData(float *dataset,int numrow)
- {
- int j;
- int k;
- float TempX;
- char abort;
-
- if ( numrow <= 1 )
- return;
- for ( j = 0; j <= numrow - 1; ++j ) {
- abort = 0;
- TempX = dataset[j];
- k = j - 1;
- while ( ! (abort) && (k >= 0) ) {
- if ( TempX < dataset[k] ) {
- dataset[k + 1] = dataset[k];
- k = k - 1;
- }
- else {
- abort = 1;
- }
- }
- dataset[k + 1] = TempX;
- }
- }
-
- void CalculateMode(float *dataset, int numrow, float *mode)
- {
- char Even;
- int Num;
-
- Even = 1;
- if ( numrow % 2 != 0 ) {
- Even = 0;
- }
- SortSumData(dataset,numrow);
- if ( Even ) {
- Num = numrow / 2;
- (*mode) = (dataset[Num] + dataset[Num + 1]) / 2;
- }
- else {
- Num = numrow / 2 ;
- (*mode) = dataset[Num];
- }
- }
-
- void SumMinMax( float *dataset,int numdat,float *minval,
- float *maxval, float *range)
- {
- int i;
-
- (*minval) = dataset[0];
- (*maxval) = dataset[0];
- for ( i = 1; i <= numdat-1; ++i ) {
- if ( dataset[i] < (*minval) ) {
- (*minval) = dataset[i];
- }
- if ( dataset[i] > (*maxval) ) {
- (*maxval) = dataset[i];
- }
- }
- (*range) = (*maxval) - (*minval);
- }
-
- void MatMean(float *datary, int numrow, float *sumx,float *mean)
- {
- int i;
-
- (*sumx) = 0.0;
- for ( i = 0; i <= numrow-1; ++i ) {
- (*sumx) = (*sumx) + datary[i];
- }
- (*mean) = (*sumx) / numrow;
- }
-
- void MatStd(float *datary, float mean,int numrow,
- float *variance, float *stddev)
- {
- int i;
- int j;
- float xsqr;
-
-
- xsqr = 0.0;
- for ( i = 0; i <= numrow-1; ++i ) {
- xsqr = xsqr + datary[i]*datary[i];
- }
- (*variance) = (xsqr - numrow * mean*mean) / (numrow - 1);
- (*stddev) = sqrt(fabs((*variance)));
- }
-
- void SummaryStats(float *dataset, int numobs, int numcol,
- float *minima, float *maxima, float *range,
- float *sumxx, float *mean,float *variance,
- float *stddev, float *semean, float *mode)
- {
- int i;
- int j;
- float *tempv;
-
- tempv = (float *) calloc(numobs*4,4);
-
- for ( j = 0; j <= numcol-1; ++j ) {
- for ( i = 0; i <= numobs-1; ++i ) {
- tempv[i] = dataset[i*numcol+j];
- }
- CalculateMode(tempv,numobs,&mode[j]);
- SumMinMax(tempv,numobs,&minima[j],&maxima[j],&range[j]);
- MatMean(tempv,numobs,&sumxx[j],&mean[j]);
- MatStd(tempv,mean[j],numobs,&variance[j],&stddev[j]);
- semean[j] = stddev[j] / sqrt(numobs);
- }
- free(tempv);
- }