/* nag_rank_regsn_censored (g08rbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include int main(void) { /* 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, *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); exit_status = 0; Vprintf("nag_rank_regsn_censored (g08rbc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read number of samples, number of parameters to be fitted, */ /* distribution power parameter and tolerance criterion for ties. */ Vscanf("%ld%ld%lf%lf%*[^\n] ", &ns, &p, &gamma, &tol); Vprintf("\n"); /* Allocate memory to nv only */ if ( !(nv = NAG_ALLOC(ns, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("Number of samples =%2ld\n", ns); Vprintf("Number of parameters fitted =%2ld\n", p); Vprintf("Distribution power parameter =%10.5f\n", gamma); Vprintf("Tolerance for ties =%10.5f\n", tol); Vprintf("\n"); /* 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]); } /* 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)) ) { 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, design matrix and censoring variable */ for (i = 1; i <= nsum; ++i) { Vscanf("%lf", &y[i - 1]); for (j = 1; j <= p; ++j) { Vscanf("%lf", &X(i,j)); } Vscanf("%ld", &icen[i - 1]); } Vscanf("%*[^\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) { Vprintf("Error from nag_rank_regsn_censored (g08rbc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("Score statistic\n"); for (i = 1; i <= p; ++i) Vprintf("%9.3f\n", parest[i - 1]); Vprintf("\n"); Vprintf("Covariance matrix of score statistic\n"); for (j = 1; j <= p; ++j) { for (i = 1; i <= j; ++i) Vprintf("%9.3f\n", PARVAR(i,j)); Vprintf("\n"); } Vprintf("Parameter estimates\n"); for (i = 1; i <= p; ++i) Vprintf("%9.3f\n", parest[p + i - 1]); Vprintf("\n"); Vprintf("Covariance matrix of parameter estimates\n"); for (i = 1; i <= p; ++i) { for (j = 1; j <= i; ++j) Vprintf("%9.3f\n", PARVAR(i + 1,j)); 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]); 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 (icen) NAG_FREE(icen); if (irank) NAG_FREE(irank); if (iwa) NAG_FREE(iwa); if (nv) NAG_FREE(nv); return exit_status; }