/* nag_robust_m_estim_1var (g07dbc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * * Mark 6 revised, 2000. * Mark 8 revised, 2004. */ #include #include #include #include #include int main(void) { Integer exit_status=0, i, isigma, maxit, n, nit; NagError fail; Nag_SigmaSimulEst sigma_enum; char sigma_enum_str[20]; double c, dchi, h1, h2, h3, *rs=0, sigma, sigsav, *sorted_x=0, thesav, theta; double tol, *x=0; INIT_FAIL(fail); Vprintf("nag_robust_m_estim_1var (g07dbc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]\n"); Vscanf("%ld %*[^\n]\n",&n); if (n>1) { if ( !( x = NAG_ALLOC(n, double)) || !( rs = NAG_ALLOC(n, double)) || !( sorted_x = NAG_ALLOC(n, 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("%*[^\n]\n"); Vscanf("%lf %lf %lf %lf %ld %*[^\n]\n", &h1,&h2,&h3,&dchi,&maxit); Vprintf("%25sInput parameters Output parameters\n",""); Vprintf(" sigma_est sigma theta tol sigma theta\n\n"); while ((scanf("%ld %lf %lf %lf%*[^\n]", &isigma,&sigma,&theta,&tol)) != EOF) { if (isigma == 1) { sigma_enum = Nag_SigmaSimul; strcpy(sigma_enum_str, "Nag_SigmaSimul"); } else if (isigma == 0) { sigma_enum = Nag_SigmaBypas; strcpy(sigma_enum_str, "Nag_SigmaBypas"); } sigsav = sigma; thesav = theta; c = 0.0; /* nag_robust_m_estim_1var (g07dbc). * Robust estimation, M-estimates for location and scale * parameters, standard weight functions */ nag_robust_m_estim_1var(sigma_enum, n, x, Nag_HampelFun, c, h1, h2, h3, dchi, &theta, &sigma, maxit, tol, rs, &nit, sorted_x, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_robust_m_estim_1var (g07dbc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("%s %8.4f %8.4f %7.4f %9.4f %8.4f\n", sigma_enum_str, sigsav, thesav,tol,sigma,theta); } END: if (x) NAG_FREE(x); if (rs) NAG_FREE(rs); if (sorted_x) NAG_FREE(sorted_x); return exit_status; }