/* nag_anderson_darling_uniform_prob (g08cjc) Example Program. * * Mark 23 Release. NAG Copyright 2011. */ #include #include #include #include #include #include int main(void) { /* Scalars */ Integer exit_status = 0, i, n; double a2, mu, p; /* Arrays */ double *x = 0, *y = 0; /* Nag types */ Nag_Boolean issort; NagError fail; printf("%s\n\n", "nag_anderson_darling_uniform_prob (g08cjc) Example Program Results"); /* Skip heading in data file */ scanf("%*[^\n] "); /* Read number of observations and parameter value */ scanf("%"NAG_IFMT "", &n); scanf("%lf", &mu); scanf("%*[^\n] "); /* Memory allocation */ if (!(x = NAG_ALLOC((n), double)) || !(y = NAG_ALLOC((n), double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Read observations */ for (i = 0; i < n; i++) { scanf("%lf", x+i); } scanf("%*[^\n]"); /* PIT */ for (i = 0; i < n; i++) { y[i] = 1.0 - exp(-x[i]/mu); } /* Let nag_anderson_darling_uniform_prob (g08cjc) sort the uniform variates */ issort = Nag_FALSE; /* Calculate the Anderson-Darling goodness-of-fit test statistic and its probability for the case of uniformly distributed data */ INIT_FAIL(fail); /* nag_anderson_darling_uniform_prob (g08cjc) */ nag_anderson_darling_uniform_prob(n, issort, y, &a2, &p, &fail); /* Results */ printf("%s ", " H0: data from exponential distribution with mean"); printf("%f\n", mu); printf("%s ", " Test statistic, A-squared: "); printf("%f\n", a2); printf("%s ", " Upper tail probability: "); printf("%f\n", p); END: NAG_FREE(x); NAG_FREE(y); return exit_status; }