/* nag_rank_regsn (g08rac) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* Scalars */ double tol; Integer exit_status, i, idist, 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, *y=0, *zin=0; Integer *irank=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); exit_status = 0; Vprintf("nag_rank_regsn (g08rac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read number of samples, number of parameters to be fitted, * error distribution parameter and tolerance criterion for ties. */ Vscanf("%ld%ld%ld%lf%*[^\n] ", &ns, &p, &idist, &tol); /* Allocate memory to nv only */ if ( !(nv = NAG_ALLOC(ns, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("\n"); Vprintf("Number of samples =%2ld\n", ns); Vprintf("Number of parameters fitted =%2ld\n", p); Vprintf("Distribution =%2ld\n", idist); Vprintf("Tolerance for ties =%8.5f\n", tol); /* Read the number of observations in each sample. */ for (i = 1; i <= ns; ++i) Vscanf("%ld", &nv[i - 1]); Vscanf("%*[^\n] "); nmax = 0; nsum = 0; for (i = 1; i <= ns; ++i) { nsum += nv[i - 1]; nmax = MAX(nmax,nv[i - 1]); } if (nmax > 0 && nmax <= 100 && nsum > 0 && nsum <= 100) { /* Allocate memory */ if ( !(eta = NAG_ALLOC(nmax, double)) || !(parest = NAG_ALLOC(4*p+1, double)) || !(parvar = NAG_ALLOC((p+1)*p, 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)) || !(irank = NAG_ALLOC(nmax, Integer)) ) { Vprintf("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 and design matrices for each sample. */ for (i = 1; i <= nsum; ++i) { Vscanf("%lf", &y[i - 1]); for (j = 1; j <= p; ++j) Vscanf("%lf", &X(i,j)); } Vscanf("%*[^\n] "); /* nag_rank_regsn (g08rac). * Regression using ranks, uncensored data */ nag_rank_regsn(order, ns, nv, y, p, x, pdx, idist, nmax, tol, parvar, pdparvar, irank, zin, eta, vapvec, parest, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_rank_regsn (g08rac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("Score statistic\n"); for (i = 1; i <= p; ++i) Vprintf("%9.3f%s", parest[i - 1], i%2 == 0 || i == p ?"\n":" "); Vprintf("\n"); Vprintf("Covariance matrix of score statistic\n"); for (j = 1; j <= p; ++j) { for (i = 1; i <= j; ++i) Vprintf("%9.3f%s", PARVAR(i,j), i%2 == 0 || i == j ?"\n":" "); } Vprintf("\n"); Vprintf("Parameter estimates\n"); for (i = 1; i <= p; ++i) Vprintf("%9.3f%s", parest[p + i - 1], i%2 == 0 || i == p ?"\n":" "); Vprintf("\n"); Vprintf("Covariance matrix of parameter estimates\n"); for (i = 1; i <= p; ++i) { Vprintf(" "); for (j = 1; j <= i; ++j) Vprintf("%9.3f%s", PARVAR(i + 1,j), j%2 == 0 || j == i ?"\n":" "); } Vprintf("\n"); Vprintf("Chi-squared statistic =%9.3f with%2ld d.f.\n", parest[p * 2], p); Vprintf("\n"); Vprintf("Standard errors of estimates and\n"); Vprintf("approximate z-statistics\n"); for (i = 1; i <= p; ++i) Vprintf("%9.3f%14.3f\n", parest[2*p + 1 + i - 1], parest[p * 3 + 1 + i - 1]); Vprintf("\n"); } END: 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 (irank) NAG_FREE(irank); if (nv) NAG_FREE(nv); return exit_status; }