Remove property settings from psppire_data_window and put them into the GtkBuilder...
[pspp] / src / language / stats / factor.c
index cfec4a9a40890d7eb09a4c6bbdcc05c98d810bcd..a53e7334240c63aacfa7adad92f7a3ebdf6d2031 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 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 <libpspp/misc.h>
 #include <libpspp/message.h>
 
-#include <output/table.h>
+#include <output/tab.h>
 
+#include <output/charts/scree.h>
+#include <output/chart-item.h>
 
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
@@ -70,6 +72,12 @@ enum extraction_method
     EXTRACTION_PAF,
   };
 
+enum plot_opts
+  {
+    PLOT_SCREE = 0x0001,
+    PLOT_ROTATION = 0x0002
+  };
+
 enum print_opts
   {
     PRINT_UNIVARIATE  = 0x0001,
@@ -100,6 +108,7 @@ struct cmd_factor
   enum mv_class exclude;
   enum print_opts print;
   enum extraction_method extraction;
+  enum plot_opts plot;
 
   /* Extraction Criteria */
   int n_factors;
@@ -515,6 +524,8 @@ cmd_factor (struct lexer *lexer, struct dataset *ds)
   const struct dictionary *dict = dataset_dict (ds);
 
   struct cmd_factor factor;
+  factor.n_vars = 0;
+  factor.vars = NULL;
   factor.method = METHOD_CORR;
   factor.missing_type = MISS_LISTWISE;
   factor.exclude = MV_ANY;
@@ -526,6 +537,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds)
   factor.econverge = 0.001;
   factor.blank = 0;
   factor.sort = false;
+  factor.plot = 0;
 
   factor.wv = dict_get_weight (dict);
 
@@ -549,7 +561,6 @@ cmd_factor (struct lexer *lexer, struct dataset *ds)
     {
       lex_match (lexer, '/');
 
-
       if (lex_match_id (lexer, "PLOT"))
        {
           lex_match (lexer, '=');
@@ -557,6 +568,7 @@ cmd_factor (struct lexer *lexer, struct dataset *ds)
            {
              if (lex_match_id (lexer, "EIGEN"))
                {
+                 factor.plot |= PLOT_SCREE;
                }
 #if FACTOR_FULLY_IMPLEMENTED
              else if (lex_match_id (lexer, "ROTATION"))
@@ -914,6 +926,22 @@ communality (struct idata *idata, int n, int n_factors)
 }
 
 
+static void
+show_scree (const struct cmd_factor *f, struct idata *idata)
+{
+  struct scree *s;
+  const char *label ;
+
+  if ( !(f->plot & PLOT_SCREE) )
+    return;
+
+
+  label = f->extraction == EXTRACTION_PC ? _("Component Number") : _("Factor Number");
+
+  s = scree_create (idata->eval, label);
+
+  scree_submit (s);
+}
 
 static void
 show_communalities (const struct cmd_factor * factor,
@@ -937,12 +965,10 @@ show_communalities (const struct cmd_factor * factor,
   if (nc <= 1)
     return;
 
-  t = tab_create (nc, nr, 0);
+  t = tab_create (nc, nr);
 
   tab_title (t, _("Communalities"));
 
-  tab_dim (t, tab_natural_dimensions, NULL);
-
   tab_headers (t, heading_columns, 0, heading_rows, 0);
 
   c = 1;
@@ -997,15 +1023,13 @@ show_factor_matrix (const struct cmd_factor *factor, struct idata *idata, const
   const int nc = heading_columns + n_factors;
   gsl_permutation *perm;
 
-  struct tab_table *t = tab_create (nc, nr, 0);
+  struct tab_table *t = tab_create (nc, nr);
 
   if ( factor->extraction == EXTRACTION_PC )
     tab_title (t, _("Component Matrix"));
   else 
     tab_title (t, _("Factor Matrix"));
 
-  tab_dim (t, tab_natural_dimensions, NULL);
-
   tab_headers (t, heading_columns, 0, heading_rows, 0);
 
   if ( factor->extraction == EXTRACTION_PC )
@@ -1109,12 +1133,10 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata,
   if ( nc <= heading_columns)
     return;
 
-  t = tab_create (nc, nr, 0);
+  t = tab_create (nc, nr);
 
   tab_title (t, _("Total Variance Explained"));
 
-  tab_dim (t, tab_natural_dimensions, NULL);
-
   tab_headers (t, heading_columns, 0, heading_rows, 0);
 
   /* Outline the box */
@@ -1164,6 +1186,7 @@ show_explained_variance (const struct cmd_factor * factor, struct idata *idata,
   for (i = 0; i < (nc - heading_columns) / 3 ; ++i)
     {
       tab_text (t, i * 3 + 1, 1, TAB_CENTER | TAT_TITLE, _("Total"));
+      /* 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 %"));
 
@@ -1261,12 +1284,10 @@ show_correlation_matrix (const struct cmd_factor *factor, const struct idata *id
   if (nr <= heading_rows && suffix_rows == 0)
     return;
 
-  t = tab_create (nc, nr + suffix_rows, 0);
+  t = tab_create (nc, nr + suffix_rows);
 
   tab_title (t, _("Correlation Matrix"));
 
-  tab_dim (t, tab_natural_dimensions, NULL);
-
   tab_hline (t, TAL_1, 0, nc - 1, heading_rows);
 
   if (nr > heading_rows)
@@ -1406,9 +1427,8 @@ 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, 0);
+      struct tab_table *t = tab_create (nc, nr);
       tab_title (t, _("Descriptive Statistics"));
-      tab_dim (t, tab_natural_dimensions, NULL);
 
       tab_headers (t, heading_columns, 0, heading_rows, 0);
 
@@ -1533,6 +1553,8 @@ do_factor (const struct cmd_factor *factor, struct casereader *r)
 
     factor_matrix_workspace_free (fmw);
 
+    show_scree (factor, idata);
+
     show_factor_matrix (factor, idata, factor_matrix);
 
     gsl_vector_free (initial_communalities);