X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffactor.c;h=4094a22b432467ce25dba36a3b3f7c55f2861013;hb=490ac70d9c9f754f733552d64c23dd6aedced342;hp=36a49d31b7384ffa2afc2d81e2883972e3d4027a;hpb=8ff8dc1996d072491c4381cf24a7202be927b08a;p=pspp diff --git a/src/language/stats/factor.c b/src/language/stats/factor.c index 36a49d31b7..4094a22b43 100644 --- a/src/language/stats/factor.c +++ b/src/language/stats/factor.c @@ -152,12 +152,13 @@ struct cmd_factor enum extraction_method extraction; enum plot_opts plot; enum rotation_type rotation; + int rotation_iterations; /* Extraction Criteria */ int n_factors; double min_eigen; double econverge; - int iterations; + int extraction_iterations; double rconverge; @@ -658,7 +659,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) @@ -813,9 +814,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 +826,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; @@ -927,6 +928,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) goto error; } } + factor.rotation_iterations = n_iterations; } else if (lex_match_id (lexer, "CRITERIA")) { @@ -978,7 +980,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) if ( lex_force_match (lexer, T_LPAREN)) { 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 +989,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 +1000,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 +1025,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds) goto error; } } + factor.extraction_iterations = n_iterations; } else if (lex_match_id (lexer, "FORMAT")) { @@ -1321,10 +1323,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); @@ -1413,7 +1415,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); } } @@ -1550,9 +1552,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 +1563,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 +1579,9 @@ 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); + 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); } } } @@ -1677,7 +1679,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 +1698,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 +1708,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); @@ -1737,6 +1739,7 @@ do_factor (const struct cmd_factor *factor, struct casereader *r) if (idata->cov == NULL) { msg (MW, _("The dataset contains no complete observations. No analysis will be performed.")); + covariance_destroy (cov); goto finish; } @@ -1783,6 +1786,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); @@ -1813,9 +1817,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); @@ -1873,7 +1877,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")); @@ -1893,9 +1897,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); @@ -1920,13 +1924,15 @@ 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; } @@ -1956,7 +1962,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);