2 * analysis-one-mean-test.c:
5 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
7 * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
25 #include <glib/gi18n-lib.h>
27 #include <tools/analysis-one-mean-test.h>
28 #include <tools/analysis-tools.h>
36 analysis_tool_one_mean_test_engine_run (data_analysis_output_t
*dao
,
37 analysis_tools_data_one_mean_test_t
*info
)
40 GSList
*data
= info
->base
.input
;
41 gboolean first
= TRUE
;
51 fd_count
= gnm_func_lookup_or_add_placeholder ("COUNT");
52 gnm_func_inc_usage (fd_count
);
53 fd_mean
= gnm_func_lookup_or_add_placeholder ("AVERAGE");
54 gnm_func_inc_usage (fd_mean
);
55 fd_var
= gnm_func_lookup_or_add_placeholder ("VAR");
56 gnm_func_inc_usage (fd_var
);
57 fd_sqrt
= gnm_func_lookup_or_add_placeholder ("SQRT");
58 gnm_func_inc_usage (fd_sqrt
);
59 fd_abs
= gnm_func_lookup_or_add_placeholder ("ABS");
60 gnm_func_inc_usage (fd_abs
);
61 fd_tdist
= gnm_func_lookup_or_add_placeholder ("TDIST");
62 gnm_func_inc_usage (fd_tdist
);
63 fd_iferror
= gnm_func_lookup_or_add_placeholder ("IFERROR");
64 gnm_func_inc_usage (fd_iferror
);
66 dao_set_italic (dao
, 0, 0, 0, 9);
67 set_cell_text_col (dao
, 0, 0, _("/Student-t Test"
75 "/P(T\xe2\x89\xa4t) one-tailed"
76 "/P(T\xe2\x89\xa4t) two-tailed"));
78 for (col
= 1; data
!= NULL
; data
= data
->next
, col
++) {
79 GnmValue
*val_org
= value_dup (data
->data
);
81 GnmExpr
const *expr_org
;
82 GnmExpr
const *expr_range_clean
;
83 GnmExpr
const *expr_stddev
;
84 GnmExpr
const *expr_abs
;
86 /* Note that analysis_tools_write_label may modify val_org */
87 dao_set_italic (dao
, col
, 0, col
, 0);
88 analysis_tools_write_label (val_org
, dao
, &info
->base
, col
, 0, col
);
89 expr_org
= gnm_expr_new_constant (val_org
);
90 expr_range_clean
= gnm_expr_new_funcall2
91 (fd_iferror
, gnm_expr_copy (expr_org
), gnm_expr_new_constant (value_new_string("")));
94 dao_set_cell_float (dao
, col
, 3, info
->mean
);
95 dao_set_cell_float (dao
, col
, 7, info
->alpha
);
98 dao_set_cell_expr (dao
, col
, 3, make_cellref (-1,0));
99 dao_set_cell_expr (dao
, col
, 7, make_cellref (-1,0));
102 expr
= gnm_expr_new_funcall1 (fd_count
, expr_org
);
103 dao_set_cell_expr (dao
, col
, 1, expr
);
105 expr
= gnm_expr_new_funcall1 (fd_mean
, gnm_expr_copy (expr_range_clean
));
106 dao_set_cell_array_expr (dao
, col
, 2, expr
);
108 expr
= gnm_expr_new_funcall1 (fd_var
, expr_range_clean
);
109 dao_set_cell_array_expr (dao
, col
, 4, expr
);
111 dao_set_cell_expr (dao
, col
, 6, gnm_expr_new_binary
112 (make_cellref (0,-5), GNM_EXPR_OP_SUB
, gnm_expr_new_constant (value_new_int (1))));
114 expr_stddev
= gnm_expr_new_funcall1
115 (fd_sqrt
, gnm_expr_new_binary (make_cellref (0,-1), GNM_EXPR_OP_DIV
, make_cellref (0,-4)));
116 expr
= gnm_expr_new_binary
117 (gnm_expr_new_binary (make_cellref (0,-3), GNM_EXPR_OP_SUB
, make_cellref (0,-2)),
120 dao_set_cell_array_expr (dao
, col
, 5, expr
);
122 expr_abs
= gnm_expr_new_funcall1 (fd_abs
, make_cellref (0,-3));
123 expr
= gnm_expr_new_funcall3 (fd_tdist
, expr_abs
, make_cellref (0,-2),
124 gnm_expr_new_constant (value_new_int (1)));
125 dao_set_cell_expr (dao
, col
, 8, expr
);
127 expr_abs
= gnm_expr_new_funcall1 (fd_abs
, make_cellref (0,-4));
128 expr
= gnm_expr_new_funcall3 (fd_tdist
, expr_abs
, make_cellref (0,-3),
129 gnm_expr_new_constant (value_new_int (2)));
130 dao_set_cell_expr (dao
, col
, 9, expr
);
132 gnm_func_dec_usage (fd_count
);
133 gnm_func_dec_usage (fd_mean
);
134 gnm_func_dec_usage (fd_var
);
135 gnm_func_dec_usage (fd_abs
);
136 gnm_func_dec_usage (fd_sqrt
);
137 gnm_func_dec_usage (fd_tdist
);
138 gnm_func_dec_usage (fd_iferror
);
140 dao_redraw_respan (dao
);
147 analysis_tool_one_mean_test_engine (G_GNUC_UNUSED GOCmdContext
*gcc
, data_analysis_output_t
*dao
, gpointer specs
,
148 analysis_tool_engine_t selector
, gpointer result
)
150 analysis_tools_data_one_mean_test_t
*info
= specs
;
153 case TOOL_ENGINE_UPDATE_DESCRIPTOR
:
154 return (dao_command_descriptor
155 (dao
, _("Student-t Test (%s)"), result
)
157 case TOOL_ENGINE_UPDATE_DAO
:
158 prepare_input_range (&info
->base
.input
, info
->base
.group_by
);
159 dao_adjust (dao
, 1 + g_slist_length (info
->base
.input
), 10);
161 case TOOL_ENGINE_CLEAN_UP
:
162 return analysis_tool_generic_clean (specs
);
163 case TOOL_ENGINE_LAST_VALIDITY_CHECK
:
165 case TOOL_ENGINE_PREPARE_OUTPUT_RANGE
:
166 dao_prepare_output (NULL
, dao
, _("Student-t Test"));
168 case TOOL_ENGINE_FORMAT_OUTPUT_RANGE
:
169 return dao_format_output (dao
, _("Student-t Test"));
170 case TOOL_ENGINE_PERFORM_CALC
:
172 return analysis_tool_one_mean_test_engine_run (dao
, specs
);