1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include "debug-print.h"
40 +format=lab:!labels/nolabels/nocatlabs,
44 +missing=miss:!table/include/dependent;
45 +cells[cl_]=default,count,sum,mean,stddev,variance,all;
46 +statistics[st_]=anova,linearity,all,none.
52 static void debug_print (struct cmd_means *cmd);
55 /* TABLES: Variable lists for each dimension. */
56 int n_dim; /* Number of dimensions. */
57 int *nv_dim; /* Number of variables in each dimension. */
58 struct variable ***v_dim; /* Variables in each dimension. */
60 /* VARIABLES: List of variables. */
62 struct variable **v_var;
64 /* Parses and executes the T-TEST procedure. */
69 int success = CMD_FAILURE;
76 lex_match_id ("MEANS");
77 if (!parse_means (&cmd))
83 for (i = 0; i < MNS_CL_count; i++)
86 if (i >= MNS_CL_count)
87 cmd.a_cells[MNS_CL_ALL] = 1;
90 cmd.a_cells[MNS_CL_DEFAULT] = 1;
91 if (cmd.a_cells[MNS_CL_DEFAULT] || cmd.a_cells[MNS_CL_ALL])
92 cmd.a_cells[MNS_CL_MEAN] = cmd.a_cells[MNS_CL_STDDEV] = cmd.a_cells[MNS_CL_COUNT] = 1;
93 if (cmd.a_cells[MNS_CL_ALL])
94 cmd.a_cells[MNS_CL_SUM] = cmd.a_cells[MNS_CL_VARIANCE] = 1;
96 if (cmd.sbc_statistics)
98 if (!cmd.a_statistics[MNS_ST_ANOVA] && !cmd.a_statistics[MNS_ST_LINEARITY])
99 cmd.a_statistics[MNS_ST_ANOVA] = 1;
100 if (cmd.a_statistics[MNS_ST_ALL])
101 cmd.a_statistics[MNS_ST_ANOVA] = cmd.a_statistics[MNS_ST_LINEARITY] = 1;
106 msg (SE, _("Missing required subcommand TABLES."));
114 success = CMD_SUCCESS;
120 for (i = 0; i < n_dim; i++)
130 /* Returns nonzero only if value V is valid as an endpoint for a
131 dependent variable in integer mode. */
133 validate_dependent_endpoint (double V)
135 return V == (int) V && V != LOWEST && V != HIGHEST;
138 /* Parses the TABLES subcommand. */
140 mns_custom_tables (struct cmd_means *cmd)
142 struct dictionary *dict;
143 struct dictionary temp_dict;
145 if (!lex_match_id ("TABLES")
146 && (token != T_ID || !is_varname (tokid))
151 if (cmd->sbc_tables || cmd->sbc_crossbreak)
153 msg (SE, _("TABLES or CROSSBREAK subcommand may not appear more "
158 if (cmd->sbc_variables)
161 temp_dict.var = v_var;
162 temp_dict.nvar = n_var;
167 temp_dict.name_tab = hsh_create (8, compare_variables, hash_variable,
169 for (i = 0; i < temp_dict.nvar; i++)
170 hsh_force_insert (temp_dict.name_tab, temp_dict.var[i]);
174 dict = &default_dict;
179 struct variable **vl;
181 if (!parse_variables (dict, &vl, &nvl, PV_NO_DUPLICATE | PV_NO_SCRATCH))
185 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
186 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
188 nv_dim[n_dim - 1] = nvl;
189 v_dim[n_dim - 1] = vl;
191 if (cmd->sbc_variables)
195 for (i = 0; i < nv_dim[0]; i++)
197 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
199 if (v_inf->min == SYSMIS)
201 msg (SE, _("Variable %s specified on TABLES or "
202 "CROSSBREAK, but not specified on "
210 v_inf->min = (int) v_inf->min;
211 v_inf->max = (int) v_inf->max;
213 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
215 msg (SE, _("LOWEST and HIGHEST may not be used "
216 "for independent variables (%s)."),
220 if (v_inf->min != (int) v_inf->min
221 || v_inf->max != (int) v_inf->max)
223 msg (SE, _("Independent variables (%s) may not "
224 "have noninteger endpoints in their "
233 while (lex_match (T_BY));
235 /* Check for duplicates. */
239 for (i = 0; i < default_dict.nvar; i++)
240 default_dict.var[i]->foo = 0;
241 for (i = 0; i < dict->nvar; i++)
242 if (dict->var[i]->foo++)
244 msg (SE, _("Variable %s is multiply specified on TABLES "
251 if (cmd->sbc_variables)
252 hsh_destroy (temp_dict.name_tab);
257 /* Parse CROSSBREAK subcommand. */
259 mns_custom_crossbreak (struct cmd_means *cmd)
261 return mns_custom_tables (cmd);
264 /* Parses the VARIABLES subcommand. */
266 mns_custom_variables (struct cmd_means *cmd)
270 msg (SE, _("VARIABLES must precede TABLES."));
274 if (cmd->sbc_variables == 1)
278 for (i = 0; i < default_dict.nvar; i++)
279 default_dict.var[i]->p.mns.min = SYSMIS;
288 if (!parse_variables (&default_dict, &v_var, &n_var,
289 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
292 if (!lex_force_match ('('))
297 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
301 if (!lex_force_num ())
311 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
315 if (!lex_force_num ())
321 if (!lex_force_match (')'))
327 msg (SE, _("Upper value (%g) is less than lower value "
328 "(%g) on VARIABLES subcommand."), max, min);
335 for (i = orig_n; i < n_var; i++)
337 struct means_proc *v_inf = &v_var[i]->p.mns;
344 while (token != '/' && token != '.');
351 debug_print (struct cmd_means *cmd)
357 if (cmd->sbc_variables)
361 printf (" VARIABLES=");
362 for (i = 0; i < default_dict.nvar; i++)
364 struct variable *v = default_dict.var[i];
366 if (v->p.mns.min == SYSMIS)
370 printf ("%s(", v->name);
371 if (v->p.mns.min == LOWEST)
374 printf ("%g", v->p.mns.min);
376 if (v->p.mns.max == HIGHEST)
379 printf ("%g", v->p.mns.max);
386 for (i = 0; i < n_dim; i++)
393 for (j = 0; j < nv_dim[i]; j++)
397 printf (v_dim[i][j]->name);
402 #endif /* DEBUGGING */