X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffactor.c;h=ed10d16d6d25ee24ed98bf9770eb7b90e2560355;hb=687a88f81434045ba4230b503fc582e20a0f1c02;hp=89c1e2f58ae7cc734bc29c61ec8d4a68d9cd0a65;hpb=991d42fe68b1bfbceed959e084ab5178490c9a7b;p=pspp diff --git a/src/language/stats/factor.c b/src/language/stats/factor.c index 89c1e2f58a..ed10d16d6d 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, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2012, 2014, 2015, 2016 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 @@ -96,6 +96,7 @@ enum rotation_type ROT_VARIMAX = 0, ROT_EQUAMAX, ROT_QUARTIMAX, + ROT_PROMAX, ROT_NONE }; @@ -131,13 +132,65 @@ quartimax_coefficients (double *x, double *y, *y = c ; } -static const rotation_coefficients rotation_coeff[3] = { +static const rotation_coefficients rotation_coeff[] = { varimax_coefficients, equamax_coefficients, - quartimax_coefficients + quartimax_coefficients, + varimax_coefficients /* PROMAX is identical to VARIMAX */ }; +/* return diag (C'C) ^ {-0.5} */ +static gsl_matrix * +diag_rcp_sqrt (const gsl_matrix *C) +{ + int j; + gsl_matrix *d = gsl_matrix_calloc (C->size1, C->size2); + gsl_matrix *r = gsl_matrix_calloc (C->size1, C->size2); + + assert (C->size1 == C->size2); + + gsl_linalg_matmult_mod (C, GSL_LINALG_MOD_TRANSPOSE, + C, GSL_LINALG_MOD_NONE, + d); + + for (j = 0 ; j < d->size2; ++j) + { + double e = gsl_matrix_get (d, j, j); + e = 1.0 / sqrt (e); + gsl_matrix_set (r, j, j, e); + } + + gsl_matrix_free (d); + + return r; +} + + + +/* return diag ((C'C)^-1) ^ {-0.5} */ +static gsl_matrix * +diag_rcp_inv_sqrt (const gsl_matrix *CCinv) +{ + int j; + gsl_matrix *r = gsl_matrix_calloc (CCinv->size1, CCinv->size2); + + assert (CCinv->size1 == CCinv->size2); + + for (j = 0 ; j < CCinv->size2; ++j) + { + double e = gsl_matrix_get (CCinv, j, j); + e = 1.0 / sqrt (e); + gsl_matrix_set (r, j, j, e); + } + + return r; +} + + + + + struct cmd_factor { size_t n_vars; @@ -152,12 +205,14 @@ struct cmd_factor enum extraction_method extraction; enum plot_opts plot; enum rotation_type rotation; + int rotation_iterations; + int promax_power; /* Extraction Criteria */ int n_factors; double min_eigen; double econverge; - int iterations; + int extraction_iterations; double rconverge; @@ -621,7 +676,9 @@ static void rotate (const struct cmd_factor *cf, const gsl_matrix *unrot, const gsl_vector *communalities, gsl_matrix *result, - gsl_vector *rotated_loadings + gsl_vector *rotated_loadings, + gsl_matrix *pattern_matrix, + gsl_matrix *factor_correlation_matrix ) { int j, k; @@ -658,7 +715,7 @@ rotate (const struct cmd_factor *cf, const gsl_matrix *unrot, /* Now perform the rotation iterations */ prev_sv = initial_sv (normalised); - for (i = 0 ; i < cf->iterations ; ++i) + for (i = 0 ; i < cf->rotation_iterations ; ++i) { double sv = 0.0; for (j = 0 ; j < normalised->size2; ++j) @@ -730,6 +787,142 @@ rotate (const struct cmd_factor *cf, const gsl_matrix *unrot, gsl_matrix_free (h_sqrt); gsl_matrix_free (normalised); + if (cf->rotation == ROT_PROMAX) + { + /* general purpose m by m matrix, where m is the number of factors */ + gsl_matrix *mm1 = gsl_matrix_calloc (unrot->size2, unrot->size2); + gsl_matrix *mm2 = gsl_matrix_calloc (unrot->size2, unrot->size2); + + /* general purpose m by p matrix, where p is the number of variables */ + gsl_matrix *mp1 = gsl_matrix_calloc (unrot->size2, unrot->size1); + + gsl_matrix *pm1 = gsl_matrix_calloc (unrot->size1, unrot->size2); + + gsl_permutation *perm = gsl_permutation_alloc (unrot->size2); + + int signum; + + int i, j; + + /* The following variables follow the notation by SPSS Statistical Algorithms + page 342 */ + gsl_matrix *L = gsl_matrix_calloc (unrot->size2, unrot->size2); + gsl_matrix *P = clone_matrix (result); + gsl_matrix *D ; + gsl_matrix *Q ; + + + /* Vector of length p containing (indexed by i) + \Sum^m_j {\lambda^2_{ij}} */ + gsl_vector *rssq = gsl_vector_calloc (unrot->size1); + + for (i = 0; i < P->size1; ++i) + { + double sum = 0; + for (j = 0; j < P->size2; ++j) + { + sum += gsl_matrix_get (result, i, j) + * gsl_matrix_get (result, i, j); + + } + + gsl_vector_set (rssq, i, sqrt (sum)); + } + + for (i = 0; i < P->size1; ++i) + { + for (j = 0; j < P->size2; ++j) + { + double l = gsl_matrix_get (result, i, j); + double r = gsl_vector_get (rssq, i); + gsl_matrix_set (P, i, j, pow (fabs (l / r), cf->promax_power + 1) * r / l); + } + } + + gsl_vector_free (rssq); + + gsl_linalg_matmult_mod (result, + GSL_LINALG_MOD_TRANSPOSE, + result, + GSL_LINALG_MOD_NONE, + mm1); + + gsl_linalg_LU_decomp (mm1, perm, &signum); + gsl_linalg_LU_invert (mm1, perm, mm2); + + gsl_linalg_matmult_mod (mm2, GSL_LINALG_MOD_NONE, + result, GSL_LINALG_MOD_TRANSPOSE, + mp1); + + gsl_linalg_matmult_mod (mp1, GSL_LINALG_MOD_NONE, + P, GSL_LINALG_MOD_NONE, + L); + + D = diag_rcp_sqrt (L); + Q = gsl_matrix_calloc (unrot->size2, unrot->size2); + + gsl_linalg_matmult_mod (L, GSL_LINALG_MOD_NONE, + D, GSL_LINALG_MOD_NONE, + Q); + + gsl_matrix *QQinv = gsl_matrix_calloc (unrot->size2, unrot->size2); + + gsl_linalg_matmult_mod (Q, GSL_LINALG_MOD_TRANSPOSE, + Q, GSL_LINALG_MOD_NONE, + QQinv); + + gsl_linalg_cholesky_decomp (QQinv); + gsl_linalg_cholesky_invert (QQinv); + + + gsl_matrix *C = diag_rcp_inv_sqrt (QQinv); + gsl_matrix *Cinv = clone_matrix (C); + + gsl_linalg_cholesky_decomp (Cinv); + gsl_linalg_cholesky_invert (Cinv); + + + gsl_linalg_matmult_mod (result, GSL_LINALG_MOD_NONE, + Q, GSL_LINALG_MOD_NONE, + pm1); + + gsl_linalg_matmult_mod (pm1, GSL_LINALG_MOD_NONE, + Cinv, GSL_LINALG_MOD_NONE, + pattern_matrix); + + + gsl_linalg_matmult_mod (C, GSL_LINALG_MOD_NONE, + QQinv, GSL_LINALG_MOD_NONE, + mm1); + + gsl_linalg_matmult_mod (mm1, GSL_LINALG_MOD_NONE, + C, GSL_LINALG_MOD_TRANSPOSE, + factor_correlation_matrix); + + gsl_linalg_matmult_mod (pattern_matrix, GSL_LINALG_MOD_NONE, + factor_correlation_matrix, GSL_LINALG_MOD_NONE, + pm1); + + gsl_matrix_memcpy (result, pm1); + + + gsl_matrix_free (QQinv); + gsl_matrix_free (C); + gsl_matrix_free (Cinv); + + gsl_matrix_free (D); + gsl_matrix_free (Q); + gsl_matrix_free (L); + gsl_matrix_free (P); + + gsl_permutation_free (perm); + + gsl_matrix_free (mm1); + gsl_matrix_free (mm2); + gsl_matrix_free (mp1); + gsl_matrix_free (pm1); + } + /* reflect negative sums and populate the rotated loadings vector*/ for (i = 0 ; i < result->size2; ++i) @@ -740,7 +933,7 @@ rotate (const struct cmd_factor *cf, const gsl_matrix *unrot, { double s = gsl_matrix_get (result, j, i); ssq += s * s; - sum += gsl_matrix_get (result, j, i); + sum += s; } gsl_vector_set (rotated_loadings, i, ssq); @@ -813,9 +1006,8 @@ static bool run_factor (struct dataset *ds, const struct cmd_factor *factor); int cmd_factor (struct lexer *lexer, struct dataset *ds) { - bool extraction_seen = false; const struct dictionary *dict = dataset_dict (ds); - + int n_iterations = 25; struct cmd_factor factor; factor.n_vars = 0; factor.vars = NULL; @@ -826,7 +1018,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) factor.extraction = EXTRACTION_PC; factor.n_factors = 0; factor.min_eigen = SYSMIS; - factor.iterations = 25; + factor.extraction_iterations = 25; + factor.rotation_iterations = 25; factor.econverge = 0.001; factor.blank = 0; @@ -858,7 +1051,28 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) { lex_match (lexer, T_SLASH); - if (lex_match_id (lexer, "PLOT")) + if (lex_match_id (lexer, "ANALYSIS")) + { + struct const_var_set *vs; + const struct variable **vars; + size_t n_vars; + bool ok; + + lex_match (lexer, T_EQUALS); + + vs = const_var_set_create_from_array (factor.vars, factor.n_vars); + ok = parse_const_var_set_vars (lexer, vs, &vars, &n_vars, + PV_NO_DUPLICATE | PV_NUMERIC); + const_var_set_destroy (vs); + + if (!ok) + goto error; + + free (factor.vars); + factor.vars = vars; + factor.n_vars = n_vars; + } + else if (lex_match_id (lexer, "PLOT")) { lex_match (lexer, T_EQUALS); while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) @@ -917,6 +1131,18 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) { factor.rotation = ROT_QUARTIMAX; } + else if (lex_match_id (lexer, "PROMAX")) + { + factor.promax_power = 5; + if (lex_match (lexer, T_LPAREN) + && lex_force_int (lexer)) + { + factor.promax_power = lex_integer (lexer); + lex_get (lexer); + lex_force_match (lexer, T_RPAREN); + } + factor.rotation = ROT_PROMAX; + } else if (lex_match_id (lexer, "NOROTATE")) { factor.rotation = ROT_NONE; @@ -927,6 +1153,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) goto error; } } + factor.rotation_iterations = n_iterations; } else if (lex_match_id (lexer, "CRITERIA")) { @@ -935,9 +1162,9 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) { if (lex_match_id (lexer, "FACTORS")) { - if ( lex_force_match (lexer, T_LPAREN)) + if ( lex_force_match (lexer, T_LPAREN) + && lex_force_int (lexer)) { - lex_force_int (lexer); factor.n_factors = lex_integer (lexer); lex_get (lexer); lex_force_match (lexer, T_RPAREN); @@ -945,9 +1172,9 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "MINEIGEN")) { - if ( lex_force_match (lexer, T_LPAREN)) + if ( lex_force_match (lexer, T_LPAREN) + && lex_force_num (lexer)) { - lex_force_num (lexer); factor.min_eigen = lex_number (lexer); lex_get (lexer); lex_force_match (lexer, T_RPAREN); @@ -955,30 +1182,30 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "ECONVERGE")) { - if ( lex_force_match (lexer, T_LPAREN)) + if ( lex_force_match (lexer, T_LPAREN) + && lex_force_num (lexer)) { - lex_force_num (lexer); factor.econverge = lex_number (lexer); lex_get (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); - } + { + 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, T_LPAREN)) + if ( lex_force_match (lexer, T_LPAREN) + && lex_force_int (lexer)) { - lex_force_int (lexer); - factor.iterations = lex_integer (lexer); + n_iterations = lex_integer (lexer); lex_get (lexer); lex_force_match (lexer, T_RPAREN); } @@ -987,7 +1214,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) { factor.n_factors = 0; factor.min_eigen = 1; - factor.iterations = 25; + n_iterations = 25; } else { @@ -998,7 +1225,6 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "EXTRACTION")) { - extraction_seen = true; lex_match (lexer, T_EQUALS); while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { @@ -1024,6 +1250,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) goto error; } } + factor.extraction_iterations = n_iterations; } else if (lex_match_id (lexer, "FORMAT")) { @@ -1036,9 +1263,9 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "BLANK")) { - if ( lex_force_match (lexer, T_LPAREN)) + if ( lex_force_match (lexer, T_LPAREN) + && lex_force_num (lexer)) { - lex_force_num (lexer); factor.blank = lex_number (lexer); lex_get (lexer); lex_force_match (lexer, T_RPAREN); @@ -1321,10 +1548,10 @@ show_communalities (const struct cmd_factor * factor, tab_text (t, c++, i + heading_rows, TAT_TITLE, var_to_string (factor->vars[i])); if (factor->print & PRINT_INITIAL) - tab_double (t, c++, i + heading_rows, 0, gsl_vector_get (initial, i), NULL); + tab_double (t, c++, i + heading_rows, 0, gsl_vector_get (initial, i), NULL, RC_OTHER); if (factor->print & PRINT_EXTRACTION) - tab_double (t, c++, i + heading_rows, 0, gsl_vector_get (extracted, i), NULL); + tab_double (t, c++, i + heading_rows, 0, gsl_vector_get (extracted, i), NULL, RC_OTHER); } tab_submit (t); @@ -1335,6 +1562,7 @@ static void show_factor_matrix (const struct cmd_factor *factor, struct idata *idata, const char *title, const gsl_matrix *fm) { int i; + const int n_factors = idata->n_extractions; const int heading_columns = 1; @@ -1413,7 +1641,7 @@ show_factor_matrix (const struct cmd_factor *factor, struct idata *idata, const if ( fabs (x) < factor->blank) continue; - tab_double (t, heading_columns + j, heading_rows + i, 0, x, NULL); + tab_double (t, heading_columns + j, heading_rows + i, 0, x, NULL, RC_OTHER); } } @@ -1454,7 +1682,9 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, nc += 3; if (factor->print & PRINT_ROTATION) - nc += 3; + { + nc += factor->rotation == ROT_PROMAX ? 1 : 3; + } /* No point having a table with only headings */ if ( nc <= heading_columns) @@ -1506,18 +1736,23 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, if (factor->print & PRINT_ROTATION) { - tab_joint_text (t, c, 0, c + 2, 0, TAB_CENTER | TAT_TITLE, _("Rotation Sums of Squared Loadings")); - c += 3; + const int width = factor->rotation == ROT_PROMAX ? 0 : 2; + tab_joint_text (t, c, 0, c + width, 0, TAB_CENTER | TAT_TITLE, _("Rotation Sums of Squared Loadings")); + c += width + 1; } - for (i = 0; i < (nc - heading_columns) / 3 ; ++i) + for (i = 0; i < (nc - heading_columns + 2) / 3 ; ++i) { tab_text (t, i * 3 + 1, 1, TAB_CENTER | TAT_TITLE, _("Total")); + + tab_vline (t, TAL_2, heading_columns + i * 3, 0, nr - 1); + + if (i == 2 && factor->rotation == ROT_PROMAX) + continue; + /* xgettext:no-c-format */ tab_text (t, i * 3 + 2, 1, TAB_CENTER | TAT_TITLE, _("% of Variance")); tab_text (t, i * 3 + 3, 1, TAB_CENTER | TAT_TITLE, _("Cumulative %")); - - tab_vline (t, TAL_2, heading_columns + i * 3, 0, nr - 1); } for (i = 0 ; i < initial_eigenvalues->size; ++i) @@ -1550,9 +1785,9 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, /* Initial Eigenvalues */ if (factor->print & PRINT_INITIAL) { - tab_double (t, c++, i + heading_rows, 0, i_lambda, NULL); - tab_double (t, c++, i + heading_rows, 0, i_percent, NULL); - tab_double (t, c++, i + heading_rows, 0, i_cum, NULL); + tab_double (t, c++, i + heading_rows, 0, i_lambda, NULL, RC_OTHER); + tab_double (t, c++, i + heading_rows, 0, i_percent, NULL, RC_OTHER); + tab_double (t, c++, i + heading_rows, 0, i_cum, NULL, RC_OTHER); } @@ -1561,9 +1796,9 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, if (i < idata->n_extractions) { /* Sums of squared loadings */ - tab_double (t, c++, i + heading_rows, 0, e_lambda, NULL); - tab_double (t, c++, i + heading_rows, 0, e_percent, NULL); - tab_double (t, c++, i + heading_rows, 0, e_cum, NULL); + tab_double (t, c++, i + heading_rows, 0, e_lambda, NULL, RC_OTHER); + tab_double (t, c++, i + heading_rows, 0, e_percent, NULL, RC_OTHER); + tab_double (t, c++, i + heading_rows, 0, e_cum, NULL, RC_OTHER); } } @@ -1577,9 +1812,12 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, 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_double (t, c++, i + heading_rows, 0, r_lambda, NULL, RC_OTHER); + if (factor->rotation != ROT_PROMAX) + { + tab_double (t, c++, i + heading_rows, 0, r_percent, NULL, RC_OTHER); + tab_double (t, c++, i + heading_rows, 0, r_cum, NULL, RC_OTHER); + } } } } @@ -1589,6 +1827,67 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata, } +static void +show_factor_correlation (const struct cmd_factor * factor, const gsl_matrix *fcm) +{ + size_t i, j; + const int heading_columns = 1; + const int heading_rows = 1; + const int nr = heading_rows + fcm->size2; + const int nc = heading_columns + fcm->size1; + struct tab_table *t = tab_create (nc, nr); + + tab_title (t, _("Factor Correlation Matrix")); + + 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); + + /* Vertical lines */ + tab_box (t, + -1, -1, + -1, TAL_1, + heading_columns, 0, + nc - 1, nr - 1); + + tab_hline (t, TAL_1, 0, nc - 1, heading_rows); + tab_hline (t, TAL_1, 1, nc - 1, 1); + + tab_vline (t, TAL_2, heading_columns, 0, nr - 1); + + + if ( factor->extraction == EXTRACTION_PC) + tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Component")); + else + tab_text (t, 0, 0, TAB_LEFT | TAT_TITLE, _("Factor")); + + for (i = 0 ; i < fcm->size1; ++i) + { + tab_text_format (t, heading_columns + i, 0, TAB_CENTER | TAT_TITLE, _("%zu"), i + 1); + } + + for (i = 0 ; i < fcm->size2; ++i) + { + tab_text_format (t, 0, heading_rows + i, TAB_CENTER | TAT_TITLE, _("%zu"), i + 1); + } + + + for (i = 0 ; i < fcm->size1; ++i) + { + for (j = 0 ; j < fcm->size2; ++j) + tab_double (t, heading_columns + i, heading_rows +j, 0, + gsl_matrix_get (fcm, i, j), NULL, RC_OTHER); + } + + tab_submit (t); +} + + static void show_correlation_matrix (const struct cmd_factor *factor, const struct idata *idata) { @@ -1677,7 +1976,7 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id for (i = 0; i < factor->n_vars; ++i) { for (j = 0; j < factor->n_vars; ++j) - tab_double (t, heading_columns + i, y + j, 0, gsl_matrix_get (idata->corr, i, j), NULL); + tab_double (t, heading_columns + i, y + j, 0, gsl_matrix_get (idata->corr, i, j), NULL, RC_OTHER); } } @@ -1696,7 +1995,7 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id if (i == j) continue; - tab_double (t, heading_columns + i, y + j, 0, significance_of_correlation (rho, w), NULL); + tab_double (t, heading_columns + i, y + j, 0, significance_of_correlation (rho, w), NULL, RC_PVALUE); } } } @@ -1706,7 +2005,7 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id { tab_text (t, 0, nr, TAB_LEFT | TAT_TITLE, _("Determinant")); - tab_double (t, 1, nr, 0, idata->detR, NULL); + tab_double (t, 1, nr, 0, idata->detR, NULL, RC_OTHER); } tab_submit (t); @@ -1784,6 +2083,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) const int nr = heading_rows + factor->n_vars; struct tab_table *t = tab_create (nc, nr); + tab_set_format (t, RC_WEIGHT, wfmt); tab_title (t, _("Descriptive Statistics")); tab_headers (t, heading_columns, 0, heading_rows, 0); @@ -1814,9 +2114,9 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) const struct variable *v = factor->vars[i]; tab_text (t, 0, i + heading_rows, TAB_LEFT | TAT_TITLE, var_to_string (v)); - tab_double (t, 1, i + heading_rows, 0, gsl_matrix_get (mean_matrix, i, i), NULL); - tab_double (t, 2, i + heading_rows, 0, sqrt (gsl_matrix_get (var_matrix, i, i)), NULL); - tab_double (t, 3, i + heading_rows, 0, gsl_matrix_get (idata->n, i, i), wfmt); + tab_double (t, 1, i + heading_rows, 0, gsl_matrix_get (mean_matrix, i, i), NULL, RC_OTHER); + tab_double (t, 2, i + heading_rows, 0, sqrt (gsl_matrix_get (var_matrix, i, i)), NULL, RC_OTHER); + tab_double (t, 3, i + heading_rows, 0, gsl_matrix_get (idata->n, i, i), NULL, RC_WEIGHT); } tab_submit (t); @@ -1874,7 +2174,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) 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_double (t, 2, 0, 0, sum_ssq_r / (sum_ssq_r + sum_ssq_a), NULL, RC_OTHER); tab_text (t, 0, 1, TAT_TITLE | TAB_LEFT, _("Bartlett's Test of Sphericity")); @@ -1894,9 +2194,9 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) 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_double (t, 2, 1, 0, xsq, NULL, RC_OTHER); + tab_double (t, 2, 2, 0, df, NULL, RC_INTEGER); + tab_double (t, 2, 3, 0, gsl_cdf_chisq_Q (xsq, df), NULL, RC_PVALUE); tab_submit (t); @@ -1921,18 +2221,22 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) if (idata->n_extractions == 0) { - msg (MW, _("The FACTOR criteria result in zero factors extracted. Therefore no analysis will be performed.")); + msg (MW, _("The %s criteria result in zero factors extracted. Therefore no analysis will be performed."), "FACTOR"); goto finish; } if (idata->n_extractions > factor->n_vars) { - msg (MW, _("The FACTOR criteria result in more factors than variables, which is not meaningful. No analysis will be performed.")); + msg (MW, + _("The %s criteria result in more factors than variables, which is not meaningful. No analysis will be performed."), + "FACTOR"); goto finish; } { gsl_matrix *rotated_factors = NULL; + gsl_matrix *pattern_matrix = NULL; + gsl_matrix *fcm = NULL; gsl_vector *rotated_loadings = NULL; const gsl_vector *extracted_eigenvalues = NULL; @@ -1957,7 +2261,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) gsl_vector_memcpy (initial_communalities, idata->msr); - for (i = 0; i < factor->iterations; ++i) + for (i = 0; i < factor->extraction_iterations; ++i) { double min, max; gsl_vector_memcpy (diff, idata->msr); @@ -1999,10 +2303,16 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) { rotated_factors = gsl_matrix_calloc (factor_matrix->size1, factor_matrix->size2); rotated_loadings = gsl_vector_calloc (factor_matrix->size2); + if (factor->rotation == ROT_PROMAX) + { + pattern_matrix = gsl_matrix_calloc (factor_matrix->size1, factor_matrix->size2); + fcm = gsl_matrix_calloc (factor_matrix->size2, factor_matrix->size2); + } + - rotate (factor, factor_matrix, extracted_communalities, rotated_factors, rotated_loadings); + rotate (factor, factor_matrix, extracted_communalities, rotated_factors, rotated_loadings, pattern_matrix, fcm); } - + show_explained_variance (factor, idata, idata->eval, extracted_eigenvalues, rotated_loadings); factor_matrix_workspace_free (fmw); @@ -2013,16 +2323,27 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) factor->extraction == EXTRACTION_PC ? _("Component Matrix") : _("Factor Matrix"), factor_matrix); + if ( factor->rotation == ROT_PROMAX) + { + show_factor_matrix (factor, idata, _("Pattern Matrix"), pattern_matrix); + gsl_matrix_free (pattern_matrix); + } + if ( factor->rotation != ROT_NONE) { show_factor_matrix (factor, idata, - factor->extraction == EXTRACTION_PC ? _("Rotated Component Matrix") : _("Rotated Factor Matrix"), + (factor->rotation == ROT_PROMAX) ? _("Structure Matrix") : + (factor->extraction == EXTRACTION_PC ? _("Rotated Component Matrix") : _("Rotated Factor Matrix")), rotated_factors); gsl_matrix_free (rotated_factors); } - + if ( factor->rotation == ROT_PROMAX) + { + show_factor_correlation (factor, fcm); + gsl_matrix_free (fcm); + } gsl_matrix_free (factor_matrix); gsl_vector_free (rotated_loadings); @@ -2038,4 +2359,3 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) } -