/* PSPP - a program for statistical analysis.
- Copyright (C) 2009, 2010, 2011 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
#include "language/lexer/lexer.h"
#include "language/lexer/value-parser.h"
#include "language/lexer/variable-parser.h"
+#include "libpspp/cast.h"
#include "libpspp/message.h"
#include "libpspp/misc.h"
#include "math/correlation.h"
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;
gsl_matrix_free (id->evec);
if (id->cov != NULL)
gsl_matrix_free (id->cov);
+ if (id->corr != NULL)
+ gsl_matrix_free (CONST_CAST (gsl_matrix *, id->corr));
free (id);
}
/* 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)
h_sqrt, normalised, 0.0, result);
gsl_matrix_free (h_sqrt);
+ gsl_matrix_free (normalised);
/* reflect negative sums and populate the rotated loadings vector*/
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;
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;
goto error;
}
}
+ factor.rotation_iterations = n_iterations;
}
else if (lex_match_id (lexer, "CRITERIA"))
{
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);
}
{
factor.n_factors = 0;
factor.min_eigen = 1;
- factor.iterations = 25;
+ n_iterations = 25;
}
else
{
}
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)
{
goto error;
}
}
+ factor.extraction_iterations = n_iterations;
}
else if (lex_match_id (lexer, "FORMAT"))
{
const double e_lambda = gsl_vector_get (extracted_eigenvalues, i);
double e_percent = 100.0 * e_lambda / e_total ;
- const double r_lambda = gsl_vector_get (rotated_loadings, i);
- double r_percent = 100.0 * r_lambda / e_total ;
-
c = 0;
tab_text_format (t, c++, i + heading_rows, TAB_LEFT | TAT_TITLE, _("%zu"), i + 1);
i_cum += i_percent;
e_cum += e_percent;
- r_cum += r_percent;
/* Initial Eigenvalues */
if (factor->print & PRINT_INITIAL)
}
}
- if (factor->print & PRINT_ROTATION)
- {
- if (i < idata->n_extractions)
- {
- 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);
- }
- }
+ 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);
if (idata->cov == NULL)
{
msg (MW, _("The dataset contains no complete observations. No analysis will be performed."));
+ covariance_destroy (cov);
goto finish;
}
var_matrix = covariance_moments (cov, MOMENT_VARIANCE);
mean_matrix = covariance_moments (cov, MOMENT_MEAN);
idata->n = covariance_moments (cov, MOMENT_NONE);
+
if ( factor->method == METHOD_CORR)
{
else
analysis_matrix = idata->cov;
+
if (factor->print & PRINT_DETERMINANT
|| factor->print & PRINT_KMO)
{
}
show_correlation_matrix (factor, idata);
+ covariance_destroy (cov);
{
+ gsl_matrix *am = matrix_dup (analysis_matrix);
gsl_eigen_symmv_workspace *workspace = gsl_eigen_symmv_alloc (factor->n_vars);
- gsl_eigen_symmv (matrix_dup (analysis_matrix), idata->eval, idata->evec, workspace);
+ gsl_eigen_symmv (am, idata->eval, idata->evec, workspace);
gsl_eigen_symmv_free (workspace);
+ gsl_matrix_free (am);
}
gsl_eigen_symmv_sort (idata->eval, idata->evec, GSL_EIGEN_SORT_ABS_DESC);
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);
+ gsl_matrix_free (factor_matrix);
+ gsl_vector_free (rotated_loadings);
gsl_vector_free (initial_communalities);
gsl_vector_free (extracted_communalities);
}