[gnumeric] Add option to the regression tool to allow for multiple Y. [#620505]



commit c6c2ee12657985287724851c368b359bb26616b9
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Sun Jun 6 21:28:49 2010 -0600

    Add option to the regression tool to allow for multiple Y. [#620505]
    
    2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* analysis-tools.h (analysis_tools_data_regression_t): new field
    	* analysis-tools.c (analysis_tool_regression_engine_run): use
    	  analysis_tool_get_function
    	(analysis_tool_regression_simple_engine_run): use
    	  analysis_tool_get_function and obey the new multiple-y setting.
    
    2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* regression.glade: add new checkbox and move the selectors for
    	  the type of regression ahead of the input fields.
    	* dialog-analysis-tools.c (regression_tool_ok_clicked_cb):
    	  handle multiple-y
    	(regression_tool_update_sensitivity_cb): ditto
    	(dialog_regression_tool): ditto
    	(regression_tool_regression_radio_toggled_cb): new
    	(regression_tool_regression_check_toggled_cb): new

 NEWS                                |    1 +
 src/dialogs/ChangeLog               |   11 +++
 src/dialogs/dialog-analysis-tools.c |  101 ++++++++++++++++++++++++++-
 src/dialogs/regression.glade        |  128 +++++++++++++++++++++++------------
 src/tools/ChangeLog                 |    8 ++
 src/tools/analysis-tools.c          |  121 +++++++++++++++------------------
 src/tools/analysis-tools.h          |    1 +
 7 files changed, 257 insertions(+), 114 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4b39d19..81c1eb7 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Andreas:
 	* Make changing the scope of a named expression undoable.
 	* Add search tool to paste- and define-names dialogs. [#465840]
 	* Check whether defined names are in use before deleting them.
+	* Add option to the regression tool to allow for multiple Y. [#620505]
 
 Jean:
 	* Do not ungrab a not grabbed item. [#620369]
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index 9f456fd..e3264f3 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,5 +1,16 @@
 2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
 
+	* regression.glade: add new checkbox and move the selectors for
+	  the type of regression ahead of the input fields.
+	* dialog-analysis-tools.c (regression_tool_ok_clicked_cb):
+	  handle multiple-y
+	(regression_tool_update_sensitivity_cb): ditto
+	(dialog_regression_tool): ditto
+	(regression_tool_regression_radio_toggled_cb): new
+	(regression_tool_regression_check_toggled_cb): new
+
+2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
+
 	* dialog-define-names.c (name_guru_warn): implement
 
 2010-06-04 Andreas J. Guelzow <aguelzow pyrshep ca>
diff --git a/src/dialogs/dialog-analysis-tools.c b/src/dialogs/dialog-analysis-tools.c
index 4a95a92..243e25d 100644
--- a/src/dialogs/dialog-analysis-tools.c
+++ b/src/dialogs/dialog-analysis-tools.c
@@ -233,6 +233,8 @@ typedef struct {
 typedef struct {
 	GenericToolState base;
 	GtkWidget *confidence_entry;
+	GtkWidget *simple_linear_regression_radio;
+	GtkWidget *switch_variables_check;
 } RegressionToolState;
 
 typedef struct {
@@ -2171,8 +2173,12 @@ regression_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget *button,
 	w = glade_xml_get_widget (state->base.gui, "intercept-button");
 	data->intercept = 1 - gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
 
-	w = glade_xml_get_widget (state->base.gui, "multiple-regression-button");
-	data->multiple_regression = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
+	data->multiple_regression 
+		= !gtk_toggle_button_get_active 
+		(GTK_TOGGLE_BUTTON (state->simple_linear_regression_radio));
+
+	data->multiple_y = gtk_toggle_button_get_active 
+		(GTK_TOGGLE_BUTTON (state->switch_variables_check));
 
 	if (cmd_analysis_tool (WORKBOOK_CONTROL (state->base.wbcg), state->base.sheet,
 			       dao, data, analysis_tool_regression_engine)) {
@@ -2212,13 +2218,19 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
         GnmValue *input_range_2;
 	gint y_h, y_w;
 	gint x_h, x_w;
+	gboolean switch_v;
+
+	switch_v = gtk_toggle_button_get_active 
+		(GTK_TOGGLE_BUTTON (state->switch_variables_check));
 
 	/* Checking Input Range */
         input_range_2 = gnm_expr_entry_parse_as_value (
 		GNM_EXPR_ENTRY (state->base.input_entry_2), state->base.sheet);
 	if (input_range_2 == NULL) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
-				    _("The y variable range is invalid."));
+				    switch_v ?
+				    _("The x variable range is invalid.") :
+				    _("The y variable range is invalid.") );
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
 	}
@@ -2229,18 +2241,24 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
 
 	if (y_h == 0 || y_w == 0) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
+				    switch_v ?
+				    _("The x variable range is invalid.") :
 				    _("The y variable range is invalid."));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
 	}
 	if (y_h != 1 && y_w != 1) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
+				    switch_v ?
+				    _("The x variable range must be a vector (n by 1 or 1 by n).") :
 				    _("The y variable range must be a vector (n by 1 or 1 by n)."));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
 	}
 	if (y_h <= 2 && y_w <= 2) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
+				    switch_v ?
+				    _("The x variable range is to small") :
 				    _("The y variable range is to small"));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
@@ -2250,6 +2268,8 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
 		(GNM_EXPR_ENTRY (state->base.input_entry), state->base.sheet);
 	if (input_range == NULL) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
+				    switch_v ?
+				    _("The y variables range is invalid.") :
 				    _("The x variables range is invalid."));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
@@ -2261,6 +2281,8 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
 
 	if (x_h == 0 || x_w == 0) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
+				    switch_v ?
+				    _("The y variables range is invalid.") :
 				    _("The x variables range is invalid."));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
@@ -2268,7 +2290,9 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
 
 	if ((y_h == 1 && y_w != x_w) || (y_w == 1 && y_h != x_h)) {
 		gtk_label_set_text (GTK_LABEL (state->base.warning),
-				    _("The sizes of the x variable and y variable ranges do not match."));
+				    switch_v ?
+				    _("The sizes of the y variable and x variables ranges do not match.") :
+				    _("The sizes of the x variable and y variables ranges do not match."));
 		gtk_widget_set_sensitive (state->base.ok_button, FALSE);
 		return;
 	}
@@ -2294,6 +2318,50 @@ regression_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
 	gtk_widget_set_sensitive (state->base.ok_button, TRUE);
 }
 
+static void
+regression_tool_regression_radio_toggled_cb (G_GNUC_UNUSED 
+					     GtkToggleButton *togglebutton,
+					     RegressionToolState *state) 
+{
+	if (!gtk_toggle_button_get_active 
+	    (GTK_TOGGLE_BUTTON (state->simple_linear_regression_radio)))
+		gtk_toggle_button_set_active 
+			(GTK_TOGGLE_BUTTON (state->switch_variables_check), 
+			 FALSE);
+}
+
+static void
+regression_tool_regression_check_toggled_cb (G_GNUC_UNUSED 
+					     GtkToggleButton *togglebutton,
+					     RegressionToolState *state) 
+{
+	GtkWidget *w1, *w2;
+
+	w1 = glade_xml_get_widget 
+		(state->base.gui, "var1-label");
+	w2 = glade_xml_get_widget 
+		(state->base.gui, "var2-label");
+
+	if (gtk_toggle_button_get_active 
+	    (GTK_TOGGLE_BUTTON (state->switch_variables_check))) {
+ 		gtk_toggle_button_set_active 
+			(GTK_TOGGLE_BUTTON 
+			 (state->simple_linear_regression_radio), 
+			 TRUE);
+		gtk_label_set_markup_with_mnemonic  (GTK_LABEL (w1),
+						     _("_Y variables:"));
+		gtk_label_set_markup_with_mnemonic  (GTK_LABEL (w2),
+						     _("_X variable:"));
+	} else {
+		gtk_label_set_markup_with_mnemonic  (GTK_LABEL (w1),
+						     _("_X variables:"));
+		gtk_label_set_markup_with_mnemonic  (GTK_LABEL (w2),
+						     _("_Y variable:"));		
+	}
+	regression_tool_update_sensitivity_cb (NULL, state);
+}
+
+
 /**
  * dialog_regression_tool:
  * @wbcg:
@@ -2341,6 +2409,31 @@ dialog_regression_tool (WBCGtk *wbcg, Sheet *sheet)
 	gnumeric_editable_enters (GTK_WINDOW (state->base.dialog),
 				  GTK_WIDGET (state->confidence_entry));
 
+	state->simple_linear_regression_radio 
+		= glade_xml_get_widget 
+		(state->base.gui, "simple-regression-button");
+	state->switch_variables_check 
+		= glade_xml_get_widget 
+		(state->base.gui, "multiple-independent-check");
+	gtk_toggle_button_set_active 
+		(GTK_TOGGLE_BUTTON (state->simple_linear_regression_radio),
+		 FALSE);
+	gtk_toggle_button_set_active 
+		(GTK_TOGGLE_BUTTON (state->switch_variables_check),
+		 FALSE);
+	g_signal_connect 
+		(G_OBJECT (state->simple_linear_regression_radio),
+		 "toggled",
+		 G_CALLBACK (regression_tool_regression_radio_toggled_cb), 
+		 state);
+	g_signal_connect 
+		(G_OBJECT (state->switch_variables_check),
+		 "toggled",
+		 G_CALLBACK (regression_tool_regression_check_toggled_cb), 
+		 state);
+   
+
+
 	gnm_dao_set_put (GNM_DAO (state->base.gdao), TRUE, TRUE);
 	regression_tool_update_sensitivity_cb (NULL, state);
 	tool_load_selection ((GenericToolState *)state, TRUE);
diff --git a/src/dialogs/regression.glade b/src/dialogs/regression.glade
index f902c84..9b700dc 100644
--- a/src/dialogs/regression.glade
+++ b/src/dialogs/regression.glade
@@ -4,7 +4,7 @@
   <!-- interface-naming-policy toplevel-contextual -->
   <widget class="GtkDialog" id="Regression">
     <property name="title" translatable="yes">Regression</property>
-    <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+    <property name="type_hint">dialog</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="vbox1">
@@ -18,7 +18,7 @@
               <widget class="GtkTable" id="input-table">
                 <property name="visible">True</property>
                 <property name="border_width">12</property>
-                <property name="n_rows">3</property>
+                <property name="n_rows">8</property>
                 <property name="n_columns">2</property>
                 <property name="column_spacing">12</property>
                 <property name="row_spacing">6</property>
@@ -29,11 +29,13 @@
                     <property name="xpad">5</property>
                     <property name="label" translatable="yes">_X variables:</property>
                     <property name="use_underline">True</property>
-                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                    <property name="justify">right</property>
                   </widget>
                   <packing>
+                    <property name="top_attach">4</property>
+                    <property name="bottom_attach">5</property>
                     <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"></property>
+                    <property name="y_options">GTK_SHRINK</property>
                   </packing>
                 </child>
                 <child>
@@ -43,13 +45,13 @@
                     <property name="xpad">5</property>
                     <property name="label" translatable="yes">_Y variable:</property>
                     <property name="use_underline">True</property>
-                    <property name="justify">GTK_JUSTIFY_RIGHT</property>
+                    <property name="justify">right</property>
                   </widget>
                   <packing>
-                    <property name="top_attach">1</property>
-                    <property name="bottom_attach">2</property>
+                    <property name="top_attach">5</property>
+                    <property name="bottom_attach">6</property>
                     <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"></property>
+                    <property name="y_options">GTK_SHRINK</property>
                   </packing>
                 </child>
                 <child>
@@ -62,13 +64,80 @@
                     <property name="draw_indicator">True</property>
                   </widget>
                   <packing>
+                    <property name="top_attach">6</property>
+                    <property name="bottom_attach">7</property>
+                    <property name="x_options">GTK_FILL</property>
+                    <property name="y_options">GTK_SHRINK</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="multiple-regression-button">
+                    <property name="label" translatable="yes">_Multiple linear regression</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="border_width">3</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="right_attach">2</property>
+                    <property name="y_options">GTK_SHRINK</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkRadioButton" id="simple-regression-button">
+                    <property name="label" translatable="yes">Multiple 2-_variable regressions</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="border_width">3</property>
+                    <property name="use_underline">True</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">multiple-regression-button</property>
+                  </widget>
+                  <packing>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="y_options">GTK_SHRINK</property>
+                  </packing>
+                </child>
+                <child>
+                  <widget class="GtkCheckButton" id="multiple-independent-check">
+                    <property name="label" translatable="yes">Multiple dependent (y) variables</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="draw_indicator">True</property>
+                  </widget>
+                  <packing>
+                    <property name="right_attach">2</property>
                     <property name="top_attach">2</property>
                     <property name="bottom_attach">3</property>
-                    <property name="x_options">GTK_FILL</property>
-                    <property name="y_options"></property>
+                    <property name="y_options">GTK_SHRINK</property>
+                    <property name="x_padding">40</property>
                   </packing>
                 </child>
                 <child>
+                  <widget class="GtkHSeparator" id="hseparator1">
+                    <property name="visible">True</property>
+                  </widget>
+                  <packing>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">3</property>
+                    <property name="bottom_attach">4</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
                   <placeholder/>
                 </child>
                 <child>
@@ -102,7 +171,7 @@
                         <property name="visible">True</property>
                         <property name="xpad">5</property>
                         <property name="label" translatable="yes">Confidence level:</property>
-                        <property name="justify">GTK_JUSTIFY_CENTER</property>
+                        <property name="justify">center</property>
                       </widget>
                       <packing>
                         <property name="expand">False</property>
@@ -144,39 +213,10 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkRadioButton" id="multiple-regression-button">
-                    <property name="label" translatable="yes">_Multiple linear regression</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="border_width">3</property>
-                    <property name="use_underline">True</property>
-                    <property name="active">True</property>
-                    <property name="draw_indicator">True</property>
-                  </widget>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">2</property>
-                  </packing>
+                  <placeholder/>
                 </child>
                 <child>
-                  <widget class="GtkRadioButton" id="simple-regression-button">
-                    <property name="label" translatable="yes">Multiple 2-_variable regressions</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="border_width">3</property>
-                    <property name="use_underline">True</property>
-                    <property name="active">True</property>
-                    <property name="draw_indicator">True</property>
-                    <property name="group">multiple-regression-button</property>
-                  </widget>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">3</property>
-                  </packing>
+                  <placeholder/>
                 </child>
                 <child>
                   <placeholder/>
@@ -238,7 +278,7 @@
         <child internal-child="action_area">
           <widget class="GtkHButtonBox" id="hbuttonbox1">
             <property name="visible">True</property>
-            <property name="layout_style">GTK_BUTTONBOX_END</property>
+            <property name="layout_style">end</property>
             <child>
               <widget class="GtkButton" id="helpbutton">
                 <property name="label">gtk-help</property>
@@ -288,7 +328,7 @@
           </widget>
           <packing>
             <property name="expand">False</property>
-            <property name="pack_type">GTK_PACK_END</property>
+            <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
         </child>
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index 83c1555..6d998d4 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,3 +1,11 @@
+2010-06-06 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* analysis-tools.h (analysis_tools_data_regression_t): new field
+	* analysis-tools.c (analysis_tool_regression_engine_run): use
+	  analysis_tool_get_function
+	(analysis_tool_regression_simple_engine_run): use 
+	  analysis_tool_get_function and obey the new multiple-y setting. 
+	
 2010-06-02  Morten Welinder  <terra gnome org>
 
 	* gnm-solver.c (gnm_solver_set_status, gnm_solver_elapsed):
diff --git a/src/tools/analysis-tools.c b/src/tools/analysis-tools.c
index 0b0d7fd..25e3f22 100644
--- a/src/tools/analysis-tools.c
+++ b/src/tools/analysis-tools.c
@@ -2850,15 +2850,15 @@ analysis_tool_regression_engine_run (data_analysis_output_t *dao,
 	GnmExpr const *expr_upper;
 	GnmExpr const *expr_confidence;
 
-	GnmFunc *fd_linest;
-	GnmFunc *fd_index;
-	GnmFunc *fd_fdist;
-	GnmFunc *fd_sum;
-	GnmFunc *fd_sqrt;
-	GnmFunc *fd_tdist;
-	GnmFunc *fd_abs;
-	GnmFunc *fd_tinv;
-	GnmFunc *fd_transpose;
+	GnmFunc *fd_linest    = analysis_tool_get_function ("LINEST", dao);
+	GnmFunc *fd_index     = analysis_tool_get_function ("INDEX", dao);
+	GnmFunc *fd_fdist     = analysis_tool_get_function ("FDIST", dao);
+	GnmFunc *fd_sum       = analysis_tool_get_function ("SUM", dao);
+	GnmFunc *fd_sqrt      = analysis_tool_get_function ("SQRT", dao);
+	GnmFunc *fd_tdist     = analysis_tool_get_function ("TDIST", dao);
+	GnmFunc *fd_abs       = analysis_tool_get_function ("ABS", dao);
+	GnmFunc *fd_tinv      = analysis_tool_get_function ("TINV", dao);
+	GnmFunc *fd_transpose = analysis_tool_get_function ("TRANSPOSE", dao);
 	GnmFunc *fd_concatenate = NULL;
 	GnmFunc *fd_cell = NULL;
 	GnmFunc *fd_offset = NULL;
@@ -2867,31 +2867,11 @@ analysis_tool_regression_engine_run (data_analysis_output_t *dao,
 	char const *label = ((info->group_by == GROUPED_BY_ROW) ? _("Row")
 			     : _("Column"));
 
-	fd_linest = gnm_func_lookup_or_add_placeholder ("LINEST", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_linest);
-	fd_index = gnm_func_lookup_or_add_placeholder ("INDEX", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_index);
-	fd_fdist = gnm_func_lookup_or_add_placeholder ("FDIST", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_fdist);
-	fd_sum = gnm_func_lookup_or_add_placeholder ("SUM", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_sum);
-	fd_sqrt = gnm_func_lookup_or_add_placeholder ("SQRT", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_sqrt);
-	fd_tdist = gnm_func_lookup_or_add_placeholder ("TDIST", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_tdist);
-	fd_abs = gnm_func_lookup_or_add_placeholder ("ABS", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_abs);
-	fd_tinv = gnm_func_lookup_or_add_placeholder ("TINV", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_tinv);
-	fd_transpose = gnm_func_lookup_or_add_placeholder ("TRANSPOSE", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_transpose);
 	if (!info->base.labels) {
-		fd_concatenate = gnm_func_lookup_or_add_placeholder ("CONCATENATE", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-		gnm_func_ref (fd_concatenate);
-		fd_cell = gnm_func_lookup_or_add_placeholder ("CELL", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-		gnm_func_ref (fd_cell);
-		fd_offset = gnm_func_lookup_or_add_placeholder ("OFFSET", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-		gnm_func_ref (fd_offset);
+		fd_concatenate = analysis_tool_get_function ("CONCATENATE",
+							     dao);
+		fd_cell        = analysis_tool_get_function ("CELL", dao);
+		fd_offset      = analysis_tool_get_function ("OFFSET", dao);
 	}
 
 	cb_adjust_areas (val_1, NULL);
@@ -3306,44 +3286,47 @@ static gboolean
 analysis_tool_regression_simple_engine_run (data_analysis_output_t *dao,
 				     analysis_tools_data_regression_t *info)
 {
-	GnmFunc *fd_linest;
-	GnmFunc *fd_index;
-	GnmFunc *fd_fdist;
-	GnmFunc *fd_rows;
-	GnmFunc *fd_columns;
+	GnmFunc *fd_linest  = analysis_tool_get_function ("LINEST", dao);
+	GnmFunc *fd_index   = analysis_tool_get_function ("INDEX", dao);
+	GnmFunc *fd_fdist   = analysis_tool_get_function ("FDIST", dao);
+	GnmFunc *fd_rows    = analysis_tool_get_function ("ROWS", dao);
+	GnmFunc *fd_columns = analysis_tool_get_function ("COLUMNS", dao);
 
 	GSList *inputdata;
 	guint row;
 
 	GnmValue *val_dep = value_dup (info->base.range_2);
-	GnmExpr const *expr_intercept = gnm_expr_new_constant (value_new_bool (info->intercept));
+	GnmExpr const *expr_intercept 
+		= gnm_expr_new_constant (value_new_bool (info->intercept));
 	GnmExpr const *expr_observ;
 	GnmExpr const *expr_val_dep;
 
-	fd_linest = gnm_func_lookup_or_add_placeholder ("LINEST", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_linest);
-	fd_index = gnm_func_lookup_or_add_placeholder ("INDEX", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_index);
-	fd_fdist = gnm_func_lookup_or_add_placeholder ("FDIST", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_fdist);
-	fd_rows = gnm_func_lookup_or_add_placeholder ("ROWS", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_rows);
-	fd_columns = gnm_func_lookup_or_add_placeholder ("COLUMNS", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
-	gnm_func_ref (fd_columns);
-
 	dao_set_italic (dao, 0, 0, 4, 0);
 	dao_set_italic (dao, 0, 2, 5, 2);
-        set_cell_text_row (dao, 0, 0, _("/SUMMARY OUTPUT"
-					"/"
-					"/Response Variable:"
-					"/"
-					"/Observations:"));
-        set_cell_text_row (dao, 0, 2, _("/Independent Variable"
-					"/R^2"
-					"/Slope"
-					"/Intercept"
-					"/F"
-					"/Significance of F"));
+        set_cell_text_row (dao, 0, 0, info->multiple_y ?
+			   _("/SUMMARY OUTPUT"
+			     "/"
+			     "/Independent Variable:"
+			     "/"
+			     "/Observations:") :
+			   _("/SUMMARY OUTPUT"
+			     "/"
+			     "/Response Variable:"
+			     "/"
+			     "/Observations:"));
+        set_cell_text_row (dao, 0, 2, info->multiple_y ?
+			   _("/Response Variable"
+			     "/R^2"
+			     "/Slope"
+			     "/Intercept"
+			     "/F"
+			     "/Significance of F") :
+			   _("/Independent Variable"
+			     "/R^2"
+			     "/Slope"
+			     "/Intercept"
+			     "/F"
+			     "/Significance of F"));
 	analysis_tools_write_a_label (val_dep, dao,
 				      info->base.labels, info->group_by,
 				      3, 0);
@@ -3363,11 +3346,17 @@ analysis_tool_regression_simple_engine_run (data_analysis_output_t *dao,
 		analysis_tools_write_a_label (val_indep, dao,
 					      info->base.labels, info->group_by,
 					      0, row);
-		expr_linest = gnm_expr_new_funcall4 (fd_linest,
-						     gnm_expr_copy (expr_val_dep),
-						     gnm_expr_new_constant (val_indep),
-						     gnm_expr_copy (expr_intercept),
-						     gnm_expr_new_constant (value_new_bool (TRUE)));
+		expr_linest = info->multiple_y ?
+			gnm_expr_new_funcall4 (fd_linest,
+					       gnm_expr_new_constant (val_indep),
+					       gnm_expr_copy (expr_val_dep),
+					       gnm_expr_copy (expr_intercept),
+					       gnm_expr_new_constant (value_new_bool (TRUE))) :
+			gnm_expr_new_funcall4 (fd_linest,
+					       gnm_expr_copy (expr_val_dep),
+					       gnm_expr_new_constant (val_indep),
+					       gnm_expr_copy (expr_intercept),
+					       gnm_expr_new_constant (value_new_bool (TRUE)));
 		dao_set_cell_array_expr (dao, 1, row,
 				 gnm_expr_new_funcall3 (fd_index,
 							gnm_expr_copy (expr_linest),
diff --git a/src/tools/analysis-tools.h b/src/tools/analysis-tools.h
index bab0fa6..b9d2347 100644
--- a/src/tools/analysis-tools.h
+++ b/src/tools/analysis-tools.h
@@ -170,6 +170,7 @@ typedef struct {
 	gint       intercept;
 	group_by_t group_by;
 	gboolean   multiple_regression;
+        gboolean   multiple_y;
 	GSList    *indep_vars;
 } analysis_tools_data_regression_t;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]