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

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

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

int main(void) {

  /* Scalars */
  double clevel, sum, tl, tu, xmean;
  Integer exit_status, i, ifreq, n, num;
  NagError fail;

  INIT_FAIL(fail);

  exit_status = 0;
  printf("nag_univar_ci_poisson (g07abc) Example Program Results\n");

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

  /* Read in the number of Noxious Seeds in a sub sample and
   * the frequency with which that number occurs.
   */

  /* Compute the sample mean */
  sum = 0.0;
  n = 0;
  while (scanf("%" NAG_IFMT "%" NAG_IFMT "%*[^\n] ", &num, &ifreq) != EOF)
  {
    sum += (double)num * (double)ifreq;
    n += ifreq;
  }
  xmean = sum / (double)n;

  printf("\n");
  printf("The point estimate of the Poisson parameter = %6.4f\n", xmean);
  for (i = 1; i <= 2; ++i) {
    if (i == 1) {
      clevel = 0.95;
      printf("\n");
      printf("95 percent Confidence Interval for the estimate\n");
    } else {
      clevel = 0.99;
      printf("99 percent Confidence Interval for the estimate\n");
    }
    /* nag_univar_ci_poisson (g07abc).
     * Computes confidence interval for the parameter of a
     * Poisson distribution
     */
    nag_univar_ci_poisson(n, xmean, clevel, &tl, &tu, &fail);
    if (fail.code != NE_NOERROR) {
      printf("Error from nag_univar_ci_poisson (g07abc).\n%s\n", fail.message);
      exit_status = 1;
      goto END;
    }

    printf("( %6.4f , %6.4f )\n", tl, tu);
    printf("\n");
  }

END:
  return exit_status;
}