/* nag_condl_logistic (g11cac) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double dev, tol; Integer iprint, exit_status, i, p, j, m, maxit, n, ns, pdz; NagError fail; Nag_OrderType order; /* Arrays */ double *b = 0, *cov = 0, *sc = 0, *se = 0, *z = 0; Integer *ic = 0, *isi = 0, *isz = 0, *nca = 0, *nct = 0; #ifdef NAG_COLUMN_MAJOR #define Z(I, J) z[(J-1)*pdz + I - 1] order = Nag_ColMajor; #else #define Z(I, J) z[(I-1)*pdz + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); exit_status = 0; fprintf(fpout, "nag_condl_logistic (g11cac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%ld%ld%ld%*[^\n] ", &n, &m, &ns, &maxit); pdz = n; iprint = 0; tol = 1e-5; /* Allocate arrays z, ic, isi and isz */ if (!(z = NAG_ALLOC(pdz * m, double)) || !(ic = NAG_ALLOC(n, Integer)) || !(isi = NAG_ALLOC(n, Integer)) || !(isz = NAG_ALLOC(m, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } if (order == Nag_ColMajor) pdz = n; else pdz = m; for (i = 1; i <= n; ++i) { fscanf(fpin, "%ld%ld", &isi[i-1], &ic[i-1]); for (j = 1; j <= m; ++j) fscanf(fpin, "%lf", &Z(i, j)); fscanf(fpin, "%*[^\n] "); } for (j = 1; j <= m; ++j) fscanf(fpin, "%ld", &isz[j-1]); fscanf(fpin, "%ld%*[^\n] ", &p); /* Allocate other arrays */ if (!(b = NAG_ALLOC(p, double)) || !(cov = NAG_ALLOC(p*(p+1)/2, double)) || !(sc = NAG_ALLOC(p, double)) || !(se = NAG_ALLOC(p, double)) || !(nca = NAG_ALLOC(ns, Integer)) || !(nct = NAG_ALLOC(ns, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (j = 1; j <= m; ++j) fscanf(fpin, "%lf", &b[j-1]); fscanf(fpin, "%*[^\n] "); /* nag_condl_logistic (g11cac). * Returns parameter estimates for the conditional analysis * of stratified data */ nag_condl_logistic(order, n, m, ns, z, pdz, isz, p, ic, isi, &dev, b, se, sc, cov, nca, nct, tol, maxit, iprint, 0, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_condl_logistic (g11cac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Deviance = %13.4e\n", dev); fprintf(fpout, "\n"); fprintf(fpout, " Strata No. Cases No. Controls\n"); fprintf(fpout, "\n"); for (i = 1; i <= ns; ++i) fprintf(fpout, " %3ld %2ld %2ld" " \n", i, nca[i-1], nct[i-1]); fprintf(fpout, "\n"); fprintf(fpout, " Parameter Estimate Standard Error\n"); fprintf(fpout, "\n"); for (i = 1; i <= p; ++i) fprintf(fpout, "%5ld %8.4f %8.4f \n", i, b[i-1], se[i-1]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (b) NAG_FREE(b); if (cov) NAG_FREE(cov); if (sc) NAG_FREE(sc); if (se) NAG_FREE(se); if (z) NAG_FREE(z); if (ic) NAG_FREE(ic); if (isi) NAG_FREE(isi); if (isz) NAG_FREE(isz); if (nca) NAG_FREE(nca); if (nct) NAG_FREE(nct); return exit_status; }