/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-2000, 2009-2013 Free Software Foundation, Inc.
+ Copyright (C) 1997-2000, 2009-2014 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include <config.h>
+#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
size_t var_cnt; /* Number of variables. */
enum dsc_missing_type missing_type; /* Treatment of missing values. */
enum mv_class exclude; /* Classes of missing values to exclude. */
+ struct variable *filter; /* Dictionary FILTER BY variable. */
struct casereader *z_reader; /* Reader for count, mean, stddev. */
casenumber count; /* Number left in this SPLIT FILE group.*/
bool ok;
else if (lex_match_id (lexer, "DEFAULT"))
dsc->show_stats |= DEFAULT_STATS;
else
- dsc->show_stats |= 1ul << (match_statistic (lexer));
+ {
+ enum dsc_statistic s = match_statistic (lexer);
+ if (s == DSC_NONE )
+ {
+ lex_error (lexer, NULL);
+ goto error;
+ }
+ dsc->show_stats |= 1ul << s;
+ }
lex_match (lexer, T_COMMA);
}
if (dsc->show_stats == 0)
dsc->sort_ascending = 0;
else
lex_error (lexer, NULL);
- lex_force_match (lexer, T_RPAREN);
+ if (! lex_force_match (lexer, T_RPAREN))
+ goto error;
}
}
else if (var_cnt == 0)
dsc->vars[i].moments = moments_create (dsc->max_moment);
/* Data pass. */
- grouper = casegrouper_create_splits (proc_open_filtering (ds, z_cnt == 0),
- dict);
+ grouper = casegrouper_create_splits (proc_open_filtering (ds, false), dict);
while (casegrouper_get_next_group (grouper, &group))
calc_descriptives (dsc, group, ds);
ok = casegrouper_destroy (grouper);
tab_submit (t);
}
+static void
+descriptives_set_all_sysmis_zscores (const struct dsc_trns *t, struct ccase *c)
+{
+ const struct dsc_z_score *z;
+
+ for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++)
+ case_data_rw (c, z->z_var)->f = SYSMIS;
+}
+
/* Transformation function to calculate Z-scores. Will return SYSMIS if any of
the following are true: 1) mean or standard deviation is SYSMIS 2) score is
SYSMIS 3) score is user missing and they were not included in the original
struct dsc_trns *t = trns_;
struct dsc_z_score *z;
const struct variable **vars;
- int all_sysmis = 0;
+
+ *c = case_unshare (*c);
+
+ if (t->filter)
+ {
+ double f = case_num (*c, t->filter);
+ if (f == 0.0 || var_is_num_missing (t->filter, f, MV_ANY))
+ {
+ descriptives_set_all_sysmis_zscores (t, *c);
+ return TRNS_CONTINUE;
+ }
+ }
if (t->count <= 0)
{
msg (SE, _("Internal error processing Z scores"));
t->ok = false;
}
- for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++)
- z->mean = z->std_dev = SYSMIS;
+ descriptives_set_all_sysmis_zscores (t, *c);
+ return TRNS_CONTINUE;
}
}
t->count--;
double score = case_num (*c, *vars);
if (var_is_num_missing (*vars, score, t->exclude))
{
- all_sysmis = 1;
- break;
+ descriptives_set_all_sysmis_zscores (t, *c);
+ return TRNS_CONTINUE;
}
}
}
- *c = case_unshare (*c);
for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++)
{
double input = case_num (*c, z->src_var);
double *output = &case_data_rw (*c, z->z_var)->f;
- if (z->mean == SYSMIS || z->std_dev == SYSMIS || all_sysmis
+ if (z->mean == SYSMIS || z->std_dev == SYSMIS
|| var_is_num_missing (z->src_var, input, t->exclude))
*output = SYSMIS;
else
t->var_cnt = 0;
t->vars = NULL;
}
+ t->filter = dict_get_filter (dataset_dict (ds));
t->z_reader = casewriter_make_reader (dsc->z_writer);
t->count = 0;
t->ok = true;
dst_var = dict_create_var_assert (dataset_dict (ds), dv->z_name, 0);
label = xasprintf (_("Z-score of %s"),var_to_string (dv->v));
- var_set_label (dst_var, label, false);
+ var_set_label (dst_var, label);
free (label);
z = &t->z_scores[cnt++];
calc_descriptives (struct dsc_proc *dsc, struct casereader *group,
struct dataset *ds)
{
+ struct variable *filter = dict_get_filter (dataset_dict (ds));
struct casereader *pass1, *pass2;
casenumber count;
struct ccase *c;
{
double weight = dict_get_case_weight (dataset_dict (ds), c, NULL);
+ if (filter)
+ {
+ double f = case_num (c, filter);
+ if (f == 0.0 || var_is_num_missing (filter, f, MV_ANY))
+ continue;
+ }
+
/* Check for missing values. */
if (listwise_missing (dsc, c))
{
{
double weight = dict_get_case_weight (dataset_dict (ds), c, NULL);
+ if (filter)
+ {
+ double f = case_num (c, filter);
+ if (f == 0.0 || var_is_num_missing (filter, f, MV_ANY))
+ continue;
+ }
+
/* Check for missing values. */
if (dsc->missing_type == DSC_LISTWISE && listwise_missing (dsc, c))
continue;
}
/* Calculate results. */
- if (dsc->z_writer)
+ if (dsc->z_writer && count > 0)
{
c = case_create (casewriter_get_proto (dsc->z_writer));
z_idx = 0;
if (dsc->calc_stats & (1ul << DSC_SUM))
dv->stats[DSC_SUM] = W * dv->stats[DSC_MEAN];
- if (dv->z_name)
+ if (dv->z_name && c != NULL)
{
case_data_rw_idx (c, z_idx++)->f = dv->stats[DSC_MEAN];
case_data_rw_idx (c, z_idx++)->f = dv->stats[DSC_STDDEV];
nc = 0;
tab_text (t, nc++, i + 1, TAB_LEFT, var_to_string (dv->v));
- tab_text_format (t, nc++, i + 1, 0, "%g", dv->valid);
+ tab_text_format (t, nc++, i + 1, 0, "%.*g", DBL_DIG + 1, dv->valid);
if (dsc->format == DSC_SERIAL)
- tab_text_format (t, nc++, i + 1, 0, "%g", dv->missing);
+ tab_text_format (t, nc++, i + 1, 0, "%.*g", DBL_DIG + 1, dv->missing);
for (j = 0; j < DSC_N_STATS; j++)
if (dsc->show_stats & (1ul << j))
- tab_double (t, nc++, i + 1, TAB_NONE, dv->stats[j], NULL);
+ tab_double (t, nc++, i + 1, TAB_NONE, dv->stats[j], NULL, RC_OTHER);
}
- tab_title (t, _("Valid cases = %g; cases with missing value(s) = %g."),
- dsc->valid, dsc->missing_listwise);
+ tab_title (t, _("Valid cases = %.*g; cases with missing value(s) = %.*g."),
+ DBL_DIG + 1, dsc->valid,
+ DBL_DIG + 1, dsc->missing_listwise);
tab_submit (t);
}