/* nag_dummy_vars (g04eac) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include #include int main (void) { char mean[2], type[2], weight[2]; double *b=0, *cov=0, df, *h=0, *p=0, *q=0, *rep, *res, rss, *se=0, tol; double *v=0, *com_ar=0, *wtptr=0, *wt=0, *x=0, *y=0; Integer i, *ifact=0, ip, irank, *isx=0, j, levels, m, n, tdq, tdx; Integer exit_status=0; Boolean svd; Nag_DummyType dum_type; NagError fail; Nag_IncludeMean mean_enum; INIT_FAIL(fail); Vprintf("g04eac Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld %ld %s %s %s", &n, &levels, type, weight, mean); if (*type == 'P') dum_type = Nag_Poly; else if (*type == 'H') dum_type = Nag_Helmert; else if (*type == 'F') dum_type = Nag_FirstLevel; else if (*type == 'L') dum_type = Nag_LastLevel; else if (*type == 'C') dum_type = Nag_AllLevels; else dum_type = (Nag_DummyType)-999; if (*mean == 'M') mean_enum = Nag_MeanInclude; else if (*mean == 'Z') mean_enum = Nag_MeanZero; else mean_enum = (Nag_IncludeMean)-999; if (dum_type == Nag_AllLevels) tdx = levels; else tdx = levels - 1; if (!(x = NAG_ALLOC(n*tdx, double)) || !(rep = NAG_ALLOC(levels, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (dum_type == Nag_Poly) { if (!(v=NAG_ALLOC(levels, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { if (!(v=NAG_ALLOC(1, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } if (!(wt = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(ifact = NAG_ALLOC(n, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("\n"); if (*weight == 'W') { for (i = 1; i <= n; ++i) Vscanf("%ld %lf %lf", &ifact[i - 1], &y[i - 1], &wt[i - 1]); wtptr=wt; } else { for (i = 1; i <= n; ++i) Vscanf("%ld %lf", &ifact[i - 1], &y[i - 1]); wtptr = 0; } if (dum_type == Nag_Poly) for (j = 1; j <= levels; ++j) Vscanf("%lf", &v[j - 1]); /* Calculate dummy variables */ g04eac(dum_type, n, levels, ifact, x, tdx, v, rep, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g04eac.\n%s\n", fail.message); exit_status = 1; goto END; } m = tdx; ip = m; if (mean_enum == Nag_MeanInclude) ++ip; if (!(b=NAG_ALLOC(ip, double)) || !(se=NAG_ALLOC(ip, double)) || !(cov=NAG_ALLOC(ip*(ip+1)/2, double)) || !(p=NAG_ALLOC(2*ip + ip*ip, double)) || !(com_ar=NAG_ALLOC(5*(ip-1) + ip*ip, double)) || !(h=NAG_ALLOC(n, double)) || !(res=NAG_ALLOC(n, double)) || !(q=NAG_ALLOC(n*(ip+1), double)) || !(tdq = ip+1) || !(isx=NAG_ALLOC(m, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (j = 1; j <= m; ++j) isx[j - 1] = 1; /* Set tolerance */ tol = 1e-5; g02dac(mean_enum, n, x, tdx, m, isx, ip, y, wtptr, &rss, &df, b, se, cov, res, h, q, tdq, &svd, &irank, p, tol, com_ar, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g04dac.\n%s\n", fail.message); exit_status = 1; goto END; } if (svd) Vprintf(" %s%4ld\n\n", "Model not of full rank, rank = ", irank); Vprintf(" %s %12.4e\n", "Residual sum of squares = ", rss); Vprintf(" %s%4.0f\n\n","Degrees of freedom = ", df); Vprintf("%s\n\n", "Variable Parameter estimate Standard error"); for (j = 1; j <= ip; ++j) Vprintf(" %6ld %20.4e %20.4e\n", j, b[j - 1], se[j - 1]); END: if (x) NAG_FREE(x); if (rep) NAG_FREE(rep); if (v) NAG_FREE(v); if (v) NAG_FREE(v); if (wt) NAG_FREE(wt); if (y) NAG_FREE(y); if (ifact) NAG_FREE(ifact); if (b) NAG_FREE(b); if (se) NAG_FREE(se); if (cov) NAG_FREE(cov); if (p) NAG_FREE(p); if (com_ar) NAG_FREE(com_ar); if (h) NAG_FREE(h); if (res) NAG_FREE(res); if (q) NAG_FREE(q); if (isx) NAG_FREE(isx); return exit_status; }