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

NAG CL Interface Introduction
Example description
/* nag_nonpar_test_friedman (g08aec) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.0, 2024.
 */

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

int main(void) {
  Integer exit_status = 0, i, ix, j, k, n;
  NagError fail;
  double fr, sig, *x = 0;

#define X(I, J) x[((I)-1) * n + (J)-1]

  INIT_FAIL(fail);

  printf("nag_nonpar_test_friedman (g08aec) Example Program Results\n");

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

  n = 18;
  k = 3;
  ix = k;
  if (!(x = NAG_ALLOC(ix * n, double))) {
    printf("Allocation failure\n");
    exit_status = -1;
    goto END;
  }
  for (i = 1; i <= ix; ++i)
    for (j = 1; j <= n; ++j)
      scanf("%lf", &X(i, j));

  printf("\nFriedman test\n");
  printf("\nData values\n");
  printf("\n   Group  Group  Group\n");
  printf("     1      2      3\n");
  for (j = 1; j <= 18; ++j) {
    for (i = 1; i <= 3; ++i)
      printf("%7.1f", X(i, j));
    printf("\n");
  }
  /* nag_nonpar_test_friedman (g08aec).
   * Friedman two-way analysis of variance on k matched
   * samples
   */
  nag_nonpar_test_friedman(k, n, x, n, &fr, &sig, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_nonpar_test_friedman (g08aec).\n%s\n", fail.message);
    exit_status = 1;
    goto END;
  }
  printf("\n");
  printf("%s%6.3f\n", "Test statistic       ", fr);
  printf("%s%6" NAG_IFMT "\n", "Degrees of freedom   ", k - 1);
  printf("%s%6.3f\n", "Significance         ", sig);
END:
  NAG_FREE(x);
  return exit_status;
}