Commit 7dc4e081 authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Implemented COUPNUM().

2000-07-03  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/functions/fn-financial.c: Implemented COUPNUM().

	* src/analysis-tools.c: Started the implementation of the third
	anova tool (two-factor with replication).

	* src/dialogs/analysis-tools.glade: Added dialog for the new
	tool.  Fixed the `Correlation' dialog.

	* src/dialogs/dialog-analysis-tools.c: Added
	dialog_anova_two_factor_without_r_tool().

	* src/dialogs/tools.h: Related changes.

	* TODO: Added `Data analysis tools' section.
parent ada6538e
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
......@@ -5,8 +5,10 @@ Jody:
* Deadkey support.
Jukka:
* Implemented TRUE and FALSE logical functions and started
COUPDAYS.
* Started the implementation of `Anova: Two-Factor With Replication'
data analysis tool
* Implemented COUPNUM and started COUPDAYS.
* Implemented TRUE and FALSE logical functions.
Morten:
* Cleanup analysis tool code.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
2000-07-03 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/functions/fn-financial.c: Implemented COUPNUM().
* src/analysis-tools.c: Started the implementation of the third
anova tool (two-factor with replication).
* src/dialogs/analysis-tools.glade: Added dialog for the new
tool. Fixed the `Correlation' dialog.
* src/dialogs/dialog-analysis-tools.c: Added
dialog_anova_two_factor_without_r_tool().
* src/dialogs/tools.h: Related changes.
* TODO: Added `Data analysis tools' section.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* src/parser.y (exp) : Add production for sheet specific names.
......
......@@ -29,13 +29,22 @@ Gnumeric Spread Sheet task list
* Implement Even More Functions
* AREAS and GETPIVOTDATA
* AMORDEGRC, AMORLINC, COUPDAYBS, COUPDAYSNC, COUPNCD, COUPNUM,
COUPPCD, CUMIPMT, CUMPRINC, MDURATION, ODDFPRICE, ODDFYIELD,
ODDLPRICE, ODDLYIELD, PRICE, VDB, YIELD, YIELDDISC, and YIELDMAT.
* AMORDEGRC, AMORLINC, COUPDAYBS, COUPDAYSNC, COUPNCD, COUPPCD,
CUMIPMT, CUMPRINC, MDURATION, ODDFPRICE, ODDFYIELD, ODDLPRICE,
ODDLYIELD, PRICE, VDB, YIELD, YIELDDISC, and YIELDMAT.
* Fix the Following Functions
* CELL, COUPDAYS, and DURATION
* Data Analysis Tools
* Finish `Anova: Two-Factor With Replication'
* Implement `Patterned distribution' for `Random Number Generation'
* Implement new tools:
- `Exponential Smoothing'
- `Fourier Analysis'
- `Histogram'
* Finish the documentation
* Printing
* Preview
* Stroke support for zoom etc.
......
......@@ -51,6 +51,26 @@
</sect2>
<sect2>
<title>Anova: Two-Factor With Replication Tool</title>
<para>For this tool, the given input range should contain at least
two columns of numeric data and the labels of the columns and the
labels of the groups. The labels of the columns are given as the
usual way; if you give an input range A1:D10, for example, the
labels of the columns should be placed in B1, C1, and D1. The
labels of the groups should be placed into the first column, each
one of them at the first row of the group. For example, if we have
three groups in our A1:D10 range (rows per sample is set to three),
the group names should be placed at A2, A5, and A8.</para>
</sect2>
<sect2>
<title>Anova: Two-Factor Without Replication Tool</title>
</sect2>
<sect2>
<title>Correlation Tool</title>
......@@ -185,6 +205,10 @@
Type I error of one-tailed test.</para>
</sect2>
<sect2>
<title>Moving Average Tool</title>
</sect2>
<sect2>
<title>Random Number Generation Tool</title>
......@@ -236,6 +260,15 @@
</sect3>
</sect2>
<sect2>
<title>Rank and Percentile Tool</title>
</sect2>
<sect2>
<title>Regression Tool</title>
</sect2>
<sect2>
<title>Sampling Tool</title>
......@@ -257,6 +290,20 @@
the original data set is taken at most once to the sample.</para>
</sect2>
<sect2>
<title>t-Test: Paired Two Sample for Means Tool</title>
</sect2>
<sect2>
<title>t-Test: Two-Sample Assuming Equal Variances Tool</title>
</sect2>
<sect2>
<title>t-Test: Two-Sample Assuming Unequal Variances Tool</title>
</sect2>
<sect2>
<title>z-Test:Two Samples for Means Tool</title>
......
......@@ -216,6 +216,41 @@ coupdays(GDate *settlement, GDate *maturity, int freq, int basis)
}
}
static int
coupnum(GDate *settlement, GDate *maturity, int freq, int basis)
{
int years, months, days;
GDateYear sy;
GDateMonth sm;
GDateDay sd;
sy = g_date_year (settlement);
sm = g_date_month (settlement);
sd = g_date_day (settlement);
years = g_date_year (maturity) - sy;
months = g_date_month (maturity) - sm;
days = g_date_day (maturity) - sd
+ (g_date_is_leap_year (sy) && sd==28 && sm==2);
if (freq == 1)
return years + (months > 0 || days > 0);
else if (freq == 2)
return years*2
+ (months > 6) + (months == 6 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -6);
else
return years*4
+ (months > 9) + (months == 9 && days > 0)
+ (months > 6) + (months == 6 && days > 0)
+ (months > 3) + (months == 3 && days > 0)
+ (months > 0) + (months == 0 && days > 0)
- (months <= -3)
- (months <= -6)
- (months <= -9);
}
/***************************************************************************/
......@@ -2258,7 +2293,10 @@ gnumeric_coupdays (FunctionEvalInfo *ei, Value **argv)
settlement = datetime_value_to_g(argv[0]);
maturity = datetime_value_to_g(argv[1]);
freq = value_get_as_int (argv[2]);
basis = value_get_as_int (argv[3]);
if (argv[3] != NULL)
basis = value_get_as_int (argv[3]);
else
basis = 0;
if (settlement == NULL || maturity == NULL)
return value_new_error (ei->pos, gnumeric_err_VALUE);
......@@ -2346,7 +2384,29 @@ static char *help_coupnum = {
static Value *
gnumeric_coupnum (FunctionEvalInfo *ei, Value **argv)
{
return value_new_error (ei->pos, "#UNIMPLEMENTED!");
GDate *settlement;
GDate *maturity;
int freq, basis;
float_t n;
settlement = datetime_value_to_g(argv[0]);
maturity = datetime_value_to_g(argv[1]);
freq = value_get_as_int (argv[2]);
if (argv[3] != NULL)
basis = value_get_as_int (argv[3]);
else
basis = 0;
if (settlement == NULL || maturity == NULL)
return value_new_error (ei->pos, gnumeric_err_VALUE);
if (basis < 0 || basis > 4 || (freq != 1 && freq != 2 && freq != 4)
|| g_date_compare(settlement, maturity) > 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
n = coupnum (settlement, maturity, freq, basis);
return value_new_float (n);
}
/***************************************************************************/
......
......@@ -2611,3 +2611,157 @@ int anova_two_factor_without_r_tool (Workbook *wb, Sheet *sheet, Range *range,
return 0;
}
/************* Anova: Two-Factor With Replication 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.
*
**/
int anova_two_factor_with_r_tool (Workbook *wb, Sheet *sheet, Range *range,
int rows_per_sample, float_t alpha,
data_analysis_output_t *dao)
{
int cols, rows, i, j, k, n;
int count, gr_count;
float_t sum, sqrsum, x, v;
float_t gr_sum, gr_sqrsum;
int *col_count;
float_t *col_sum, *col_sqrsum;
Cell *cell;
cols = range->end.col - range->start.col + 1;
rows = range->end.row - range->start.row + 1;
/* Check that correct number of rows per sample */
if ((rows-1) % rows_per_sample != 0)
return 1;
/* Check that at least two columns of data are given */
if (cols < 3)
return 3;
/* Check that the data contains numbers only */
for (i=1; i<rows; i++) {
for (j=1; j<cols; j++) {
cell = sheet_cell_get (sheet, range->start.col + j,
range->start.row + i);
if (cell == NULL
|| !VALUE_IS_NUMBER(cell->value))
return 2;
}
}
prepare_output (wb, dao, _("Anova"));
set_cell (dao, 0, 0, _("Anova: Two-Factor With Replication"));
set_cell (dao, 0, 2, _("SUMMARY"));
col_count = g_new (int, cols);
col_sum = g_new (float_t, cols);
col_sqrsum = g_new (float_t, cols);
for (i=1; i<cols; i++) {
cell = sheet_cell_get (sheet, range->start.col+i,
range->start.row);
if (cell->value != NULL)
set_cell_value (dao, i, 2, cell->value);
col_count[i-1] = 0;
col_sum[i-1] = 0;
col_sqrsum[i-1] = 0;
}
set_italic (dao, 1, 2, i-1, 2);
set_cell (dao, i, 2, _("Total"));
for (i=n=0; i<rows-1; i+=rows_per_sample) {
cell = sheet_cell_get (sheet, range->start.col,
range->start.row+i+1);
/* Print the names of the groups */
if (cell != NULL)
set_cell_value (dao, 0, n*6+3, cell->value);
set_italic (dao, 0, n*6+3, 0, n*6+3);
set_cell (dao, 0, n*6+4, "Count");
set_cell (dao, 0, n*6+5, "Sum");
set_cell (dao, 0, n*6+6, "Average");
set_cell (dao, 0, n*6+7, "Variance");
gr_count = 0;
gr_sum = 0;
gr_sqrsum = 0;
for (j=1; j<cols; j++) {
count = 0;
sum = 0;
sqrsum = 0;
for (k=0; k<rows_per_sample; k++) {
cell = sheet_cell_get (sheet, range->start.col+j,
range->start.row + k + 1 +
n*rows_per_sample);
++count;
x = value_get_as_float (cell->value);
sum += x;
sqrsum += x * x;
col_count[j-1]++;
col_sum[j-1] += x;
col_sqrsum[j-1] += x * x;
}
v = (sqrsum - (sum * sum) / count) / (count - 1);
gr_count += count;
gr_sum += sum;
gr_sqrsum += sqrsum;
set_cell_int (dao, j, n*6+4, count);
set_cell_float (dao, j, n*6+5, sum);
set_cell_float (dao, j, n*6+6, sum / count);
set_cell_float (dao, j, n*6+7, v);
}
v = (gr_sqrsum - (gr_sum * gr_sum) / gr_count) / (gr_count - 1);
set_cell_int (dao, j, n*6+4, gr_count);
set_cell_float (dao, j, n*6+5, gr_sum);
set_cell_float (dao, j, n*6+6, gr_sum / gr_count);
set_cell_float (dao, j, n*6+7, v);
++n;
}
set_cell (dao, 0, n*6+3, _("Total"));
set_italic (dao, 0, n*6+3, 0, n*6+3);
set_cell (dao, 0, n*6+4, _("Count"));
set_cell (dao, 0, n*6+5, _("Sum"));
set_cell (dao, 0, n*6+6, _("Average"));
set_cell (dao, 0, n*6+7, _("Variance"));
for (i=1; i<cols; i++) {
v = (col_sqrsum[i-1] - (col_sum[i-1] * col_sum[i-1]) /
col_count[i-1]) / (col_count[i-1] - 1);
set_cell_int (dao, i, n*6+4, col_count[i-1]);
set_cell_float (dao, i, n*6+5, col_sum[i-1]);
set_cell_float (dao, i, n*6+6, col_sum[i-1] / col_count[i-1]);
set_cell_float (dao, i, n*6+7, v);
}
set_cell (dao, 0, n*6+10, _("ANOVA"));
set_cell (dao, 0, n*6+11, _("Source of Variation"));
set_cell (dao, 0, n*6+12, _("Sample"));
set_cell (dao, 0, n*6+13, _("Columns"));
set_cell (dao, 0, n*6+14, _("Interaction"));
set_cell (dao, 0, n*6+15, _("Within"));
set_cell (dao, 0, n*6+17, _("Total"));
set_cell (dao, 1, n*6+11, _("SS"));
set_cell (dao, 2, n*6+11, _("df"));
set_cell (dao, 3, n*6+11, _("MS"));
set_cell (dao, 4, n*6+11, _("F"));
set_cell (dao, 5, n*6+11, _("P-value"));
set_cell (dao, 6, n*6+11, _("F crit"));
set_italic (dao, 0, n*6+11, 6, n*6+11);
/* FIXME: Implement the rest of the ANOVA computations. */
return 0;
}
......@@ -2662,6 +2662,379 @@
</widget>
</widget>
<widget>
<class>GnomeDialog</class>
<name>Anova3</name>
<visible>False</visible>
<title>Anova: Two-Factor With Replication</title>
<type>GTK_WINDOW_TOPLEVEL</type>
<position>GTK_WIN_POS_NONE</position>
<modal>False</modal>
<allow_shrink>False</allow_shrink>
<allow_grow>False</allow_grow>
<auto_shrink>False</auto_shrink>
<auto_close>False</auto_close>
<hide_on_close>False</hide_on_close>
<widget>
<class>GtkVBox</class>
<child_name>GnomeDialog:vbox</child_name>
<name>dialog-vbox2</name>
<homogeneous>False</homogeneous>
<spacing>8</spacing>
<child>
<padding>4</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkVBox</class>
<name>vbox2</name>
<homogeneous>False</homogeneous>
<spacing>0</spacing>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkFrame</class>
<name>frame1</name>
<label>Input</label>
<label_xalign>0</label_xalign>
<shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
<child>
<padding>0</padding>
<expand>True</expand>
<fill>True</fill>
</child>
<widget>
<class>GtkTable</class>
<name>table1</name>
<border_width>4</border_width>
<rows>4</rows>
<columns>2</columns>
<homogeneous>False</homogeneous>
<row_spacing>0</row_spacing>
<column_spacing>4</column_spacing>
<widget>
<class>GtkEntry</class>
<name>anova3_entry1</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>anova3_entry2</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkEntry</class>
<name>anova3_entry3</name>
<can_focus>True</can_focus>
<editable>True</editable>
<text_visible>True</text_visible>
<text_max_length>0</text_max_length>
<text></text>
<child>
<left_attach>1</left_attach>
<right_attach>2</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>True</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label4</name>
<label>_Alpha:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<default_focus_target>anova3_entry3</default_focus_target>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>2</top_attach>
<bottom_attach>3</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label3</name>
<label>_Rows per sample:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<default_focus_target>anova3_entry2</default_focus_target>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>1</top_attach>
<bottom_attach>2</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>
<widget>
<class>GtkLabel</class>
<name>label2</name>
<label>_Input Range:</label>
<justify>GTK_JUSTIFY_CENTER</justify>
<wrap>False</wrap>
<xalign>1</xalign>
<yalign>0.5</yalign>
<xpad>0</xpad>
<ypad>0</ypad>
<default_focus_target>anova3_entry1</default_focus_target>
<child>
<left_attach>0</left_attach>
<right_attach>1</right_attach>
<top_attach>0</top_attach>
<bottom_attach>1</bottom_attach>
<xpad>0</xpad>
<ypad>0</ypad>
<xexpand>False</xexpand>
<yexpand>False</yexpand>
<xshrink>False</xshrink>
<yshrink>False</yshrink>
<xfill>True</xfill>
<yfill>False</yfill>
</child>
</widget>