/* nag_rank_regsn_censored (g08rbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double gamma, tol; Integer exit_status, i, p, j, nmax, ns, nsum; Integer pdx, pdparvar; NagError fail; Nag_OrderType order; /* Arrays */ double *eta = 0, *parest = 0, *parvar = 0, *vapvec = 0, *x = 0; double *y = 0, *zin = 0; Integer *icen = 0, *irank = 0, *iwa = 0, *nv = 0; #ifdef NAG_COLUMN_MAJOR #define X(I, J) x[(J-1)*pdx + I - 1] #define PARVAR(I, J) parvar[(J-1)*pdparvar + I - 1] order = Nag_ColMajor; #else #define X(I, J) x[(I-1)*pdx + J - 1] #define PARVAR(I, J) parvar[(I-1)*pdparvar + 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_rank_regsn_censored (g08rbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); /* Read number of samples, number of parameters to be fitted, */ /* distribution power parameter and tolerance criterion for ties. */ fscanf(fpin, "%ld%ld%lf%lf%*[^\n] ", &ns, &p, &gamma, &tol); fprintf(fpout, "\n"); /* Allocate memory to nv only */ if (!(nv = NAG_ALLOC(ns, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } fprintf(fpout, "Number of samples =%2ld\n", ns); fprintf(fpout, "Number of parameters fitted =%2ld\n", p); fprintf(fpout, "Distribution power parameter =%10.5f\n", gamma); fprintf(fpout, "Tolerance for ties =%10.5f\n", tol); fprintf(fpout, "\n"); /* Read the number of observations in each sample */ for (i = 1; i <= ns; ++i) fscanf(fpin, "%ld", &nv[i - 1]); fscanf(fpin, "%*[^\n] "); nmax = 0; nsum = 0; for (i = 1; i <= ns; ++i) { nsum += nv[i - 1]; nmax = MAX(nmax, nv[i - 1]); } /* Allocate memory */ if (!(eta = NAG_ALLOC(nmax, double)) || !(parest = NAG_ALLOC(4*p+1, double)) || !(parvar = NAG_ALLOC(7 * 6, double)) || !(vapvec = NAG_ALLOC(nmax*(nmax+1)/2, double)) || !(x = NAG_ALLOC(nsum * p, double)) || !(y = NAG_ALLOC(nsum, double)) || !(zin = NAG_ALLOC(nmax, double)) || !(icen = NAG_ALLOC(nsum, Integer)) || !(irank = NAG_ALLOC(nmax, Integer)) || !(iwa = NAG_ALLOC(400, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } #ifdef NAG_COLUMN_MAJOR pdx = nsum; pdparvar = p+1; #else pdx = p; pdparvar = p; #endif /* Read in observations, design matrix and censoring variable */ for (i = 1; i <= nsum; ++i) { fscanf(fpin, "%lf", &y[i - 1]); for (j = 1; j <= p; ++j) { fscanf(fpin, "%lf", &X(i, j)); } fscanf(fpin, "%ld", &icen[i - 1]); } fscanf(fpin, "%*[^\n] "); /* nag_rank_regsn_censored (g08rbc). * Regression using ranks, right-censored data */ nag_rank_regsn_censored(order, ns, nv, y, p, x, pdx, icen, gamma, nmax, tol, parvar, pdparvar, irank, zin, eta, vapvec, parest, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_rank_regsn_censored (g08rbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "Score statistic\n"); for (i = 1; i <= p; ++i) fprintf(fpout, "%9.3f\n", parest[i - 1]); fprintf(fpout, "\n"); fprintf(fpout, "Covariance matrix of score statistic\n"); for (j = 1; j <= p; ++j) { for (i = 1; i <= j; ++i) fprintf(fpout, "%9.3f\n", PARVAR(i, j)); fprintf(fpout, "\n"); } fprintf(fpout, "Parameter estimates\n"); for (i = 1; i <= p; ++i) fprintf(fpout, "%9.3f\n", parest[p + i - 1]); fprintf(fpout, "\n"); fprintf(fpout, "Covariance matrix of parameter estimates\n"); for (i = 1; i <= p; ++i) { for (j = 1; j <= i; ++j) fprintf(fpout, "%9.3f\n", PARVAR(i + 1, j)); fprintf(fpout, "\n"); } fprintf(fpout, "Chi-squared statistic =%9.3f with%2ld d.f.\n", parest[p * 2], p); fprintf(fpout, "\n"); fprintf(fpout, "Standard errors of estimates and\n"); fprintf(fpout, "approximate z-statistics\n"); for (i = 1; i <= p; ++i) fprintf(fpout, "%9.3f%14.3f\n", parest[2*p + 1 + i - 1], parest[p * 3 + 1 + i - 1]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (eta) NAG_FREE(eta); if (parest) NAG_FREE(parest); if (parvar) NAG_FREE(parvar); if (vapvec) NAG_FREE(vapvec); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (zin) NAG_FREE(zin); if (icen) NAG_FREE(icen); if (irank) NAG_FREE(irank); if (iwa) NAG_FREE(iwa); if (nv) NAG_FREE(nv); return exit_status; }