/* nag_mv_orthomax (g03bac) Example Program. * * Copyright 1998 Numerical Algorithms Group. * * Mark 5, 1998. * Mark 8 revised, 2004. * */ #include #include #include #include #define R(I,J) r[(I)*tdr + J] #define FL(I,J) fl[(I)*tdf + J] #define FLR(I,J) flr[(I)*tdf + J] int main(void) { Integer exit_status=0, i, iter, j, k, maxit, nvar, tdf, tdr; NagError fail; Nag_RotationLoading stand; char char_stand[2]; double acc, *fl=0, *flr=0, g, *r=0; INIT_FAIL(fail); Vprintf("nag_mv_orthomax (g03bac) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld",&nvar); Vscanf("%ld",&k); Vscanf("%lf",&g); Vscanf("%s",char_stand); Vscanf("%lf",&acc); Vscanf("%ld",&maxit); if (*char_stand == 'S') stand = Nag_RoLoadStand; else stand = Nag_RoLoadNotStand; if ( k>=2 && nvar>= k) { if ( !( r = NAG_ALLOC(k*k, double)) || !( fl = NAG_ALLOC(nvar*k, double))|| !( flr = NAG_ALLOC(nvar*k, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tdr = k; tdf = k; tdf = k; } else { Vprintf("Invalid k or nvar.\n"); exit_status = 1; return exit_status; } for (i = 0; i < nvar; ++i) { for (j = 0; j < k; ++j) Vscanf("%lf",&FL(i,j)); } /* nag_mv_orthomax (g03bac). * Orthogonal rotations for loading matrix */ nag_mv_orthomax(stand, g, nvar, k, fl, tdf, flr, r, tdr, acc, maxit, &iter, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_mv_orthomax (g03bac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n Rotated factor loadings\n\n"); for (i = 0; i < nvar; ++i) { for (j = 0; j < k; ++j) Vprintf(" %8.3f",FLR(i,j)); Vprintf("\n"); } Vprintf("\n Rotation matrix\n\n"); for (i = 0; i < k; ++i) { for (j = 0; j < k; ++j) Vprintf(" %8.3f",R(i,j)); Vprintf("\n"); } END: if (r) NAG_FREE(r); if (fl) NAG_FREE(fl); if (flr) NAG_FREE(flr); return exit_status; }