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

NAG CL Interface Introduction
Example description
/* nag_nonpar_test_sign (g08aac) Example Program.
 *
 * Copyright 2021 Numerical Algorithms Group.
 *
 * Mark 27.3, 2021.
 */

#include <nag.h>
#include <stdio.h>

int main(void) {
  Integer exit_status = 0, i, n, non_tied, s;
  NagError fail;
  double p, *x = 0, *y = 0;

  INIT_FAIL(fail);

  printf("nag_nonpar_test_sign (g08aac) Example Program Results\n");

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

  n = 17;
  if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }

  for (i = 1; i <= n; i++)
    scanf("%lf", &x[i - 1]);

  for (i = 1; i <= n; i++)
    scanf("%lf", &y[i - 1]);

  printf("\n%s\n\n", "Sign test");
  printf("%s\n\n", "Data values");
  for (i = 1; i <= n; i++)
    printf("%3.0f%s", x[i - 1], i % n ? "" : "\n");
  printf("\n");

  for (i = 1; i <= n; i++)
    printf("%3.0f%s", y[i - 1], i % n ? "" : "\n");
  printf("\n");

  /* nag_nonpar_test_sign (g08aac).
   * Sign test on two paired samples
   */
  nag_nonpar_test_sign(n, x, y, &s, &p, &non_tied, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_nonpar_test_sign (g08aac).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }

  printf("%s%5" NAG_IFMT "\n", "Test statistic   ", s);
  printf("%s%5" NAG_IFMT "\n", "Observations     ", non_tied);
  printf("%s%5.3f\n", "Lower tail prob. ", p);
END:
  NAG_FREE(x);
  NAG_FREE(y);
  return exit_status;
}