/* nag_glm_binomial (g02gbc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * 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, *ivar=0, j, m, max_iter, n, nvar, print_iter; Integer rank, tdv, tdx; NagError fail; Nag_IncludeMean mean; Nag_Link link; char linkc, meanc, weightc; double *beta=0, *binom=0, *cov=0, dev, df, eps, *offsetptr=0, *se=0; double tol, *v=0, *wt=0, *wtptr, *x=0, *y=0; INIT_FAIL(fail); Vprintf("nag_glm_binomial (g02gbc) 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 ( !( binom = NAG_ALLOC(n, double)) || !( wt = NAG_ALLOC(n, double)) || !( x = NAG_ALLOC(n*m, double)) || !( y = NAG_ALLOC(n, double)) || !( ivar = 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) nvar += 1; if (mean == Nag_MeanInclude) nvar += 1; if ( !( beta = NAG_ALLOC(nvar, double)) || !( v = NAG_ALLOC((n)*(nvar+6), double)) || !( se = NAG_ALLOC(nvar, double)) || !( cov = NAG_ALLOC(nvar*(nvar+1)/2, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdv = nvar+6; /* Set other control parameters */ max_iter = 10; tol = 5e-5; eps = 1e-6; /* nag_glm_binomial (g02gbc). * Fits a generalized linear model with binomial errors */ nag_glm_binomial(link, mean, n, x, tdx, m, ivar, nvar, y, binom, wtptr, offsetptr, &dev, &df, beta, &rank, se, cov,v, tdv, tol, max_iter, print_iter, "", eps, &fail); if (fail.code == NE_NOERROR || fail.code == NE_SVD_NOT_CONV || 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