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

NAG CL Interface Introduction
Example description
/* nag_univar_robust_1var_trimmed (g07ddc) Example Program.
 *
 * Copyright 2024 Numerical Algorithms Group.
 *
 * Mark 30.2, 2024.
 *
 */

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

#define NMAX 1000
int main(void) {

  /* Local variables */
  Integer exit_status = 0, i, k, n;
  NagError fail;
  double alpha, propn, *sx = 0, tmean, tvar, wmean, wvar, *x = 0;

  INIT_FAIL(fail);

  printf("nag_univar_robust_1var_trimmed (g07ddc) Example Program Results\n\n");
  /* Skip heading in data file */
  scanf("%*[^\n] ");
  scanf("%" NAG_IFMT " ", &n);
  if (n >= 2) {
    if (!(x = NAG_ALLOC(NMAX, double)) || !(sx = NAG_ALLOC(NMAX, double))) {
      printf("Allocation failure\n");
      exit_status = -1;
      goto END;
    }
  } else {
    printf("Invalid n.\n");
    exit_status = 1;
    return exit_status;
  }
  for (i = 1; i <= n; ++i)
    scanf("%lf ", &x[i - 1]);
  scanf("%lf ", &alpha);

  /* nag_univar_robust_1var_trimmed (g07ddc).
   * Trimmed and winsorized mean of a sample with estimates of
   * the variances of the two means
   */
  nag_univar_robust_1var_trimmed(n, x, alpha, &tmean, &wmean, &tvar, &wvar, &k,
                                 sx, &fail);
  if (fail.code != NE_NOERROR) {
    printf("Error from nag_univar_robust_1var_trimmed (g07ddc).\n%s\n",
           fail.message);
    exit_status = 1;
    goto END;
  }

  propn = (double)k / n;
  propn = 100.0 - propn * 200.0;
  printf("Statistics from middle %6.2f%% of data\n\n", propn);
  printf("               Trimmed-mean = %11.4f\n", tmean);
  printf("   Variance of Trimmed-mean = %11.4f\n\n", tvar);
  printf("            Winsorized-mean = %11.4f\n", wmean);
  printf("Variance of Winsorized-mean = %11.4f\n", wvar);
END:
  NAG_FREE(x);
  NAG_FREE(sx);
  return exit_status;
}