From: Michael Kiefte Date: Tue, 6 Apr 2004 18:14:36 +0000 (+0000) Subject: * Changed dict_get_case_weight() to accept an additional int * flag to complain about... X-Git-Tag: sav-api~2523 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf89e411db41c05c39753b05cf144c8b26a44d96;p=pspp * Changed dict_get_case_weight() to accept an additional int * flag to complain about system-missing, user-missing, zero, or negative weights. * Updated existing functions to pass int * to dict_get_case_weight(). --- diff --git a/src/aggregate.c b/src/aggregate.c index b345ca113e..9ffa35f5b5 100644 --- a/src/aggregate.c +++ b/src/aggregate.c @@ -794,8 +794,9 @@ accumulate_aggregate_info (struct agr_proc *agr, { struct agr_var *iter; double weight; + int bad_warn = 1; - weight = dict_get_case_weight (default_dict, input); + weight = dict_get_case_weight (default_dict, input, &bad_warn); for (iter = agr->vars; iter; iter = iter->next) if (iter->src) diff --git a/src/crosstabs.q b/src/crosstabs.q index 1f66f066b3..4a58d10c96 100644 --- a/src/crosstabs.q +++ b/src/crosstabs.q @@ -584,8 +584,10 @@ precalc (void *aux UNUSED) static int calc_general (struct ccase *c, void *aux UNUSED) { + int bad_warn = 1; + /* Case weight. */ - double weight = dict_get_case_weight (default_dict, c); + double weight = dict_get_case_weight (default_dict, c, &bad_warn); /* Flattened current table index. */ int t; @@ -656,8 +658,10 @@ calc_general (struct ccase *c, void *aux UNUSED) static int calc_integer (struct ccase *c, void *aux UNUSED) { + int bad_warn = 1; + /* Case weight. */ - double weight = dict_get_case_weight (default_dict, c); + double weight = dict_get_case_weight (default_dict, c, &bad_warn); /* Flattened current table index. */ int t; diff --git a/src/descript.c b/src/descript.c index e7577ae791..7d25b3138d 100644 --- a/src/descript.c +++ b/src/descript.c @@ -142,7 +142,7 @@ struct dsc_proc /* Accumulated results. */ double missing_listwise; /* Sum of weights of cases missing listwise. */ double valid; /* Sum of weights of valid cases. */ - int bad_weight; /* Nonzero if a bad weight has been found. */ + int bad_warn; /* Warn if bad weight found. */ enum dsc_statistic sort_by_stat; /* Statistic to sort by; -1: name. */ int sort_ascending; /* !0: ascending order; 0: descending. */ unsigned long show_stats; /* Statistics to display. */ @@ -189,7 +189,7 @@ cmd_descriptives (void) dsc->format = DSC_LINE; dsc->missing_listwise = 0.; dsc->valid = 0.; - dsc->bad_weight = 0; + dsc->bad_warn = 1; dsc->sort_by_stat = DSC_NONE; dsc->sort_ascending = 1; dsc->show_stats = dsc->calc_stats = DEFAULT_STATS; @@ -386,10 +386,6 @@ cmd_descriptives (void) /* Data pass. */ multipass_procedure_with_splits (calc_descriptives, dsc); - if (dsc->bad_weight) - msg (SW, _("At least one case in the data file had a weight value " - "that was system-missing, zero, or negative. These case(s) " - "were ignored.")); /* Z-scoring! */ if (z_cnt) @@ -661,13 +657,10 @@ calc_descriptives (const struct casefile *cf, void *dsc_) reader = casefile_get_reader (cf); while (casereader_read (reader, &c)) { - double weight = dict_get_case_weight (default_dict, c); + double weight = dict_get_case_weight (default_dict, c, &dsc->bad_warn); if (weight <= 0.0) - { - dsc->bad_weight = 1; continue; - } - + /* Check for missing values. */ if (listwise_missing (dsc, c)) { @@ -707,7 +700,8 @@ calc_descriptives (const struct casefile *cf, void *dsc_) reader = casefile_get_reader (cf); while (casereader_read (reader, &c)) { - double weight = dict_get_case_weight (default_dict, c); + double weight = dict_get_case_weight (default_dict, c, + &dsc->bad_warn); if (weight <= 0.0) continue; diff --git a/src/dictionary.c b/src/dictionary.c index f2ac187a1d..8cceaf1a80 100644 --- a/src/dictionary.c +++ b/src/dictionary.c @@ -558,11 +558,14 @@ dict_get_weight (const struct dictionary *d) return d->weight; } -/* Returns the value of D's weighting variable in case C, except - that a negative weight is returned as 0. Returns 1 if the - dictionary is unweighted. */ +/* Returns the value of D's weighting variable in case C, except that a + negative weight is returned as 0. Returns 1 if the dictionary is + unweighted. Will warn about missing, negative, or zero values if + warn_on_invalid is nonzero. The function will set warn_on_invalid to zero + if an invalid weight is found. */ double -dict_get_case_weight (const struct dictionary *d, const struct ccase *c) +dict_get_case_weight (const struct dictionary *d, const struct ccase *c, + int *warn_on_invalid) { assert (d != NULL); assert (c != NULL); @@ -572,8 +575,14 @@ dict_get_case_weight (const struct dictionary *d, const struct ccase *c) else { double w = c->data[d->weight->fv].f; - if (w < 0.0) + if ( w < 0.0 || w == SYSMIS || is_num_user_missing(w, d->weight) ) w = 0.0; + if ( w == 0.0 && *warn_on_invalid ) { + *warn_on_invalid = 0; + msg (SW, _("At least one case in the data file had a weight value " + "that was user-missing, system-missing, zero, or " + "negative. These case(s) were ignored.")); + } return w; } } diff --git a/src/frequencies.q b/src/frequencies.q index d9926f6d67..8a4151640e 100644 --- a/src/frequencies.q +++ b/src/frequencies.q @@ -370,8 +370,9 @@ calc (struct ccase *c, void *aux UNUSED) { double weight; int i; + int bad_warn = 1; - weight = dict_get_case_weight (default_dict, c); + weight = dict_get_case_weight (default_dict, c, &bad_warn); for (i = 0; i < n_variables; i++) { diff --git a/src/levene.c b/src/levene.c index 5b633746e3..cfbab7bec2 100644 --- a/src/levene.c +++ b/src/levene.c @@ -232,10 +232,11 @@ static int levene_calc (const struct ccase *c, void *_l) { int i; + int warn = 0; struct levene_info *l = (struct levene_info *) _l; const union value *gv = &c->data[l->v_indep->fv]; struct group_statistics key; - double weight = dict_get_case_weight(default_dict,c); + double weight = dict_get_case_weight(default_dict,c,&warn); /* Skip the entire case if /MISSING=LISTWISE is set */ @@ -327,10 +328,11 @@ static int levene2_calc (const struct ccase *c, void *_l) { int i; + int warn = 0; struct levene_info *l = (struct levene_info *) _l; - double weight = dict_get_case_weight(default_dict,c); + double weight = dict_get_case_weight(default_dict,c,&warn); const union value *gv = &c->data[l->v_indep->fv]; struct group_statistics key; diff --git a/src/t-test.q b/src/t-test.q index 172f236d7f..4c4135ba73 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -208,7 +208,7 @@ static int mode; static struct cmd_t_test cmd; - +static int bad_weight_warn; int cmd_t_test(void) @@ -296,6 +296,8 @@ cmd_t_test(void) else value_is_missing = is_missing; + bad_weight_warn = 1; + multipass_procedure_with_splits (calculate, &cmd); n_pairs=0; @@ -1303,7 +1305,7 @@ common_calc (const struct ccase *c, void *_cmd) int i; struct cmd_t_test *cmd = (struct cmd_t_test *)_cmd; - double weight = dict_get_case_weight(default_dict,c); + double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set */ @@ -1403,7 +1405,7 @@ one_sample_calc (const struct ccase *c, void *cmd_) struct cmd_t_test *cmd = (struct cmd_t_test *)cmd_; - double weight = dict_get_case_weight(default_dict,c); + double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set */ if ( cmd->miss == TTS_LISTWISE ) @@ -1512,7 +1514,7 @@ paired_calc (const struct ccase *c, void *cmd_) struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_; - double weight = dict_get_case_weight(default_dict,c); + double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set , AND one member of a pair is missing */ @@ -1676,7 +1678,7 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd) const union value *gv = &c->data[indep_var->fv]; - const double weight = dict_get_case_weight(default_dict,c); + const double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); if ( value_is_missing(gv,indep_var) ) { diff --git a/src/var.h b/src/var.h index faf2cd2bd5..6b82624317 100644 --- a/src/var.h +++ b/src/var.h @@ -301,7 +301,8 @@ int dict_rename_vars (struct dictionary *, size_t count, char **err_name); struct variable *dict_get_weight (const struct dictionary *); -double dict_get_case_weight (const struct dictionary *, const struct ccase *); +double dict_get_case_weight (const struct dictionary *, + const struct ccase *, int *); void dict_set_weight (struct dictionary *, struct variable *); struct variable *dict_get_filter (const struct dictionary *);