X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Freliability.c;h=695beabb5706d863dd716e5d24e1612afb9c777e;hb=80788c833f111c2e9aef3e25bdb44d6a56423313;hp=34daf7239f7b3e57216b8e7f0640bef27bee4835;hpb=01b970b8972e4e457b1d8e3f5af350c325152942;p=pspp diff --git a/src/language/stats/reliability.c b/src/language/stats/reliability.c index 34daf7239f..695beabb57 100644 --- a/src/language/stats/reliability.c +++ b/src/language/stats/reliability.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011, 2013 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 @@ -18,26 +18,21 @@ #include -#include - -#include -#include - - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include +#include "data/casegrouper.h" +#include "data/casereader.h" +#include "data/dataset.h" +#include "data/dictionary.h" +#include "data/format.h" +#include "data/missing-values.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "language/lexer/variable-parser.h" +#include "libpspp/message.h" +#include "libpspp/misc.h" +#include "libpspp/str.h" +#include "math/moments.h" +#include "output/tab.h" +#include "output/text-item.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -113,6 +108,26 @@ struct reliability static bool run_reliability (struct dataset *ds, const struct reliability *reliability); +static void +reliability_destroy (struct reliability *rel) +{ + int j; + ds_destroy (&rel->scale_name); + if (rel->sc) + for (j = 0; j < rel->n_sc ; ++j) + { + int x; + free (rel->sc[j].items); + moments1_destroy (rel->sc[j].total); + for (x = 0; x < rel->sc[j].n_items; ++x) + free (rel->sc[j].m[x]); + free (rel->sc[j].m); + } + + free (rel->sc); + free (rel->variables); +} + int cmd_reliability (struct lexer *lexer, struct dataset *ds) { @@ -122,21 +137,23 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) reliability.n_variables = 0; reliability.variables = NULL; reliability.model = MODEL_ALPHA; - reliability.exclude = MV_ANY; + reliability.exclude = MV_ANY; reliability.summary = 0; - + reliability.n_sc = 0; + reliability.sc = NULL; reliability.wv = dict_get_weight (dict); - reliability.total_start = 0; + ds_init_empty (&reliability.scale_name); + - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (!lex_force_match_id (lexer, "VARIABLES")) { goto error; } - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (!parse_variables_const (lexer, dict, &reliability.variables, &reliability.n_variables, PV_NO_DUPLICATE | PV_NUMERIC)) @@ -154,7 +171,7 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) reliability.n_sc = 1; reliability.sc = xzalloc (sizeof (struct cronbach) * reliability.n_sc); - ds_init_cstr (&reliability.scale_name, "ANY"); + ds_assign_cstr (&reliability.scale_name, "ANY"); c = &reliability.sc[0]; c->n_items = reliability.n_variables; @@ -166,31 +183,31 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) - while (lex_token (lexer) != '.') + while (lex_token (lexer) != T_ENDCMD) { - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (lex_match_id (lexer, "SCALE")) { struct const_var_set *vs; - if ( ! lex_force_match (lexer, '(')) + if ( ! lex_force_match (lexer, T_LPAREN)) goto error; if ( ! lex_force_string (lexer) ) goto error; - ds_init_string (&reliability.scale_name, lex_tokstr (lexer)); + ds_assign_substring (&reliability.scale_name, lex_tokss (lexer)); lex_get (lexer); - if ( ! lex_force_match (lexer, ')')) + if ( ! lex_force_match (lexer, T_RPAREN)) goto error; - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); vs = const_var_set_create_from_array (reliability.variables, reliability.n_variables); - + free (reliability.sc->items); if (!parse_const_var_set_vars (lexer, vs, &reliability.sc->items, &reliability.sc->n_items, 0)) { const_var_set_destroy (vs); @@ -201,7 +218,7 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "MODEL")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "ALPHA")) { reliability.model = MODEL_ALPHA; @@ -211,12 +228,12 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) reliability.model = MODEL_SPLIT; reliability.split_point = -1; - if ( lex_match (lexer, '(')) + if ( lex_match (lexer, T_LPAREN)) { lex_force_num (lexer); reliability.split_point = lex_number (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else @@ -224,7 +241,7 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "SUMMARY")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "TOTAL")) { reliability.summary |= SUMMARY_TOTAL; @@ -238,8 +255,8 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "MISSING")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "INCLUDE")) { @@ -268,6 +285,12 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) int i; const struct cronbach *s; + if ( reliability.split_point >= reliability.n_variables) + { + msg (ME, _("The split point must be less than the number of variables")); + goto error; + } + reliability.n_sc += 2 ; reliability.sc = xrealloc (reliability.sc, sizeof (struct cronbach) * reliability.n_sc); @@ -324,11 +347,11 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) if ( ! run_reliability (ds, &reliability)) goto error; - free (reliability.variables); + reliability_destroy (&reliability); return CMD_SUCCESS; error: - free (reliability.variables); + reliability_destroy (&reliability); return CMD_FAILURE; } @@ -352,7 +375,6 @@ run_reliability (struct dataset *ds, const struct reliability *reliability) struct casegrouper *grouper = casegrouper_create_splits (proc_open (ds), dict); - while (casegrouper_get_next_group (grouper, &group)) { do_reliability (group, ds, reliability); @@ -477,7 +499,7 @@ do_reliability (struct casereader *input, struct dataset *ds, alpha (s->n_items, s->sum_of_variances, s->variance_of_sums); } - text_item_submit (text_item_create_format (TEXT_ITEM_PARAGRAPH, "Scale: %s", + text_item_submit (text_item_create_format (TEXT_ITEM_PARAGRAPH, _("Scale: %s"), ds_cstr (&rel->scale_name))); case_processing_summary (n_valid, n_missing, dataset_dict (ds));