/* nag_glm_poisson (g02gcc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * * Mark 6 revised, 2000. * Mark 8 revised, 2004. */ #include #include #include #include #include static int set_enum(char linkc, Nag_Link *link, char meanc, Nag_IncludeMean *mean); #define X(I,J) x[(I)*tdx + J] #define V(I,J) v[(I)*tdv + J] int main(void) { Integer exit_status=0, i, ip, j, m, max_iter, n, print_iter, rank, *sx=0; Integer tdv, tdx; NagError fail; Nag_IncludeMean mean; Nag_Link link; char linkc, meanc, weightc; double *b=0, *cov=0, dev, df, eps, ex_power, *offsetptr=0, *se=0; double tol, *v=0, *wt=0, *wtptr, *x=0, *y=0; INIT_FAIL(fail); Vprintf("nag_glm_poisson (g02gcc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf(" %c %c %c %ld %ld %ld", &linkc, &meanc, &weightc, &n, &m, &print_iter); /* Check and set control parameters */ if (set_enum(linkc, &link, meanc, &mean)) { Vprintf("Invalid mean.\n"); exit_status = 1; return exit_status; } if (n>=2 && m>=1) { if ( !( wt = NAG_ALLOC(n, double)) || !( x = NAG_ALLOC(n*m, double)) || !( y = NAG_ALLOC(n, double)) || !( sx = NAG_ALLOC(m, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdx = m; } else { Vprintf("Invalid n or m.\n"); exit_status = 1; return exit_status; } if (toupper(weightc)=='W') { wtptr = wt; for (i=0; i0) ip += 1; if (mean == Nag_MeanInclude) ip += 1; if (link == Nag_Expo) Vscanf("%lf", &ex_power); else ex_power = 0.0; if ( !( b = NAG_ALLOC(ip, double)) || !( v = NAG_ALLOC(n*(ip+6), double)) || !( se = NAG_ALLOC(ip, double)) || !( cov = NAG_ALLOC(ip*(ip+1)/2, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdv = ip+6; /* Set other control parameters */ max_iter = 10; tol = 5e-5; eps = 1e-6; /* nag_glm_poisson (g02gcc). * Fits a generalized linear model with Poisson errors */ nag_glm_poisson(link, mean, n, x, tdx, m,sx, ip, y, wtptr, offsetptr, ex_power, &dev, &df, b, &rank, se, cov, v, tdv, tol, max_iter, print_iter, "", eps, &fail); if (fail.code == NE_NOERROR || fail.code == NE_LSQ_ITER_NOT_CONV || fail.code == NE_RANK_CHANGED || fail.code == NE_ZERO_DOF_ERROR) { Vprintf("\nDeviance = %12.4e\n", dev); Vprintf("Degrees of freedom = %3.1f\n\n", df); Vprintf(" Estimate Standard error\n\n"); for (i=0; i