NAG Library Manual, Mark 30
Interfaces:  FL   CL   CPP   AD 

NAG CL Interface Introduction
Example description
/* nag_nonpar_gofstat_anddar_normal (g08ckc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.0, 2024.
 */
#include <math.h>
#include <nag.h>
#include <stdio.h>
#include <string.h>

int main(void) {
  Integer exit_status = 0;
  /* Scalars */
  double a2, aa2, p, ybar, yvar;
  Integer i, n;
  /* Arrays */
  double *y = 0;
  /* Nag types */
  Nag_Boolean issort;
  NagError fail;

  printf("%s\n\n",
         "nag_nonpar_gofstat_anddar_normal (g08ckc) Example Program Results");

  /* Skip heading in data file */
  scanf("%*[^\n] ");

  /* Read number of observations */
  scanf("%" NAG_IFMT "", &n);
  scanf("%*[^\n] ");

  /* Memory allocation */
  if (!(y = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  /* Read observations */
  for (i = 0; i < n; i++) {
    scanf("%lf", y + i);
  }
  scanf("%*[^\n] ");

  /* Let nag_nonpar_gofstat_anddar_normal (g08ckc) sort the data */
  issort = Nag_FALSE;

  /* Calculate the Anderson-Darling goodness-of-fit test statistic and its
     probability for the case of a fully-unspecified Normal distribution */
  INIT_FAIL(fail);
  /* nag_nonpar_gofstat_anddar_normal (g08ckc) */
  nag_nonpar_gofstat_anddar_normal(n, issort, (const double *)y, &ybar, &yvar,
                                   &a2, &aa2, &p, &fail);

  /* Results */
  printf("%s ", "H0: data from Normal distribution with mean");
  printf("%6g ", ybar);
  printf("%s ", "and variance");
  printf("%6g\n", yvar);
  printf("%s", " Test statistic, A-squared: ");
  printf("%6g\n", a2);
  printf("%s", " Adjusted A-squared:        ");
  printf("%6g\n", aa2);
  printf("%s", " Upper tail probability:    ");
  printf("%6g\n", p);

END:
  NAG_FREE(y);

  return exit_status;
}