#include "math/correlation.h"
#include "math/covariance.h"
#include "math/moments.h"
-#include "output/chart-item.h"
#include "output/charts/scree.h"
#include "output/pivot-table.h"
typedef void (*rotation_coefficients) (double *x, double *y,
double a, double b, double c, double d,
- const gsl_matrix *loadings );
+ const gsl_matrix *loadings);
static void
varimax_coefficients (double *x, double *y,
double a, double b, double c, double d,
- const gsl_matrix *loadings )
+ const gsl_matrix *loadings)
{
*x = d - 2 * a * b / loadings->size1;
*y = c - (a * a - b * b) / loadings->size1;
static void
equamax_coefficients (double *x, double *y,
double a, double b, double c, double d,
- const gsl_matrix *loadings )
+ const gsl_matrix *loadings)
{
*x = d - loadings->size2 * a * b / loadings->size1;
*y = c - loadings->size2 * (a * a - b * b) / (2 * loadings->size1);
static struct idata *
idata_alloc (size_t n_vars)
{
- struct idata *id = xzalloc (sizeof (*id));
+ struct idata *id = XZALLOC (struct idata);
id->n_extractions = 0;
id->msr = gsl_vector_alloc (n_vars);
for (i = 0; i < m->size1; ++i)
{
- if (i == j ) continue;
+ if (i == j) continue;
ss += pow2 (gsl_matrix_get (m, i, j));
}
int i;
/* If there is a cached value, then return that. */
- if ( idata->n_extractions != 0)
+ if (idata->n_extractions != 0)
return idata->n_extractions;
/* Otherwise, if the number of factors has been explicitly requested,
gsl_vector_view row = gsl_matrix_row (mat, p->data[n - 1 - i]);
size_t maxindex = gsl_vector_max_index (&row.vector);
- if ( maxindex > column_n )
+ if (maxindex > column_n)
break;
/* All subsequent elements of this row, are of no interest.
gsl_permutation_free (p);
gsl_matrix_free (mat);
- assert ( 0 == gsl_permutation_valid (perm));
+ assert (0 == gsl_permutation_valid (perm));
/* We want the biggest value to be first */
gsl_permutation_reverse (perm);
l4s += lambda_4;
l2s += lambda_sq;
}
- sv += ( fm->size1 * l4s - (l2s * l2s) ) / (fm->size1 * fm->size1 );
+ sv += (fm->size1 * l4s - (l2s * l2s)) / (fm->size1 * fm->size1);
}
return sv;
}
phi = atan2 (x, y) / 4.0 ;
/* Don't bother rotating if the angle is small */
- if ( fabs (sin (phi) ) <= pow (10.0, -15.0))
+ if (fabs (sin (phi)) <= pow (10.0, -15.0))
continue;
for (p = 0; p < normalised->size1; ++p)
l2s += lambda_sq;
}
}
- sv += ( normalised->size1 * l4s - (l2s * l2s) ) / (normalised->size1 * normalised->size1 );
+ sv += (normalised->size1 * l4s - (l2s * l2s)) / (normalised->size1 * normalised->size1);
}
- if ( fabs (sv - prev_sv) <= cf->rconverge)
+ if (fabs (sv - prev_sv) <= cf->rconverge)
break;
prev_sv = sv;
gsl_vector_set (rotated_loadings, i, ssq);
- if ( sum < 0 )
+ if (sum < 0)
for (j = 0 ; j < result->size1; ++j)
{
double *lambda = gsl_matrix_ptr (result, j, i);
if (! lex_force_match (lexer, T_RPAREN))
goto error;
- mr = create_matrix_reader_from_case_reader (dict, matrix_reader,
- &factor.vars, &factor.n_vars);
+ mr = matrix_reader_create (dict, matrix_reader);
+ factor.vars = xmemdup (mr->cvars, mr->n_cvars * sizeof *mr->cvars);
+ factor.n_vars = mr->n_cvars;
}
else
{
free (factor.vars);
factor.vars = vars;
factor.n_vars = n_vars;
+
+ if (mr)
+ {
+ free (mr->cvars);
+ mr->cvars = xmemdup (vars, n_vars * sizeof *vars);
+ mr->n_cvars = n_vars;
+ }
}
else if (lex_match_id (lexer, "PLOT"))
{
{
if (lex_match_id (lexer, "FACTORS"))
{
- if ( lex_force_match (lexer, T_LPAREN)
+ if (lex_force_match (lexer, T_LPAREN)
&& lex_force_int (lexer))
{
factor.n_factors = lex_integer (lexer);
}
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))
{
factor.min_eigen = lex_number (lexer);
}
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))
{
factor.econverge = lex_number (lexer);
}
else if (lex_match_id (lexer, "ITERATE"))
{
- if ( lex_force_match (lexer, T_LPAREN)
- && lex_force_int (lexer))
+ if (lex_force_match (lexer, T_LPAREN)
+ && lex_force_int_range (lexer, "ITERATE", 0, INT_MAX))
{
n_iterations = lex_integer (lexer);
lex_get (lexer);
}
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))
{
factor.blank = lex_number (lexer);
}
}
- if ( factor.rotation == ROT_NONE )
+ if (factor.rotation == ROT_NONE)
factor.print &= ~PRINT_ROTATION;
if (factor.n_vars < 2)
{
struct idata *id = idata_alloc (factor.n_vars);
- while (next_matrix_from_reader (&id->mm, mr,
- factor.vars, factor.n_vars))
+ while (matrix_reader_next (&id->mm, mr, NULL))
{
do_factor_by_matrix (&factor, id);
- gsl_matrix_free (id->mm.corr);
- id->mm.corr = NULL;
- gsl_matrix_free (id->mm.cov);
- id->mm.cov = NULL;
+ gsl_matrix_free (id->ai_cov);
+ id->ai_cov = NULL;
+ gsl_matrix_free (id->ai_cor);
+ id->ai_cor = NULL;
+
+ matrix_material_uninit (&id->mm);
}
idata_free (id);
}
else
- if ( ! run_factor (ds, &factor))
+ if (! run_factor (ds, &factor))
goto error;
-
- destroy_matrix_reader (mr);
+ matrix_reader_destroy (mr);
free (factor.vars);
return CMD_SUCCESS;
error:
- destroy_matrix_reader (mr);
+ matrix_reader_destroy (mr);
free (factor.vars);
return CMD_FAILURE;
}
while (casegrouper_get_next_group (grouper, &group))
{
- if ( factor->missing_type == MISS_LISTWISE )
+ if (factor->missing_type == MISS_LISTWISE)
group = casereader_create_filter_missing (group, factor->vars, factor->n_vars,
factor->exclude,
NULL, NULL);
struct scree *s;
const char *label ;
- if ( !(f->plot & PLOT_SCREE) )
+ if (!(f->plot & PLOT_SCREE))
return;
/* Initialise to the identity permutation */
gsl_permutation *perm = gsl_permutation_calloc (factor->n_vars);
- if ( factor->sort)
+ if (factor->sort)
sort_matrix_indirect (fm, perm);
for (size_t i = 0 ; i < factor->n_vars; ++i)
for (size_t j = 0 ; j < n_factors; ++j)
{
double x = gsl_matrix_get (fm, matrix_row, j);
- if ( fabs (x) < factor->blank)
+ if (fabs (x) < factor->blank)
continue;
pivot_table_put2 (table, j, var_idx, pivot_value_new_number (x));
struct pivot_table *table = pivot_table_create (
N_("Total Variance Explained"));
- table->omit_empty = true;
- /* xgettext:no-c-format */
pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
N_("Total"), PIVOT_RC_OTHER,
+ /* xgettext:no-c-format */
N_("% of Variance"), PIVOT_RC_PERCENT,
+ /* xgettext:no-c-format */
N_("Cumulative %"), PIVOT_RC_PERCENT);
struct pivot_dimension *phase = pivot_dimension_create (
}
if (factor->print & PRINT_DETERMINANT)
- table->caption = pivot_value_new_user_text_nocopy (
- xasprintf ("%s: %.2f", _("Determinant"), idata->detR));
+ {
+ struct pivot_value *caption = pivot_value_new_user_text_nocopy (
+ xasprintf ("%s: %.2f", _("Determinant"), idata->detR));
+ pivot_table_set_caption (table, caption);
+ }
pivot_table_submit (table);
}
idata->cvm = covariance_1pass_create (factor->n_vars, factor->vars,
factor->wv, factor->exclude, true);
- for ( ; (c = casereader_read (r) ); case_unref (c))
+ for (; (c = casereader_read (r)); case_unref (c))
{
covariance_accumulate (idata->cvm, c);
}
static void
do_factor_by_matrix (const struct cmd_factor *factor, struct idata *idata)
{
- if (!idata->mm.cov && !idata->mm.corr)
+ if (!idata->mm.cov && !(idata->mm.corr && idata->mm.var_matrix))
{
- msg (ME, _("The dataset has no complete covariance or correlation matrix."));
+ msg (ME, _("The dataset has no covariance matrix or a "
+ "correlation matrix along with standard devications."));
return;
}
gsl_matrix_free (tmp);
}
- if ( factor->print & PRINT_UNIVARIATE)
+ if (factor->print & PRINT_UNIVARIATE
+ && idata->mm.n && idata->mm.mean_matrix && idata->mm.var_matrix)
{
struct pivot_table *table = pivot_table_create (
N_("Descriptive Statistics"));
pivot_table_submit (table);
}
- if (factor->print & PRINT_KMO)
+ if (factor->print & PRINT_KMO && idata->mm.n)
{
struct pivot_table *table = pivot_table_create (
N_("KMO and Bartlett's Test"));
struct factor_matrix_workspace *fmw = factor_matrix_workspace_alloc (idata->msr->size, idata->n_extractions);
gsl_matrix *factor_matrix = gsl_matrix_calloc (factor->n_vars, fmw->n_factors);
- if ( factor->extraction == EXTRACTION_PAF)
+ if (factor->extraction == EXTRACTION_PAF)
{
gsl_vector *diff = gsl_vector_alloc (idata->msr->size);
struct smr_workspace *ws = ws_create (idata->analysis_matrix);
gsl_vector_minmax (diff, &min, &max);
- if ( fabs (min) < factor->econverge && fabs (max) < factor->econverge)
+ if (fabs (min) < factor->econverge && fabs (max) < factor->econverge)
break;
}
gsl_vector_free (diff);
show_aic (factor, idata);
show_communalities (factor, initial_communalities, extracted_communalities);
- if ( factor->rotation != ROT_NONE)
+ if (factor->rotation != ROT_NONE)
{
rotated_factors = gsl_matrix_calloc (factor_matrix->size1, factor_matrix->size2);
rotated_loadings = gsl_vector_calloc (factor_matrix->size2);
? N_("Component Matrix") : N_("Factor Matrix")),
factor_matrix);
- if ( factor->rotation == ROT_PROMAX)
+ if (factor->rotation == ROT_PROMAX)
{
show_factor_matrix (factor, idata, N_("Pattern Matrix"),
pattern_matrix);
gsl_matrix_free (pattern_matrix);
}
- if ( factor->rotation != ROT_NONE)
+ if (factor->rotation != ROT_NONE)
{
show_factor_matrix (factor, idata,
(factor->rotation == ROT_PROMAX
gsl_matrix_free (rotated_factors);
}
- if ( factor->rotation == ROT_PROMAX)
+ if (factor->rotation == ROT_PROMAX)
{
show_factor_correlation (factor, fcm);
gsl_matrix_free (fcm);