/* nag_robust_trimmed_1var (g07ddc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include #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); Vprintf("nag_robust_trimmed_1var (g07ddc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld ", &n); if (n>=2) { if ( !( x = NAG_ALLOC(NMAX, double)) || !( sx = NAG_ALLOC(NMAX, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 1; i <= n; ++i) Vscanf("%lf ", &x[i - 1]); Vscanf("%lf ", &alpha); /* nag_robust_trimmed_1var (g07ddc). * Trimmed and winsorized mean of a sample with estimates of * the variances of the two means */ nag_robust_trimmed_1var(n, x, alpha, &tmean, &wmean, &tvar, &wvar, &k, sx, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_robust_trimmed_1var (g07ddc).\n%s\n", fail.message); exit_status = 1; goto END; } propn = (double) k / n; propn = 100.0 - propn * 200.0; Vprintf("Statistics from middle %6.2f%% of data\n\n", propn); Vprintf(" Trimmed-mean = %11.4f\n", tmean); Vprintf(" Variance of Trimmed-mean = %11.4f\n\n", tvar); Vprintf(" Winsorized-mean = %11.4f\n", wmean); Vprintf("Variance of Winsorized-mean = %11.4f\n", wvar); END: if (x) NAG_FREE(x); if (sx) NAG_FREE(sx); return exit_status; }