Commit 0aaae76b authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Implemented F-Test tool.

1999-07-06  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/analysis-tools.c, src/dialog-analysis-tools.c,
 	src/dialogs.h: Implemented F-Test tool.
parent d68a5fd5
......@@ -11,9 +11,10 @@ Jukka:
- Implemented Correlation and Covariance tools
- Implemented Descriptive Statistics Tool
- Implemented Sampling Tool
- Implemented t-Test Tools (paired, assuming equal variance and
- Implemented t-Test Tools (paired, assuming equal variance, and
assuming unequal variance)
- Implemented z-Test Tool
- Implemented F-Test Tool
* Added the following functions:
- FORECAST() and INTERCEPT().
* And fixed these functions:
......
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
src/dialogs.h: Implemented F-Test tool.
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
......
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
src/dialogs.h: Implemented F-Test tool.
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
......
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
src/dialogs.h: Implemented F-Test tool.
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
......
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
src/dialogs.h: Implemented F-Test tool.
1999-07-06 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/analysis-tools.c, src/dialog-analysis-tools.c,
......
......@@ -1151,7 +1151,7 @@ ttest_paired_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
sprintf(buf, "%f", p);
set_cell(dao, 1, 8, buf);
/* t Critical two-tail */
/* t Critical one-tail */
sprintf(buf, "%f", 0.0); /* TODO */
set_cell(dao, 1, 9, buf);
......@@ -1259,7 +1259,7 @@ ttest_eq_var_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
sprintf(buf, "%f", p);
set_cell(dao, 1, 8, buf);
/* t Critical two-tail */
/* t Critical one-tail */
sprintf(buf, "%f", 0.0); /* TODO */
set_cell(dao, 1, 9, buf);
......@@ -1360,7 +1360,7 @@ ttest_neq_var_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
sprintf(buf, "%f", p);
set_cell(dao, 1, 7, buf);
/* t Critical two-tail */
/* t Critical one-tail */
sprintf(buf, "%f", 0.0); /* TODO */
set_cell(dao, 1, 8, buf);
......@@ -1378,3 +1378,100 @@ ttest_neq_var_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
return 0;
}
/************* F-Test Tool *********************************************
*
* The results are given in a table which can be printed out in a new
* sheet, in a new workbook, or simply into an existing sheet.
*
* TODO: a new workbook output and output to an existing sheet
*
**/
/* F-Test: Two-Sample for Variances
*/
int
ftest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
Range *input_range2, float_t alpha,
data_analysis_output_t *dao)
{
data_set_t set_one, set_two;
float_t mean1, mean2, var1, var2, f, p, df1, df2, c;
char buf[256];
if (dao->type == NewSheetOutput) {
dao->sheet = sheet_new(wb, "F-Test");
dao->start_col = dao->start_row = 0;
workbook_attach_sheet(wb, dao->sheet);
}
get_data(sheet, input_range1, &set_one);
get_data(sheet, input_range2, &set_two);
set_cell (dao, 0, 0, "");
set_cell (dao, 1, 0, "Variable 1");
set_cell (dao, 2, 0, "Variable 2");
set_cell (dao, 0, 1, "Mean");
set_cell (dao, 0, 2, "Variance");
set_cell (dao, 0, 3, "Observations");
set_cell (dao, 0, 4, "df");
set_cell (dao, 0, 5, "F");
set_cell (dao, 0, 6, "P(F<=f) one-tail");
set_cell (dao, 0, 7, "F Critical one-tail");
mean1 = set_one.sum / set_one.n;
mean2 = set_two.sum / set_two.n;
var1 = (set_one.sqrsum - set_one.sum2/set_one.n) / (set_one.n - 1);
var2 = (set_two.sqrsum - set_two.sum2/set_two.n) / (set_two.n - 1);
c = (var1/set_one.n) / (var1/set_one.n+var2/set_two.n);
df1 = set_one.n-1;
df2 = set_two.n-1;
f = var1 / var2;
p = 1.0 - pf(f, df1, df2);
/* Mean */
sprintf(buf, "%f", mean1);
set_cell(dao, 1, 1, buf);
sprintf(buf, "%f", mean2);
set_cell(dao, 2, 1, buf);
/* Variance */
sprintf(buf, "%f", var1);
set_cell(dao, 1, 2, buf);
sprintf(buf, "%f", var2);
set_cell(dao, 2, 2, buf);
/* Observations */
sprintf(buf, "%d", set_one.n);
set_cell(dao, 1, 3, buf);
sprintf(buf, "%d", set_two.n);
set_cell(dao, 2, 3, buf);
/* df */
sprintf(buf, "%f", df1);
set_cell(dao, 1, 4, buf);
sprintf(buf, "%f", df2);
set_cell(dao, 2, 4, buf);
/* F */
sprintf(buf, "%f", f);
set_cell(dao, 1, 5, buf);
/* P(F<=f) one-tail */
sprintf(buf, "%f", p);
set_cell(dao, 1, 6, buf);
/* t Critical one-tail */
sprintf(buf, "%f", 0.0); /* TODO */
set_cell(dao, 1, 7, buf);
free_data_set(&set_one);
free_data_set(&set_two);
return 0;
}
......@@ -26,6 +26,7 @@ static void dialog_ztest_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_paired_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_eq_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_neq_tool(Workbook *wb, Sheet *sheet);
static void dialog_ftest_tool(Workbook *wb, Sheet *sheet);
typedef void (*tool_fun_ptr_t)(Workbook *wb, Sheet *sheet);
......@@ -52,6 +53,8 @@ tool_list_t tools[] = {
{ { "Correlation", NULL }, dummy_fun },
{ { "Covariance", NULL }, dummy_fun },
{ { "Descriptive Statistics", NULL }, dummy_fun },
{ { "F-Test: Two-Sample for Variances", NULL },
dialog_ftest_tool },
{ { "Sampling", NULL }, dummy_fun },
{ { "t-Test: Paired Two Sample for Means", NULL },
dialog_ttest_paired_tool },
......@@ -207,7 +210,7 @@ tool_dialog_range(Workbook *wb, Sheet *sheet, int ti)
input_range);
group_ops = NULL;
if (ti == 3)
if (ti == 4)
goto skip_groupped;
groupped_label = gtk_label_new ("Groupped By:");
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
......@@ -233,7 +236,7 @@ tool_dialog_range(Workbook *wb, Sheet *sheet, int ti)
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG
(dialog[ti])->vbox),
check_buttons, TRUE, TRUE, 0);
} else if (ti == 3) {
} else if (ti == 4) {
GtkWidget *sampling_label =
gtk_label_new ("Sampling Method:");
GtkWidget *sampling_box;
......@@ -290,7 +293,7 @@ tool_dialog_loop:
return;
}
if (ti != 3)
if (ti != 4)
i = gtk_radio_group_get_selected (group_ops);
text = gtk_entry_get_text (GTK_ENTRY (input_range));
......@@ -328,7 +331,7 @@ tool_dialog_loop:
descriptive_stat_tool(wb, sheet, &range_input, !i, &ds, &dao);
break;
case 3:
case 4:
i = gtk_radio_group_get_selected(sampling_ops);
text = gtk_entry_get_text (GTK_ENTRY (sampling_entry[i]));
size = atoi(text);
......@@ -769,6 +772,95 @@ ttest_dialog_loop:
gnome_dialog_close (GNOME_DIALOG (dialog));
}
static void
dialog_ftest_tool(Workbook *wb, Sheet *sheet)
{
static GtkWidget *dialog, *box;
static GtkWidget *range1_entry, *range2_entry;
static GtkWidget *alpha_entry;
data_analysis_output_t dao;
float_t alpha;
char *text;
int selection;
static Range range_input1, range_input2;
int i=0, size;
if (!dialog) {
dialog = new_dialog("F-Test: Two-Sample for Variances",
wb->toplevel);
box = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
(dialog)->vbox), box);
range1_entry = hbox_pack_label_and_entry
("Variable 1 Range:", "", 20, box);
range2_entry = hbox_pack_label_and_entry
("Variable 2 Range:", "", 20, box);
alpha_entry = hbox_pack_label_and_entry("Alpha:", "0.95",
20, box);
gtk_widget_show_all (dialog);
} else
gtk_widget_show_all (dialog);
gtk_widget_grab_focus (range1_entry);
ttest_dialog_loop:
selection = gnome_dialog_run (GNOME_DIALOG (dialog));
if (selection == 1) {
gnome_dialog_close (GNOME_DIALOG (dialog));
return;
}
text = gtk_entry_get_text (GTK_ENTRY (range1_entry));
if (!parse_range (text, &range_input1.start_col,
&range_input1.start_row,
&range_input1.end_col,
&range_input1.end_row)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell range "
"in 'Variable 1:'"));
gtk_widget_grab_focus (range1_entry);
gtk_entry_set_position(GTK_ENTRY (range1_entry), 0);
gtk_entry_select_region(GTK_ENTRY (range1_entry), 0,
GTK_ENTRY(range1_entry)->text_length);
goto ttest_dialog_loop;
}
text = gtk_entry_get_text (GTK_ENTRY (range2_entry));
if (!parse_range (text, &range_input2.start_col,
&range_input2.start_row,
&range_input2.end_col,
&range_input2.end_row)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell range "
"in 'Variable 2:'"));
gtk_widget_grab_focus (range2_entry);
gtk_entry_set_position(GTK_ENTRY (range2_entry), 0);
gtk_entry_select_region(GTK_ENTRY (range2_entry), 0,
GTK_ENTRY(range2_entry)->text_length);
goto ttest_dialog_loop;
}
text = gtk_entry_get_text (GTK_ENTRY (alpha_entry));
alpha = atof(text);
/* TODO: radio buttos for outputs */
dao.type = NewSheetOutput;
ftest_tool (wb, sheet, &range_input1, &range_input2, alpha, &dao);
workbook_focus_sheet(sheet);
gnome_dialog_close (GNOME_DIALOG (dialog));
}
static void
selection_made(GtkWidget *clist, gint row, gint column,
......@@ -826,7 +918,7 @@ dialog_data_analysis (Workbook *wb, Sheet *sheet)
if (selection == 0) {
g_return_if_fail (tools[selected_row].fun != NULL);
if (selected_row >= 4)
if (selected_row >= 5 || selected_row == 3)
tools[selected_row].fun(wb, sheet);
else
tool_dialog_range(wb, sheet, selected_row);
......
......@@ -60,6 +60,10 @@ int sampling_tool (Workbook *wb, Sheet *sheet, Range *input_range,
gboolean periodic_flag, int size,
data_analysis_output_t *dao);
int ftest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
Range *input_range2, float_t alpha,
data_analysis_output_t *dao);
int ttest_paired_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
Range *input_range2, float_t mean_diff, float_t alpha,
data_analysis_output_t *dao);
......
......@@ -26,6 +26,7 @@ static void dialog_ztest_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_paired_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_eq_tool(Workbook *wb, Sheet *sheet);
static void dialog_ttest_neq_tool(Workbook *wb, Sheet *sheet);
static void dialog_ftest_tool(Workbook *wb, Sheet *sheet);
typedef void (*tool_fun_ptr_t)(Workbook *wb, Sheet *sheet);
......@@ -52,6 +53,8 @@ tool_list_t tools[] = {
{ { "Correlation", NULL }, dummy_fun },
{ { "Covariance", NULL }, dummy_fun },
{ { "Descriptive Statistics", NULL }, dummy_fun },
{ { "F-Test: Two-Sample for Variances", NULL },
dialog_ftest_tool },
{ { "Sampling", NULL }, dummy_fun },
{ { "t-Test: Paired Two Sample for Means", NULL },
dialog_ttest_paired_tool },
......@@ -207,7 +210,7 @@ tool_dialog_range(Workbook *wb, Sheet *sheet, int ti)
input_range);
group_ops = NULL;
if (ti == 3)
if (ti == 4)
goto skip_groupped;
groupped_label = gtk_label_new ("Groupped By:");
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
......@@ -233,7 +236,7 @@ tool_dialog_range(Workbook *wb, Sheet *sheet, int ti)
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG
(dialog[ti])->vbox),
check_buttons, TRUE, TRUE, 0);
} else if (ti == 3) {
} else if (ti == 4) {
GtkWidget *sampling_label =
gtk_label_new ("Sampling Method:");
GtkWidget *sampling_box;
......@@ -290,7 +293,7 @@ tool_dialog_loop:
return;
}
if (ti != 3)
if (ti != 4)
i = gtk_radio_group_get_selected (group_ops);
text = gtk_entry_get_text (GTK_ENTRY (input_range));
......@@ -328,7 +331,7 @@ tool_dialog_loop:
descriptive_stat_tool(wb, sheet, &range_input, !i, &ds, &dao);
break;
case 3:
case 4:
i = gtk_radio_group_get_selected(sampling_ops);
text = gtk_entry_get_text (GTK_ENTRY (sampling_entry[i]));
size = atoi(text);
......@@ -769,6 +772,95 @@ ttest_dialog_loop:
gnome_dialog_close (GNOME_DIALOG (dialog));
}
static void
dialog_ftest_tool(Workbook *wb, Sheet *sheet)
{
static GtkWidget *dialog, *box;
static GtkWidget *range1_entry, *range2_entry;
static GtkWidget *alpha_entry;
data_analysis_output_t dao;
float_t alpha;
char *text;
int selection;
static Range range_input1, range_input2;
int i=0, size;
if (!dialog) {
dialog = new_dialog("F-Test: Two-Sample for Variances",
wb->toplevel);
box = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
(dialog)->vbox), box);
range1_entry = hbox_pack_label_and_entry
("Variable 1 Range:", "", 20, box);
range2_entry = hbox_pack_label_and_entry
("Variable 2 Range:", "", 20, box);
alpha_entry = hbox_pack_label_and_entry("Alpha:", "0.95",
20, box);
gtk_widget_show_all (dialog);
} else
gtk_widget_show_all (dialog);
gtk_widget_grab_focus (range1_entry);
ttest_dialog_loop:
selection = gnome_dialog_run (GNOME_DIALOG (dialog));
if (selection == 1) {
gnome_dialog_close (GNOME_DIALOG (dialog));
return;
}
text = gtk_entry_get_text (GTK_ENTRY (range1_entry));
if (!parse_range (text, &range_input1.start_col,
&range_input1.start_row,
&range_input1.end_col,
&range_input1.end_row)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell range "
"in 'Variable 1:'"));
gtk_widget_grab_focus (range1_entry);
gtk_entry_set_position(GTK_ENTRY (range1_entry), 0);
gtk_entry_select_region(GTK_ENTRY (range1_entry), 0,
GTK_ENTRY(range1_entry)->text_length);
goto ttest_dialog_loop;
}
text = gtk_entry_get_text (GTK_ENTRY (range2_entry));
if (!parse_range (text, &range_input2.start_col,
&range_input2.start_row,
&range_input2.end_col,
&range_input2.end_row)) {
gnumeric_notice (wb, GNOME_MESSAGE_BOX_ERROR,
_("You should introduce a valid cell range "
"in 'Variable 2:'"));
gtk_widget_grab_focus (range2_entry);
gtk_entry_set_position(GTK_ENTRY (range2_entry), 0);
gtk_entry_select_region(GTK_ENTRY (range2_entry), 0,
GTK_ENTRY(range2_entry)->text_length);
goto ttest_dialog_loop;
}
text = gtk_entry_get_text (GTK_ENTRY (alpha_entry));
alpha = atof(text);
/* TODO: radio buttos for outputs */
dao.type = NewSheetOutput;
ftest_tool (wb, sheet, &range_input1, &range_input2, alpha, &dao);
workbook_focus_sheet(sheet);
gnome_dialog_close (GNOME_DIALOG (dialog));
}
static void
selection_made(GtkWidget *clist, gint row, gint column,
......@@ -826,7 +918,7 @@ dialog_data_analysis (Workbook *wb, Sheet *sheet)
if (selection == 0) {
g_return_if_fail (tools[selected_row].fun != NULL);
if (selected_row >= 4)
if (selected_row >= 5 || selected_row == 3)
tools[selected_row].fun(wb, sheet);
else
tool_dialog_range(wb, sheet, selected_row);
......
......@@ -60,6 +60,10 @@ int sampling_tool (Workbook *wb, Sheet *sheet, Range *input_range,
gboolean periodic_flag, int size,
data_analysis_output_t *dao);
int ftest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
Range *input_range2, float_t alpha,
data_analysis_output_t *dao);
int ttest_paired_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
Range *input_range2, float_t mean_diff, float_t alpha,
data_analysis_output_t *dao);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment