/* nag_mv_discrim_group (g03dcc) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * */ #include #include #include #include #define NMAX 21 #define MMAX 2 #define GPMAX 3 int main(void) { double stat; double ati[NMAX][GPMAX], det[GPMAX], gc[(GPMAX+1)*MMAX*(MMAX+1)/2], gmean[GPMAX][MMAX], p[NMAX][GPMAX], prior[GPMAX], wt[NMAX], x[NMAX][MMAX]; double df; double sig; double *wtptr=0; Integer nobs, nvar; Integer i, j, m, n; Integer iag[NMAX], ing[NMAX], isx[MMAX], nig[GPMAX]; Integer ng; Integer tdgmean=MMAX, tdp=GPMAX, tdx=MMAX; Boolean atiq = TRUE; char char_type[2]; char char_equal[2]; char weight[2]; Nag_DiscrimMethod type; Nag_GroupCovars equal; Vprintf("g03dcc Example Program Results\n\n"); /* Skip headings in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&n); Vscanf("%ld",&m); Vscanf("%ld",&nvar); Vscanf("%ld",&ng); Vscanf("%s",weight); if (n <= NMAX && m <= MMAX) { if (*weight == 'W') { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); Vscanf("%ld",&ing[i]); Vscanf("%lf",&wt[i]); } wtptr = wt; } else { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); Vscanf("%ld",&ing[i]); } } for (j = 0; j < m; ++j) Vscanf("%ld",&isx[j]); g03dac(n, m, &x[0][0], tdx, isx, nvar, ing, ng, wtptr, nig, &gmean[0][0], tdgmean, det, gc, &stat, &df, &sig, NAGERR_DEFAULT); Vscanf("%ld",&nobs); Vscanf("%s",char_equal); Vscanf("%s",char_type); if (nobs <= NMAX) { for (i = 0; i < nobs; ++i) { for (j = 0; j < m; ++j) { Vscanf("%lf",&x[i][j]); } } if (*char_type == 'E') type = Nag_DiscrimEstimate; else if (*char_type == 'P') type = Nag_DiscrimPredict; if (*char_equal == 'E') equal = Nag_EqualCovar; else if (*char_equal == 'U') equal = Nag_NotEqualCovar; g03dcc(type, equal, Nag_EqualPrior, nvar, ng, nig, &gmean[0][0], tdgmean, gc, det, nobs, m, isx, &x[0][0], tdx, prior, &p[0][0], tdp, iag, atiq, &ati[0][0], NAGERR_DEFAULT); Vprintf("\n"); Vprintf(" Obs Posterior Allocated "); Vprintf(" Atypicality "); Vprintf("\n"); Vprintf(" probabilities to group index "); Vprintf("\n"); Vprintf("\n"); for (i = 0; i < nobs; ++i) { Vprintf(" %6ld ",i+1); for (j = 0; j < ng; ++j) { Vprintf("%6.3f",p[i][j]); } Vprintf(" %6ld ",iag[i]); for (j = 0; j < ng; ++j) { Vprintf("%6.3f",ati[i][j]); } Vprintf("\n"); } } return EXIT_SUCCESS; } else { Vprintf("Incorrect input value of n or m.\n"); return EXIT_FAILURE; } }