X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Freliability.q;h=7eb20807ff645111b17353122a302ddcd431294f;hb=34609a03d32e4f974f8653fdb735674c07539402;hp=8384bb350312100214e33cfcff1b1f5057d70703;hpb=290077732ca206c99fe3d83697b38ff53af83361;p=pspp-builds.git diff --git a/src/language/stats/reliability.q b/src/language/stats/reliability.q index 8384bb35..7eb20807 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, 2010 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,25 +16,26 @@ #include -#include "xalloc.h" -#include "xmalloca.h" +#include -#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 "xalloc.h" +#include "xmalloca.h" -#include -#include +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid /* (headers) */ @@ -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); @@ -375,20 +379,10 @@ run_reliability (struct casereader *input, struct dataset *ds UNUSED, alpha (s->n_items, s->sum_of_variances, s->variance_of_sums); } + text_item_submit (text_item_create_format (TEXT_ITEM_PARAGRAPH, "Scale: %s", + ds_cstr (&rel->scale_name))); - { - struct tab_table *tab = tab_create(1, 1, 0); - - tab_dim (tab, tab_natural_dimensions); - tab_flags (tab, SOMF_NO_TITLE ); - - tab_text(tab, 0, 0, TAT_PRINTF, "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 +398,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] = @@ -421,11 +415,9 @@ reliability_statistics (const struct reliability *rel) int heading_columns = rol[rel->model].heading_cols; int heading_rows = rol[rel->model].heading_rows; - struct tab_table *tbl = tab_create (n_cols, n_rows, 0); + struct tab_table *tbl = tab_create (n_cols, n_rows); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); - tab_title (tbl, _("Reliability Statistics")); /* Vertical lines for the data only */ @@ -464,11 +456,9 @@ reliability_summary_total (const struct reliability *rel) const int heading_rows = 1; const int n_rows = rel->sc[0].n_items + heading_rows ; - struct tab_table *tbl = tab_create (n_cols, n_rows, 0); + struct tab_table *tbl = tab_create (n_cols, n_rows); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); - tab_title (tbl, _("Item-Total Statistics")); /* Vertical lines for the data only */ @@ -514,14 +504,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 +521,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,17 +534,20 @@ 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, _("Cronbach's Alpha")); tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE, - _("N of items")); + _("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 +555,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 +605,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 +631,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,27 +645,28 @@ 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; int heading_columns = 2; int heading_rows = 1; struct tab_table *tbl; - tbl = tab_create (n_cols, n_rows, 0); + tbl = tab_create (n_cols, n_rows); tab_headers (tbl, heading_columns, 0, heading_rows, 0); - tab_dim (tbl, tab_natural_dimensions); - tab_title (tbl, _("Case Processing Summary")); /* Vertical lines for the data only */ @@ -707,33 +704,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);