2 * analysis-normality.c:
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses/>.
25 #include <gnumeric-config.h>
26 #include <glib/gi18n-lib.h>
28 #include <tools/analysis-normality.h>
29 #include <tools/analysis-tools.h>
35 #include <sheet-object-graph.h>
37 #include <goffice/goffice.h>
42 analysis_tool_normality_engine_run (data_analysis_output_t
*dao
,
43 analysis_tools_data_normality_t
*info
)
46 GSList
*data
= info
->base
.input
;
52 char const *n_comment
;
54 GogGraph
*graph
= NULL
;
59 case normality_test_type_andersondarling
:
61 testname
= N_("Anderson-Darling Test");
62 n_comment
= N_("For the Anderson-Darling Test\n"
63 "the sample size must be at\n"
66 case normality_test_type_cramervonmises
:
68 testname
= N_("Cram\xc3\xa9r-von Mises Test");
69 n_comment
= N_("For the Cram\xc3\xa9r-von Mises Test\n"
70 "the sample size must be at\n"
73 case normality_test_type_lilliefors
:
75 testname
= N_("Lilliefors (Kolmogorov-Smirnov) Test");
76 n_comment
= N_("For the Lilliefors (Kolmogorov-Smirnov) Test\n"
77 "the sample size must be at least 5.");
79 case normality_test_type_shapirofrancia
:
81 testname
= N_("Shapiro-Francia Test");
82 n_comment
= N_("For the Shapiro-Francia Test\n"
83 "the sample size must be at\n"
84 "least 5 and at most 5000.");
87 g_assert_not_reached();
90 fd
= gnm_func_lookup_or_add_placeholder (fdname
);
91 gnm_func_inc_usage (fd
);
92 fd_if
= gnm_func_lookup_or_add_placeholder ("IF");
93 gnm_func_inc_usage (fd_if
);
95 dao_set_italic (dao
, 0, 0, 0, 5);
96 dao_set_cell (dao
, 0, 0, _(testname
));
102 graph
= g_object_new (GOG_TYPE_GRAPH
, NULL
);
103 chart
= GOG_CHART (gog_object_add_by_name (
104 GOG_OBJECT (graph
), "Chart", NULL
));
106 plot
= gog_plot_new_by_name ("GogProbabilityPlot");
107 go_object_set_property (G_OBJECT (plot
), "distribution",
108 "Distribution", "GODistNormal",
111 gog_object_add_by_name (GOG_OBJECT (chart
),
112 "Plot", GOG_OBJECT (plot
));
117 * Note to translators: in the following string and others like it,
118 * the "/" is a separator character that can be changed to anything
119 * if the translation needs the slash; just use, say, "|" instead.
121 * The items are bundled like this to increase translation context.
123 set_cell_text_col (dao
, 0, 1, _("/Alpha"
129 dao_set_cell_comment (dao
, 0, 4, _(n_comment
));
131 for (col
= 1; data
!= NULL
; data
= data
->next
, col
++) {
132 GnmValue
*val_org
= value_dup (data
->data
);
134 /* Note that analysis_tools_write_label may modify val_org */
135 dao_set_italic (dao
, col
, 0, col
, 0);
136 analysis_tools_write_label (val_org
, dao
, &info
->base
,
141 series
= gog_plot_new_series (plot
);
142 gog_series_set_dim (series
, 0,
143 gnm_go_data_vector_new_expr
144 (val_org
->v_range
.cell
.a
.sheet
,
145 gnm_expr_top_new (gnm_expr_new_constant (value_dup (val_org
)))),
150 dao_set_cell_float (dao
, col
, 1, info
->alpha
);
152 dao_set_cell_expr (dao
, col
, 1,
153 make_cellref (1 - col
, 0));
155 dao_set_array_expr (dao
, col
, 2, 1, 3,
156 gnm_expr_new_funcall1 (fd
, gnm_expr_new_constant (val_org
)));
157 dao_set_cell_expr (dao
, col
, 5,
158 gnm_expr_new_funcall3
159 (fd_if
, gnm_expr_new_binary
160 (make_cellref (0, -4),
162 make_cellref (0, -3)),
163 gnm_expr_new_constant (value_new_string (_("Not normal"))),
164 gnm_expr_new_constant (value_new_string (_("Possibly normal")))));
168 so
= sheet_object_graph_new (graph
);
169 g_object_unref (graph
);
171 dao_set_sheet_object (dao
, 0, 1, so
);
175 gnm_func_dec_usage (fd
);
176 gnm_func_dec_usage (fd_if
);
178 dao_redraw_respan (dao
);
183 analysis_tool_normality_engine (G_GNUC_UNUSED GOCmdContext
*gcc
, data_analysis_output_t
*dao
, gpointer specs
,
184 analysis_tool_engine_t selector
, gpointer result
)
186 analysis_tools_data_normality_t
*info
= specs
;
189 case TOOL_ENGINE_UPDATE_DESCRIPTOR
:
190 return (dao_command_descriptor (dao
, _("Normality Test (%s)"), result
)
192 case TOOL_ENGINE_UPDATE_DAO
:
193 prepare_input_range (&info
->base
.input
, info
->base
.group_by
);
194 dao_adjust (dao
, 1 + g_slist_length (info
->base
.input
), 6);
196 case TOOL_ENGINE_CLEAN_UP
:
197 return analysis_tool_generic_clean (specs
);
198 case TOOL_ENGINE_LAST_VALIDITY_CHECK
:
200 case TOOL_ENGINE_PREPARE_OUTPUT_RANGE
:
201 dao_prepare_output (NULL
, dao
, _("Normality Test"));
203 case TOOL_ENGINE_FORMAT_OUTPUT_RANGE
:
204 return dao_format_output (dao
, _("Normality Test"));
205 case TOOL_ENGINE_PERFORM_CALC
:
207 return analysis_tool_normality_engine_run (dao
, specs
);
209 return TRUE
; /* We shouldn't get here */