X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffactor.c;h=6fc106fd0551a73ceb4d148a5b94445e1f937ca4;hb=0838c7ce8528a241fd6bb422767e187af4b5d9a7;hp=d3bba77eaa3c68aac1136e4817c958daa8ceefc9;hpb=e88057263e1a2ade0c166d21f5685d6dc2797257;p=pspp diff --git a/src/language/stats/factor.c b/src/language/stats/factor.c index d3bba77eaa..6fc106fd05 100644 --- a/src/language/stats/factor.c +++ b/src/language/stats/factor.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,38 +16,33 @@ #include - #include #include #include #include #include #include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#include -#include +#include + +#include "data/casegrouper.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/dataset.h" +#include "data/dictionary.h" +#include "data/format.h" +#include "data/subcase.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "language/lexer/value-parser.h" +#include "language/lexer/variable-parser.h" +#include "libpspp/message.h" +#include "libpspp/misc.h" +#include "math/correlation.h" +#include "math/covariance.h" +#include "math/moments.h" +#include "output/chart-item.h" +#include "output/charts/scree.h" +#include "output/tab.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -163,6 +158,8 @@ struct cmd_factor double econverge; int iterations; + double rconverge; + /* Format */ double blank; bool sort; @@ -173,7 +170,7 @@ struct idata /* Intermediate values used in calculation */ const gsl_matrix *corr ; /* The correlation matrix */ - const gsl_matrix *cov ; /* The covariance matrix */ + gsl_matrix *cov ; /* The covariance matrix */ const gsl_matrix *n ; /* Matrix of number of samples */ gsl_vector *eval ; /* The eigenvalues */ @@ -182,6 +179,8 @@ struct idata int n_extractions; gsl_vector *msr ; /* Multiple Squared Regressions */ + + double detR; /* The determinant of the correlation matrix */ }; static struct idata * @@ -204,11 +203,62 @@ idata_free (struct idata *id) gsl_vector_free (id->msr); gsl_vector_free (id->eval); gsl_matrix_free (id->evec); + if (id->cov != NULL) + gsl_matrix_free (id->cov); free (id); } +static gsl_matrix * +anti_image (const gsl_matrix *m) +{ + int i, j; + gsl_matrix *a; + assert (m->size1 == m->size2); + + a = gsl_matrix_alloc (m->size1, m->size2); + + for (i = 0; i < m->size1; ++i) + { + for (j = 0; j < m->size2; ++j) + { + double *p = gsl_matrix_ptr (a, i, j); + *p = gsl_matrix_get (m, i, j); + *p /= gsl_matrix_get (m, i, i); + *p /= gsl_matrix_get (m, j, j); + } + } + + return a; +} + + +/* Return the sum of all the elements excluding row N */ +static double +ssq_od_n (const gsl_matrix *m, int n) +{ + int i, j; + double ss = 0; + assert (m->size1 == m->size2); + + assert (n < m->size1); + + for (i = 0; i < m->size1; ++i) + { + if (i == n ) continue; + for (j = 0; j < m->size2; ++j) + { + ss += pow2 (gsl_matrix_get (m, i, j)); + } + } + + return ss; +} + + + +#if 0 static void dump_matrix (const gsl_matrix *m) { @@ -222,7 +272,6 @@ dump_matrix (const gsl_matrix *m) } } - static void dump_matrix_permute (const gsl_matrix *m, const gsl_permutation *p) { @@ -247,6 +296,7 @@ dump_vector (const gsl_vector *v) } printf ("\n"); } +#endif static int @@ -539,11 +589,41 @@ clone_matrix (const gsl_matrix *m) } +static double +initial_sv (const gsl_matrix *fm) +{ + int j, k; + + double sv = 0.0; + for (j = 0 ; j < fm->size2; ++j) + { + double l4s = 0; + double l2s = 0; + + for (k = j + 1 ; k < fm->size2; ++k) + { + double lambda = gsl_matrix_get (fm, k, j); + double lambda_sq = lambda * lambda; + double lambda_4 = lambda_sq * lambda_sq; + + l4s += lambda_4; + l2s += lambda_sq; + } + sv += ( fm->size1 * l4s - (l2s * l2s) ) / (fm->size1 * fm->size1 ); + } + return sv; +} + static void -rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_type rot_type, gsl_matrix *result) +rotate (const struct cmd_factor *cf, const gsl_matrix *unrot, + const gsl_vector *communalities, + gsl_matrix *result, + gsl_vector *rotated_loadings + ) { int j, k; int i; + double prev_sv; /* First get a normalised version of UNROT */ gsl_matrix *normalised = gsl_matrix_calloc (unrot->size1, unrot->size2); @@ -571,11 +651,19 @@ rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_ gsl_matrix_free (h_sqrt_inv); + /* Now perform the rotation iterations */ - for (i = 0 ; i < 25 ; ++i) + + prev_sv = initial_sv (normalised); + for (i = 0 ; i < cf->iterations ; ++i) { + double sv = 0.0; for (j = 0 ; j < normalised->size2; ++j) { + /* These variables relate to the convergence criterium */ + double l4s = 0; + double l2s = 0; + for (k = j + 1 ; k < normalised->size2; ++k) { int p; @@ -585,6 +673,7 @@ rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_ double d = 0.0; double x, y; double phi; + for (p = 0; p < normalised->size1; ++p) { double jv = gsl_matrix_get (normalised, p, j); @@ -598,18 +687,38 @@ rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_ d += 2 * u * v; } - rotation_coeff [rot_type] (&x, &y, a, b, c, d, normalised); + rotation_coeff [cf->rotation] (&x, &y, a, b, c, d, normalised); phi = atan2 (x, y) / 4.0 ; - + + /* Don't bother rotating if the angle is small */ + if ( fabs (sin (phi) ) <= pow (10.0, -15.0)) + continue; + for (p = 0; p < normalised->size1; ++p) { double *lambda0 = gsl_matrix_ptr (normalised, p, j); double *lambda1 = gsl_matrix_ptr (normalised, p, k); drot_go (phi, lambda0, lambda1); } + + /* Calculate the convergence criterium */ + { + double lambda = gsl_matrix_get (normalised, k, j); + double lambda_sq = lambda * lambda; + double lambda_4 = lambda_sq * lambda_sq; + + l4s += lambda_4; + l2s += lambda_sq; + } } + sv += ( normalised->size1 * l4s - (l2s * l2s) ) / (normalised->size1 * normalised->size1 ); } + + if ( fabs (sv - prev_sv) <= cf->rconverge) + break; + + prev_sv = sv; } gsl_blas_dgemm (CblasNoTrans, CblasNoTrans, 1.0, @@ -618,15 +727,20 @@ rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_ gsl_matrix_free (h_sqrt); - /* reflect negative sums */ + /* reflect negative sums and populate the rotated loadings vector*/ for (i = 0 ; i < result->size2; ++i) { + double ssq = 0.0; double sum = 0.0; for (j = 0 ; j < result->size1; ++j) { + double s = gsl_matrix_get (result, j, i); + ssq += s * s; sum += gsl_matrix_get (result, j, i); } + gsl_vector_set (rotated_loadings, i, ssq); + if ( sum < 0 ) for (j = 0 ; j < result->size1; ++j) { @@ -634,8 +748,6 @@ rotate (const gsl_matrix *unrot, const gsl_vector *communalities, enum rotation_ *lambda = - *lambda; } } - - // dump_matrix (result); } @@ -712,21 +824,24 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) factor.min_eigen = SYSMIS; factor.iterations = 25; factor.econverge = 0.001; + factor.blank = 0; factor.sort = false; factor.plot = 0; factor.rotation = ROT_VARIMAX; + factor.rconverge = 0.0001; + factor.wv = dict_get_weight (dict); - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (!lex_force_match_id (lexer, "VARIABLES")) { goto error; } - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (!parse_variables_const (lexer, dict, &factor.vars, &factor.n_vars, PV_NO_DUPLICATE | PV_NUMERIC)) @@ -735,14 +850,14 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) if (factor.n_vars < 2) msg (MW, _("Factor analysis on a single variable is not useful.")); - while (lex_token (lexer) != '.') + while (lex_token (lexer) != T_ENDCMD) { - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (lex_match_id (lexer, "PLOT")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "EIGEN")) { @@ -762,8 +877,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "METHOD")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "COVARIANCE")) { @@ -782,8 +897,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "ROTATION")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { /* VARIMAX and DEFAULT are defaults */ if (lex_match_id (lexer, "VARIMAX") || lex_match_id (lexer, "DEFAULT")) @@ -811,47 +926,57 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "CRITERIA")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "FACTORS")) { - if ( lex_force_match (lexer, '(')) + if ( lex_force_match (lexer, T_LPAREN)) { lex_force_int (lexer); factor.n_factors = lex_integer (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "MINEIGEN")) { - if ( lex_force_match (lexer, '(')) + if ( lex_force_match (lexer, T_LPAREN)) { lex_force_num (lexer); factor.min_eigen = lex_number (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "ECONVERGE")) { - if ( lex_force_match (lexer, '(')) + if ( lex_force_match (lexer, T_LPAREN)) { lex_force_num (lexer); factor.econverge = lex_number (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); + } + } + else if (lex_match_id (lexer, "RCONVERGE")) + { + if ( lex_force_match (lexer, T_LPAREN)) + { + lex_force_num (lexer); + factor.rconverge = lex_number (lexer); + lex_get (lexer); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "ITERATE")) { - if ( lex_force_match (lexer, '(')) + if ( lex_force_match (lexer, T_LPAREN)) { lex_force_int (lexer); factor.iterations = lex_integer (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "DEFAULT")) @@ -870,8 +995,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) else if (lex_match_id (lexer, "EXTRACTION")) { extraction_seen = true; - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "PAF")) { @@ -898,8 +1023,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "FORMAT")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "SORT")) { @@ -907,12 +1032,12 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "BLANK")) { - if ( lex_force_match (lexer, '(')) + if ( lex_force_match (lexer, T_LPAREN)) { lex_force_num (lexer); factor.blank = lex_number (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "DEFAULT")) @@ -930,8 +1055,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) else if (lex_match_id (lexer, "PRINT")) { factor.print = 0; - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "UNIVARIATE")) { @@ -974,10 +1099,11 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) { factor.print |= PRINT_INITIAL; } -#if FACTOR_FULLY_IMPLEMENTED else if (lex_match_id (lexer, "KMO")) { + factor.print |= PRINT_KMO; } +#if FACTOR_FULLY_IMPLEMENTED else if (lex_match_id (lexer, "REPR")) { } @@ -1004,8 +1130,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "MISSING")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "INCLUDE")) { @@ -1041,6 +1167,9 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } } + if ( factor.rotation == ROT_NONE ) + factor.print &= ~PRINT_ROTATION; + if ( ! run_factor (ds, &factor)) goto error; @@ -1219,7 +1348,7 @@ show_factor_matrix (const struct cmd_factor *factor, struct idata *idata, const tab_title (t, _("Factor Matrix")); */ - tab_title (t, title); + tab_title (t, "%s", title); tab_headers (t, heading_columns, 0, heading_rows, 0); @@ -1293,7 +1422,8 @@ show_factor_matrix (const struct cmd_factor *factor, struct idata *idata, const static void show_explained_variance (const struct cmd_factor * factor, struct idata *idata, const gsl_vector *initial_eigenvalues, - const gsl_vector *extracted_eigenvalues) + const gsl_vector *extracted_eigenvalues, + const gsl_vector *rotated_loadings) { size_t i; int c = 0; @@ -1309,6 +1439,8 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, double e_total = 0.0; double e_cum = 0.0; + double r_cum = 0.0; + int nc = heading_columns; if (factor->print & PRINT_EXTRACTION) @@ -1396,7 +1528,6 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, e_total = i_total; } - for (i = 0 ; i < factor->n_vars; ++i) { const double i_lambda = gsl_vector_get (initial_eigenvalues, i); @@ -1407,7 +1538,7 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, c = 0; - tab_text_format (t, c++, i + heading_rows, TAB_LEFT | TAT_TITLE, _("%d"), i + 1); + tab_text_format (t, c++, i + heading_rows, TAB_LEFT | TAT_TITLE, _("%zu"), i + 1); i_cum += i_percent; e_cum += e_percent; @@ -1420,6 +1551,7 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, tab_double (t, c++, i + heading_rows, 0, i_cum, NULL); } + if (factor->print & PRINT_EXTRACTION) { if (i < idata->n_extractions) @@ -1430,6 +1562,23 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, tab_double (t, c++, i + heading_rows, 0, e_cum, NULL); } } + + if (rotated_loadings != NULL) + { + const double r_lambda = gsl_vector_get (rotated_loadings, i); + double r_percent = 100.0 * r_lambda / e_total ; + + if (factor->print & PRINT_ROTATION) + { + if (i < idata->n_extractions) + { + r_cum += r_percent; + tab_double (t, c++, i + heading_rows, 0, r_lambda, NULL); + tab_double (t, c++, i + heading_rows, 0, r_percent, NULL); + tab_double (t, c++, i + heading_rows, 0, r_cum, NULL); + } + } + } } tab_submit (t); @@ -1531,7 +1680,7 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id if (factor->print & PRINT_SIG) { const double y = heading_rows + y_pos_sig * factor->n_vars; - tab_text (t, 0, y, TAT_TITLE, _("Sig. 1-tailed")); + tab_text (t, 0, y, TAT_TITLE, _("Sig. (1-tailed)")); for (i = 0; i < factor->n_vars; ++i) { @@ -1551,22 +1700,9 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id if (factor->print & PRINT_DETERMINANT) { - int sign = 0; - double det = 0.0; - - const int size = idata->corr->size1; - gsl_permutation *p = gsl_permutation_calloc (size); - gsl_matrix *tmp = gsl_matrix_calloc (size, size); - gsl_matrix_memcpy (tmp, idata->corr); - - gsl_linalg_LU_decomp (tmp, p, &sign); - det = gsl_linalg_LU_det (tmp, sign); - gsl_permutation_free (p); - gsl_matrix_free (tmp); - - tab_text (t, 0, nr, TAB_LEFT | TAT_TITLE, _("Determinant")); - tab_double (t, 1, nr, 0, det, NULL); + + tab_double (t, 1, nr, 0, idata->detR, NULL); } tab_submit (t); @@ -1584,7 +1720,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) const gsl_matrix *analysis_matrix; struct idata *idata = idata_alloc (factor->n_vars); - struct covariance *cov = covariance_create (factor->n_vars, factor->vars, + struct covariance *cov = covariance_1pass_create (factor->n_vars, factor->vars, factor->wv, factor->exclude); for ( ; (c = casereader_read (r) ); case_unref (c)) @@ -1594,6 +1730,12 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) idata->cov = covariance_calculate (cov); + if (idata->cov == NULL) + { + msg (MW, _("The dataset contains no complete observations. No analysis will be performed.")); + goto finish; + } + var_matrix = covariance_moments (cov, MOMENT_VARIANCE); mean_matrix = covariance_moments (cov, MOMENT_MEAN); idata->n = covariance_moments (cov, MOMENT_NONE); @@ -1601,17 +1743,33 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) if ( factor->method == METHOD_CORR) { idata->corr = correlation_from_covariance (idata->cov, var_matrix); + analysis_matrix = idata->corr; } else analysis_matrix = idata->cov; + if (factor->print & PRINT_DETERMINANT + || factor->print & PRINT_KMO) + { + int sign = 0; + + const int size = idata->corr->size1; + gsl_permutation *p = gsl_permutation_calloc (size); + gsl_matrix *tmp = gsl_matrix_calloc (size, size); + gsl_matrix_memcpy (tmp, idata->corr); + + gsl_linalg_LU_decomp (tmp, p, &sign); + idata->detR = gsl_linalg_LU_det (tmp, sign); + gsl_permutation_free (p); + gsl_matrix_free (tmp); + } + if ( factor->print & PRINT_UNIVARIATE) { + const struct fmt_spec *wfmt = factor->wv ? var_get_print_format (factor->wv) : & F_8_0; const int nc = 4; int i; - const struct fmt_spec *wfmt = factor->wv ? var_get_print_format (factor->wv) : & F_8_0; - const int heading_columns = 1; const int heading_rows = 1; @@ -1657,9 +1815,88 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) tab_submit (t); } + if (factor->print & PRINT_KMO) + { + int i; + double sum_ssq_r = 0; + double sum_ssq_a = 0; + + double df = factor->n_vars * ( factor->n_vars - 1) / 2; + + double w = 0; + + + double xsq; + + const int heading_columns = 2; + const int heading_rows = 0; + + const int nr = heading_rows + 4; + const int nc = heading_columns + 1; + + gsl_matrix *a, *x; + + struct tab_table *t = tab_create (nc, nr); + tab_title (t, _("KMO and Bartlett's Test")); + + x = clone_matrix (idata->corr); + gsl_linalg_cholesky_decomp (x); + gsl_linalg_cholesky_invert (x); + + a = anti_image (x); + + for (i = 0; i < x->size1; ++i) + { + sum_ssq_r += ssq_od_n (x, i); + sum_ssq_a += ssq_od_n (a, i); + } + + gsl_matrix_free (a); + gsl_matrix_free (x); + + tab_headers (t, heading_columns, 0, heading_rows, 0); + + /* Outline the box */ + tab_box (t, + TAL_2, TAL_2, + -1, -1, + 0, 0, + nc - 1, nr - 1); + + tab_vline (t, TAL_2, heading_columns, 0, nr - 1); + + tab_text (t, 0, 0, TAT_TITLE | TAB_LEFT, _("Kaiser-Meyer-Olkin Measure of Sampling Adequacy")); + + tab_double (t, 2, 0, 0, sum_ssq_r / (sum_ssq_r + sum_ssq_a), NULL); + + tab_text (t, 0, 1, TAT_TITLE | TAB_LEFT, _("Bartlett's Test of Sphericity")); + + tab_text (t, 1, 1, TAT_TITLE, _("Approx. Chi-Square")); + tab_text (t, 1, 2, TAT_TITLE, _("df")); + tab_text (t, 1, 3, TAT_TITLE, _("Sig.")); + + + /* The literature doesn't say what to do for the value of W when + missing values are involved. The best thing I can think of + is to take the mean average. */ + w = 0; + for (i = 0; i < idata->n->size1; ++i) + w += gsl_matrix_get (idata->n, i, i); + w /= idata->n->size1; + + xsq = w - 1 - (2 * factor->n_vars + 5) / 6.0; + xsq *= -log (idata->detR); + + tab_double (t, 2, 1, 0, xsq, NULL); + tab_double (t, 2, 2, 0, df, &F_8_0); + tab_double (t, 2, 3, 0, gsl_cdf_chisq_Q (xsq, df), NULL); + + + tab_submit (t); + } + show_correlation_matrix (factor, idata); -#if 1 { gsl_eigen_symmv_workspace *workspace = gsl_eigen_symmv_alloc (factor->n_vars); @@ -1669,7 +1906,6 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) } gsl_eigen_symmv_sort (idata->eval, idata->evec, GSL_EIGEN_SORT_ABS_DESC); -#endif idata->n_extractions = n_extracted_factors (factor, idata); @@ -1686,6 +1922,9 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) } { + gsl_matrix *rotated_factors = NULL; + gsl_vector *rotated_loadings = NULL; + const gsl_vector *extracted_eigenvalues = NULL; gsl_vector *initial_communalities = gsl_vector_alloc (factor->n_vars); gsl_vector *extracted_communalities = gsl_vector_alloc (factor->n_vars); @@ -1745,7 +1984,16 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) show_communalities (factor, initial_communalities, extracted_communalities); - show_explained_variance (factor, idata, idata->eval, extracted_eigenvalues); + + if ( factor->rotation != ROT_NONE) + { + rotated_factors = gsl_matrix_calloc (factor_matrix->size1, factor_matrix->size2); + rotated_loadings = gsl_vector_calloc (factor_matrix->size2); + + rotate (factor, factor_matrix, extracted_communalities, rotated_factors, rotated_loadings); + } + + show_explained_variance (factor, idata, idata->eval, extracted_eigenvalues, rotated_loadings); factor_matrix_workspace_free (fmw); @@ -1757,10 +2005,6 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) if ( factor->rotation != ROT_NONE) { - gsl_matrix *rotated_factors = gsl_matrix_calloc (factor_matrix->size1, factor_matrix->size2); - - rotate (factor_matrix, extracted_communalities, factor->rotation, rotated_factors); - show_factor_matrix (factor, idata, factor->extraction == EXTRACTION_PC ? _("Rotated Component Matrix") : _("Rotated Factor Matrix"), rotated_factors); @@ -1769,6 +2013,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) } + gsl_vector_free (initial_communalities); gsl_vector_free (extracted_communalities); } @@ -1779,3 +2024,6 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) casereader_destroy (r); } + + +