/* nag_mv_prin_comp (g03aac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * */ #include #include #include #include #define NMAX 12 #define MMAX 3 int main(void) { double p[MMAX][MMAX] ,s[MMAX]; double e[MMAX][6]; double v[NMAX][MMAX], x[NMAX][MMAX], wt[NMAX]; double *wtptr=0; Integer isx[MMAX]; Integer nvar,tdx=MMAX, tde=6, tdp=MMAX, tdv=MMAX; Integer i, j, m, n; Nag_PrinCompMat pcmatrix; Nag_PrinCompScores scores; char weight[2], matrix[2], std[2]; Vprintf("g03aac Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%s",matrix); Vscanf("%s",std); Vscanf("%s",weight); Vscanf("%ld",&n); Vscanf("%ld",&m); if (*matrix == 'C') pcmatrix = Nag_MatCorrelation; else if (*matrix == 'S') pcmatrix = Nag_MatStandardised; else if (*matrix == 'U') pcmatrix = Nag_MatSumSq; else pcmatrix = Nag_MatVarCovar; if (*std == 'S') scores = Nag_ScoresStand; else if (*std == 'U') scores = Nag_ScoresNotStand; else if (*std == 'Z') scores = Nag_ScoresUnitVar; else scores = Nag_ScoresEigenval; if (n <= NMAX && m <= MMAX) { if (*weight == 'U') { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); } } else { for (i = 0; i < n; ++i) { for (j = 0; j < m; ++j) Vscanf("%lf",&x[i][j]); Vscanf("%lf",&wt[i]); } wtptr = wt; } for (j = 0; j < m; ++j) { Vscanf("%ld",&isx[j]); } Vscanf("%ld",&nvar); if (pcmatrix == Nag_MatStandardised) { for (j = 0; j < m; ++j) Vscanf("%lf",&s[j]); } g03aac(pcmatrix, scores, n, m, &x[0][0], tdx, isx, s, wtptr, nvar, &e[0][0], tde, &p[0][0], tdp, &v[0][0], tdv, NAGERR_DEFAULT); Vprintf("Eigenvalues Percentage Cumulative Chisq DF Sig\n"); Vprintf(" variation variation\n\n"); for (i = 0; i < nvar; ++i) { for (j = 0; j < 6; ++j) Vprintf("%11.4f",e[i][j]); Vprintf("\n"); } Vprintf("\nEigenvalues \n\n"); for (i = 0; i < nvar; ++i) { for (j = 0; j < nvar; ++j) Vprintf("%9.4f",p[i][j]); Vprintf("\n"); } Vprintf("\nPrincipal component scores \n\n"); for (i = 0; i < n; ++i) { Vprintf("%2ld", i+1); for (j = 0; j < nvar; ++j) Vprintf("%9.3f", v[i][j]); Vprintf("\n"); } return EXIT_SUCCESS; } else { Vprintf("Incorrect input value of n or m.\n"); return EXIT_FAILURE; } }