GRASS Programmer's Manual  6.4.2(2012)
shapiro2.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include "local_proto.h"
00005 
00006 
00007 /* this is actually the Weisberg-Bingham stat. I need to
00008    OCR the constants and implment this correctly */
00009 
00010 double *shapiro_francia(double *x, int n)
00011 {
00012     static double y[2];
00013     double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
00014     int i;
00015 
00016     if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
00017         fprintf(stderr, "Memory error in shapiro_francia\n");
00018         exit(EXIT_FAILURE);
00019     }
00020 
00021     for (i = 0; i < n; ++i)
00022         xcopy[i] = x[i];
00023 
00024     qsort(xcopy, n, sizeof(double), dcmp);
00025 
00026     for (i = 0; i < n; ++i) {
00027         z = xinormal((i + 1 - 0.375) / (n + 0.25));
00028         suma += z * xcopy[i];
00029         sumb += z * z;
00030         sumc += xcopy[i];
00031         sumd += xcopy[i] * xcopy[i];
00032     }
00033 
00034     y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
00035 
00036 #ifdef NOISY
00037     fprintf(stdout, "  TEST14 SF(N)  =%10.4f\n", y[0]);
00038 #endif /* NOISY */
00039 
00040     free(xcopy);
00041 
00042     return y;
00043 }                               /* test14_ */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines