/* nag_nonpar_gofstat_anddar_unif (g08cjc) Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
*
* Mark 28.4, 2022.
*/
#include <math.h>
#include <nag.h>
#include <stdio.h>
#include <string.h>
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_nonpar_gofstat_anddar_unif (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_nonpar_gofstat_anddar_unif (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_nonpar_gofstat_anddar_unif (g08cjc) */
nag_nonpar_gofstat_anddar_unif(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;
}