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.var_by_name = avl_create (NULL, cmp_variable, NULL);
168 for (i = 0; i < temp_dict.nvar; i++)
169 avl_force_insert (temp_dict.var_by_name, temp_dict.var[i]);
173 dict = &default_dict;
178 struct variable **vl;
180 if (!parse_variables (dict, &vl, &nvl, PV_NO_DUPLICATE | PV_NO_SCRATCH))
184 nv_dim = xrealloc (nv_dim, n_dim * sizeof (int));
185 v_dim = xrealloc (v_dim, n_dim * sizeof (struct variable **));
187 nv_dim[n_dim - 1] = nvl;
188 v_dim[n_dim - 1] = vl;
190 if (cmd->sbc_variables)
194 for (i = 0; i < nv_dim[0]; i++)
196 struct means_proc *v_inf = &v_dim[0][i]->p.mns;
198 if (v_inf->min == SYSMIS)
200 msg (SE, _("Variable %s specified on TABLES or "
201 "CROSSBREAK, but not specified on "
209 v_inf->min = (int) v_inf->min;
210 v_inf->max = (int) v_inf->max;
212 if (v_inf->min == LOWEST || v_inf->max == HIGHEST)
214 msg (SE, _("LOWEST and HIGHEST may not be used "
215 "for independent variables (%s)."),
219 if (v_inf->min != (int) v_inf->min
220 || v_inf->max != (int) v_inf->max)
222 msg (SE, _("Independent variables (%s) may not "
223 "have noninteger endpoints in their "
232 while (lex_match (T_BY));
234 /* Check for duplicates. */
238 for (i = 0; i < default_dict.nvar; i++)
239 default_dict.var[i]->foo = 0;
240 for (i = 0; i < dict->nvar; i++)
241 if (dict->var[i]->foo++)
243 msg (SE, _("Variable %s is multiply specified on TABLES "
250 if (cmd->sbc_variables)
251 avl_destroy (temp_dict.var_by_name, NULL);
256 /* Parse CROSSBREAK subcommand. */
258 mns_custom_crossbreak (struct cmd_means *cmd)
260 return mns_custom_tables (cmd);
263 /* Parses the VARIABLES subcommand. */
265 mns_custom_variables (struct cmd_means *cmd)
269 msg (SE, _("VARIABLES must precede TABLES."));
273 if (cmd->sbc_variables == 1)
277 for (i = 0; i < default_dict.nvar; i++)
278 default_dict.var[i]->p.mns.min = SYSMIS;
287 if (!parse_variables (&default_dict, &v_var, &n_var,
288 PV_APPEND | PV_NO_DUPLICATE | PV_NO_SCRATCH))
291 if (!lex_force_match ('('))
296 && (!strcmp (tokid, "LO") || lex_id_match ("LOWEST", tokid)))
300 if (!lex_force_num ())
310 && (!strcmp (tokid, "HI") || lex_id_match ("HIGHEST", tokid)))
314 if (!lex_force_num ())
320 if (!lex_force_match (')'))
326 msg (SE, _("Upper value (%g) is less than lower value "
327 "(%g) on VARIABLES subcommand."), max, min);
334 for (i = orig_n; i < n_var; i++)
336 struct means_proc *v_inf = &v_var[i]->p.mns;
343 while (token != '/' && token != '.');
350 debug_print (struct cmd_means *cmd)
356 if (cmd->sbc_variables)
360 printf (" VARIABLES=");
361 for (i = 0; i < default_dict.nvar; i++)
363 struct variable *v = default_dict.var[i];
365 if (v->p.mns.min == SYSMIS)
369 printf ("%s(", v->name);
370 if (v->p.mns.min == LOWEST)
373 printf ("%g", v->p.mns.min);
375 if (v->p.mns.max == HIGHEST)
378 printf ("%g", v->p.mns.max);
385 for (i = 0; i < n_dim; i++)
392 for (j = 0; j < nv_dim[i]; j++)
396 printf (v_dim[i][j]->name);
401 #endif /* DEBUGGING */