/* nag_regsn_mult_linear (g02dac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5 revised, 1998. * Mark 6 revised, 2000. * Mark 8 revised, 2004. */ #include #include #include #include #include static int ex1(void); static int ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } #define X(I,J) x[(I)*tdx + J] #define Q(I,J) q[(I)*tdq + J] static int ex1(void) { Nag_Boolean svd; Integer exit_status=0, i, ip, j, m, n, rank, *sx=0, tdq, tdx; NagError fail; Nag_IncludeMean mean; char meanc, weight; double *b=0, *com_ar=0, *cov=0, df, *h=0, *p=0, *q=0, *res=0, rss, *se=0; double tol, *wt=0, *wtptr, *x=0, *y=0; INIT_FAIL(fail); Vprintf("nag_regsn_mult_linear (g02dac) Example 1 Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld %ld %c %c", &n, &m, &weight, &meanc); if (meanc=='m') mean = Nag_MeanInclude; else mean = Nag_MeanZero; if (n>=2 && m>=1) { if ( !( h = NAG_ALLOC(n, double)) || !( res = NAG_ALLOC(n, double)) || !( 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 (weight=='w') { wtptr = wt; for (i=0; i0) ip += 1; if ( !( b = NAG_ALLOC(ip, double)) || !( cov = NAG_ALLOC((ip*ip+ip)/2, double)) || !( p = NAG_ALLOC(ip*(ip+2), double)) || !( q = NAG_ALLOC(n*(ip+1), double)) || !( com_ar = NAG_ALLOC(ip*ip+5*(ip-1), double)) || !( se = NAG_ALLOC(ip, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdq = ip+1; /* Set tolerance */ tol = 0.00001e0; /* nag_regsn_mult_linear (g02dac). * Fits a general (multiple) linear regression model */ nag_regsn_mult_linear(mean, n, x, tdx, m, sx, ip, y, wtptr, &rss, &df, b, se, cov, res, h, q, tdq, &svd, &rank, p, tol, com_ar, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_regsn_mult_linear (g02dac).\n%s\n", fail.message); exit_status = 1; goto END; } if (svd) Vprintf("Model not of full rank, rank = %4ld\n\n", rank); Vprintf("Residual sum of squares = %12.4e\n", rss); Vprintf("Degrees of freedom = %3.1f\n\n", df); Vprintf("Variable Parameter estimate Standard error\n\n"); for (j=0; j=1) { if ( !( h = NAG_ALLOC(n, double)) || !( res = NAG_ALLOC(n, double)) || !( wt = NAG_ALLOC(n, double)) || !( x = NAG_ALLOC(n*mmax, double)) || !( y = NAG_ALLOC(n, double)) || !( sx = NAG_ALLOC(mmax, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdx = mmax; } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } /* Set tolerance */ tol = pow(10.0, -(double)digits); m = degree; ip = degree + 1; if ( !( b = NAG_ALLOC(ip, double)) || !( cov = NAG_ALLOC((ip*ip+ip)/2, double)) || !( p = NAG_ALLOC(ip*(ip+2), double)) || !( q = NAG_ALLOC(n*(ip+1), double)) || !( com_ar = NAG_ALLOC(ip*ip+5*(ip-1), double)) || !( se = NAG_ALLOC(ip, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdq = ip+1; for (i = 0; i