X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Freliability.q;h=681669d18999fdac3c5516c9815b9079aae99dfb;hb=2cf38ce51a9f34961d68a75e0b312a591b5c9abf;hp=8384bb350312100214e33cfcff1b1f5057d70703;hpb=015e221b0f8578afee769528572c76387f26c629;p=pspp-builds.git diff --git a/src/language/stats/reliability.q b/src/language/stats/reliability.q index 8384bb35..681669d1 100644 --- a/src/language/stats/reliability.q +++ b/src/language/stats/reliability.q @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 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 @@ -16,26 +16,27 @@ #include -#include "xalloc.h" -#include "xmalloca.h" - -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid +#include -#include +#include +#include +#include #include #include -#include -#include -#include -#include - +#include #include - +#include +#include #include #include +#include "xalloc.h" +#include "xmalloca.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + /* (headers) */ /* (specification) @@ -100,6 +101,7 @@ enum model struct reliability { + const struct dictionary *dict; const struct variable **variables; int n_variables; enum mv_class exclude; @@ -142,7 +144,7 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) struct casereader *group; struct cmd_reliability cmd; - struct reliability rel = { + struct reliability rel = {NULL, NULL, 0, MV_ANY, NULL, 0, -1, DS_EMPTY_INITIALIZER, MODEL_ALPHA, 0}; @@ -154,6 +156,7 @@ cmd_reliability (struct lexer *lexer, struct dataset *ds) goto done; } + rel.dict = dataset_dict (ds); rel.variables = cmd.v_variables; rel.n_variables = cmd.n_variables; rel.exclude = MV_ANY; @@ -296,15 +299,16 @@ append_sum (const struct ccase *c, casenumber n UNUSED, void *aux) }; -static void case_processing_summary (casenumber n_valid, casenumber n_missing); +static void case_processing_summary (casenumber n_valid, casenumber n_missing, + const struct dictionary *dict); static void -run_reliability (struct casereader *input, struct dataset *ds UNUSED, +run_reliability (struct casereader *input, struct dataset *ds, struct reliability *rel) { int i; int si; - struct ccase c; + struct ccase *c; casenumber n_missing ; casenumber n_valid = 0; @@ -332,13 +336,13 @@ run_reliability (struct casereader *input, struct dataset *ds UNUSED, struct cronbach *s = &rel->sc[si]; - s->totals_idx = casereader_get_value_cnt (input); + s->totals_idx = caseproto_get_n_widths (casereader_get_proto (input)); input = casereader_create_append_numeric (input, append_sum, s, NULL); } - for (; casereader_read (input, &c); case_destroy (&c)) + for (; (c = casereader_read (input)) != NULL; case_unref (c)) { double weight = 1.0; n_valid ++; @@ -348,9 +352,9 @@ run_reliability (struct casereader *input, struct dataset *ds UNUSED, struct cronbach *s = &rel->sc[si]; for (i = 0 ; i < s->n_items ; ++i ) - moments1_add (s->m[i], case_data (&c, s->items[i])->f, weight); + moments1_add (s->m[i], case_data (c, s->items[i])->f, weight); - moments1_add (s->total, case_data_idx (&c, s->totals_idx)->f, weight); + moments1_add (s->total, case_data_idx (c, s->totals_idx)->f, weight); } } casereader_destroy (input); @@ -379,16 +383,16 @@ run_reliability (struct casereader *input, struct dataset *ds UNUSED, { struct tab_table *tab = tab_create(1, 1, 0); - tab_dim (tab, tab_natural_dimensions); + tab_dim (tab, tab_natural_dimensions, NULL); tab_flags (tab, SOMF_NO_TITLE ); - tab_text(tab, 0, 0, TAT_PRINTF, "Scale: %s", ds_cstr (&rel->scale_name)); + tab_text_format (tab, 0, 0, 0, "Scale: %s", ds_cstr (&rel->scale_name)); tab_submit(tab); } - case_processing_summary (n_valid, n_missing); + case_processing_summary (n_valid, n_missing, dataset_dict (ds)); } @@ -404,7 +408,7 @@ struct reliability_output_table int n_rows; int heading_cols; int heading_rows; - void (*populate)(struct tab_table *, const struct reliability *); + void (*populate) (struct tab_table *, const struct reliability *); }; static struct reliability_output_table rol[2] = @@ -424,7 +428,7 @@ reliability_statistics (const struct reliability *rel) struct tab_table *tbl = tab_create (n_cols, n_rows, 0); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); + tab_dim (tbl, tab_natural_dimensions, NULL); tab_title (tbl, _("Reliability Statistics")); @@ -467,7 +471,7 @@ reliability_summary_total (const struct reliability *rel) struct tab_table *tbl = tab_create (n_cols, n_rows, 0); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); + tab_dim (tbl, tab_natural_dimensions, NULL); tab_title (tbl, _("Item-Total Statistics")); @@ -514,14 +518,14 @@ reliability_summary_total (const struct reliability *rel) moments1_calculate (s->total, &weight, &mean, &var, 0, 0); - tab_float (tbl, 1, heading_rows + i, TAB_RIGHT, - mean, 8, 3); + tab_double (tbl, 1, heading_rows + i, TAB_RIGHT, + mean, NULL); - tab_float (tbl, 2, heading_rows + i, TAB_RIGHT, - s->variance_of_sums, 8, 3); + tab_double (tbl, 2, heading_rows + i, TAB_RIGHT, + s->variance_of_sums, NULL); - tab_float (tbl, 4, heading_rows + i, TAB_RIGHT, - s->alpha, 8, 3); + tab_double (tbl, 4, heading_rows + i, TAB_RIGHT, + s->alpha, NULL); moments1_calculate (rel->sc[0].m[i], &weight, &mean, &var, 0,0); @@ -531,8 +535,8 @@ reliability_summary_total (const struct reliability *rel) item_to_total_r = (cov - var) / (sqrt(var) * sqrt (s->variance_of_sums)); - tab_float (tbl, 3, heading_rows + i, TAB_RIGHT, - item_to_total_r, 8, 3); + tab_double (tbl, 3, heading_rows + i, TAB_RIGHT, + item_to_total_r, NULL); } @@ -544,6 +548,9 @@ static void reliability_statistics_model_alpha (struct tab_table *tbl, const struct reliability *rel) { + const struct variable *wv = dict_get_weight (rel->dict); + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; + const struct cronbach *s = &rel->sc[0]; tab_text (tbl, 0, 0, TAB_CENTER | TAT_TITLE, @@ -552,9 +559,9 @@ reliability_statistics_model_alpha (struct tab_table *tbl, tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE, _("N of items")); - tab_float (tbl, 0, 1, TAB_RIGHT, s->alpha, 8, 3); + tab_double (tbl, 0, 1, TAB_RIGHT, s->alpha, NULL); - tab_float (tbl, 1, 1, TAB_RIGHT, s->n_items, 8, 0); + tab_double (tbl, 1, 1, TAB_RIGHT, s->n_items, wfmt); } @@ -562,6 +569,9 @@ static void reliability_statistics_model_split (struct tab_table *tbl, const struct reliability *rel) { + const struct variable *wv = dict_get_weight (rel->dict); + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; + tab_text (tbl, 0, 0, TAB_LEFT, _("Cronbach's Alpha")); @@ -609,14 +619,14 @@ reliability_statistics_model_split (struct tab_table *tbl, - tab_float (tbl, 3, 0, TAB_RIGHT, rel->sc[1].alpha, 8, 3); - tab_float (tbl, 3, 2, TAB_RIGHT, rel->sc[2].alpha, 8, 3); + tab_double (tbl, 3, 0, TAB_RIGHT, rel->sc[1].alpha, NULL); + tab_double (tbl, 3, 2, TAB_RIGHT, rel->sc[2].alpha, NULL); - tab_float (tbl, 3, 1, TAB_RIGHT, rel->sc[1].n_items, 8, 0); - tab_float (tbl, 3, 3, TAB_RIGHT, rel->sc[2].n_items, 8, 0); + tab_double (tbl, 3, 1, TAB_RIGHT, rel->sc[1].n_items, wfmt); + tab_double (tbl, 3, 3, TAB_RIGHT, rel->sc[2].n_items, wfmt); - tab_float (tbl, 3, 4, TAB_RIGHT, - rel->sc[1].n_items + rel->sc[2].n_items, 8, 0); + tab_double (tbl, 3, 4, TAB_RIGHT, + rel->sc[1].n_items + rel->sc[2].n_items, wfmt); { /* R is the correlation between the two parts */ @@ -635,12 +645,12 @@ reliability_statistics_model_split (struct tab_table *tbl, r /= sqrt (rel->sc[2].variance_of_sums); r /= 2.0; - tab_float (tbl, 3, 5, TAB_RIGHT, r, 8, 3); + tab_double (tbl, 3, 5, TAB_RIGHT, r, NULL); /* Equal length Spearman-Brown Coefficient */ - tab_float (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), 8, 3); + tab_double (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), NULL); - tab_float (tbl, 3, 8, TAB_RIGHT, g, 8, 3); + tab_double (tbl, 3, 8, TAB_RIGHT, g, NULL); tmp = (1.0 - r*r) * rel->sc[1].n_items * rel->sc[2].n_items / pow2 (rel->sc[0].n_items); @@ -649,16 +659,19 @@ reliability_statistics_model_split (struct tab_table *tbl, uly -= pow2 (r); uly /= 2 * tmp; - tab_float (tbl, 3, 7, TAB_RIGHT, uly, 8, 3); - + tab_double (tbl, 3, 7, TAB_RIGHT, uly, NULL); } } static void -case_processing_summary (casenumber n_valid, casenumber n_missing) +case_processing_summary (casenumber n_valid, casenumber n_missing, + const struct dictionary *dict) { + const struct variable *wv = dict_get_weight (dict); + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; + casenumber total; int n_cols = 4; int n_rows = 4; @@ -668,7 +681,7 @@ case_processing_summary (casenumber n_valid, casenumber n_missing) tbl = tab_create (n_cols, n_rows, 0); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); + tab_dim (tbl, tab_natural_dimensions, NULL); tab_title (tbl, _("Case Processing Summary")); @@ -707,33 +720,32 @@ case_processing_summary (casenumber n_valid, casenumber n_missing) tab_text (tbl, heading_columns, 0, TAB_CENTER | TAT_TITLE, _("N")); - tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, - _("%%")); + tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE, _("%")); total = n_missing + n_valid; - tab_float (tbl, 2, heading_rows, TAB_RIGHT, - n_valid, 8, 0); + tab_double (tbl, 2, heading_rows, TAB_RIGHT, + n_valid, wfmt); - tab_float (tbl, 2, heading_rows + 1, TAB_RIGHT, - n_missing, 8, 0); + tab_double (tbl, 2, heading_rows + 1, TAB_RIGHT, + n_missing, wfmt); - tab_float (tbl, 2, heading_rows + 2, TAB_RIGHT, - total, 8, 0); + tab_double (tbl, 2, heading_rows + 2, TAB_RIGHT, + total, wfmt); - tab_float (tbl, 3, heading_rows, TAB_RIGHT, - 100 * n_valid / (double) total, 8, 1); + tab_double (tbl, 3, heading_rows, TAB_RIGHT, + 100 * n_valid / (double) total, NULL); - tab_float (tbl, 3, heading_rows + 1, TAB_RIGHT, - 100 * n_missing / (double) total, 8, 1); + tab_double (tbl, 3, heading_rows + 1, TAB_RIGHT, + 100 * n_missing / (double) total, NULL); - tab_float (tbl, 3, heading_rows + 2, TAB_RIGHT, - 100 * total / (double) total, 8, 1); + tab_double (tbl, 3, heading_rows + 2, TAB_RIGHT, + 100 * total / (double) total, NULL); tab_submit (tbl);