X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Freliability.c;h=8975e4f9082d780bc18704a55ffccfba7ac6ca61;hb=490ac70d9c9f754f733552d64c23dd6aedced342;hp=695beabb5706d863dd716e5d24e1612afb9c777e;hpb=ff5e81803b409939e921211f1ffd46cb24df33e9;p=pspp diff --git a/src/language/stats/reliability.c b/src/language/stats/reliability.c index 695beabb57..8975e4f908 100644 --- a/src/language/stats/reliability.c +++ b/src/language/stats/reliability.c @@ -118,9 +118,10 @@ reliability_destroy (struct reliability *rel) { 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]); + moments1_destroy (rel->sc[j].total); + if (rel->sc[j].m) + for (x = 0; x < rel->sc[j].n_items; ++x) + free (rel->sc[j].m[x]); free (rel->sc[j].m); } @@ -374,6 +375,20 @@ run_reliability (struct dataset *ds, const struct reliability *reliability) struct casereader *group; struct casegrouper *grouper = casegrouper_create_splits (proc_open (ds), dict); + int si; + + for (si = 0 ; si < reliability->n_sc; ++si) + { + struct cronbach *s = &reliability->sc[si]; + int i; + + s->m = xzalloc (sizeof *s->m * s->n_items); + s->total = moments1_create (MOMENT_VARIANCE); + + for (i = 0 ; i < s->n_items ; ++i ) + s->m[i] = moments1_create (MOMENT_VARIANCE); + } + while (casegrouper_get_next_group (grouper, &group)) { @@ -437,11 +452,10 @@ do_reliability (struct casereader *input, struct dataset *ds, { struct cronbach *s = &rel->sc[si]; - s->m = xzalloc (sizeof (s->m) * s->n_items); - s->total = moments1_create (MOMENT_VARIANCE); + moments1_clear (s->total); for (i = 0 ; i < s->n_items ; ++i ) - s->m[i] = moments1_create (MOMENT_VARIANCE); + moments1_clear (s->m[i]); } input = casereader_create_filter_missing (input, @@ -523,6 +537,7 @@ case_processing_summary (casenumber n_valid, casenumber n_missing, int heading_rows = 1; struct tab_table *tbl; tbl = tab_create (n_cols, n_rows); + tab_set_format (tbl, RC_WEIGHT, wfmt); tab_headers (tbl, heading_columns, 0, heading_rows, 0); tab_title (tbl, _("Case Processing Summary")); @@ -567,27 +582,27 @@ case_processing_summary (casenumber n_valid, casenumber n_missing, total = n_missing + n_valid; tab_double (tbl, 2, heading_rows, TAB_RIGHT, - n_valid, wfmt); + n_valid, NULL, RC_WEIGHT); tab_double (tbl, 2, heading_rows + 1, TAB_RIGHT, - n_missing, wfmt); + n_missing, NULL, RC_WEIGHT); tab_double (tbl, 2, heading_rows + 2, TAB_RIGHT, - total, wfmt); + total, NULL, RC_WEIGHT); tab_double (tbl, 3, heading_rows, TAB_RIGHT, - 100 * n_valid / (double) total, NULL); + 100 * n_valid / (double) total, NULL, RC_OTHER); tab_double (tbl, 3, heading_rows + 1, TAB_RIGHT, - 100 * n_missing / (double) total, NULL); + 100 * n_missing / (double) total, NULL, RC_OTHER); tab_double (tbl, 3, heading_rows + 2, TAB_RIGHT, - 100 * total / (double) total, NULL); + 100 * total / (double) total, NULL, RC_OTHER); tab_submit (tbl); @@ -603,8 +618,10 @@ reliability_summary_total (const struct reliability *rel) const int heading_columns = 1; const int heading_rows = 1; const int n_rows = rel->sc[0].n_items + heading_rows ; - + const struct variable *wv = rel->wv; + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; struct tab_table *tbl = tab_create (n_cols, n_rows); + tab_set_format (tbl, RC_WEIGHT, wfmt); tab_headers (tbl, heading_columns, 0, heading_rows, 0); tab_title (tbl, _("Item-Total Statistics")); @@ -653,13 +670,13 @@ reliability_summary_total (const struct reliability *rel) moments1_calculate (s->total, &weight, &mean, &var, 0, 0); tab_double (tbl, 1, heading_rows + i, TAB_RIGHT, - mean, NULL); + mean, NULL, RC_OTHER); tab_double (tbl, 2, heading_rows + i, TAB_RIGHT, - s->variance_of_sums, NULL); + s->variance_of_sums, NULL, RC_OTHER); tab_double (tbl, 4, heading_rows + i, TAB_RIGHT, - s->alpha, NULL); + s->alpha, NULL, RC_OTHER); moments1_calculate (rel->sc[0].m[i], &weight, &mean, &var, 0,0); @@ -670,7 +687,7 @@ reliability_summary_total (const struct reliability *rel) tab_double (tbl, 3, heading_rows + i, TAB_RIGHT, - item_to_total_r, NULL); + item_to_total_r, NULL, RC_OTHER); } @@ -708,8 +725,11 @@ reliability_statistics (const struct reliability *rel) int n_rows = rol[rel->model].n_rows; int heading_columns = rol[rel->model].heading_cols; int heading_rows = rol[rel->model].heading_rows; - + const struct variable *wv = rel->wv; + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; struct tab_table *tbl = tab_create (n_cols, n_rows); + tab_set_format (tbl, RC_WEIGHT, wfmt); + tab_headers (tbl, heading_columns, 0, heading_rows, 0); tab_title (tbl, _("Reliability Statistics")); @@ -746,9 +766,6 @@ static void reliability_statistics_model_alpha (struct tab_table *tbl, const struct reliability *rel) { - const struct variable *wv = rel->wv; - 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, @@ -757,9 +774,9 @@ reliability_statistics_model_alpha (struct tab_table *tbl, tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE, _("N of Items")); - tab_double (tbl, 0, 1, TAB_RIGHT, s->alpha, NULL); + tab_double (tbl, 0, 1, TAB_RIGHT, s->alpha, NULL, RC_OTHER); - tab_double (tbl, 1, 1, TAB_RIGHT, s->n_items, wfmt); + tab_double (tbl, 1, 1, TAB_RIGHT, s->n_items, NULL, RC_WEIGHT); } @@ -767,9 +784,6 @@ static void reliability_statistics_model_split (struct tab_table *tbl, const struct reliability *rel) { - const struct variable *wv = rel->wv; - const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; - tab_text (tbl, 0, 0, TAB_LEFT, _("Cronbach's Alpha")); @@ -782,8 +796,6 @@ reliability_statistics_model_split (struct tab_table *tbl, tab_text (tbl, 2, 1, TAB_LEFT, _("N of Items")); - - tab_text (tbl, 1, 2, TAB_LEFT, _("Part 2")); @@ -793,15 +805,12 @@ reliability_statistics_model_split (struct tab_table *tbl, tab_text (tbl, 2, 3, TAB_LEFT, _("N of Items")); - - tab_text (tbl, 1, 4, TAB_LEFT, _("Total N of Items")); tab_text (tbl, 0, 5, TAB_LEFT, _("Correlation Between Forms")); - tab_text (tbl, 0, 6, TAB_LEFT, _("Spearman-Brown Coefficient")); @@ -817,14 +826,14 @@ reliability_statistics_model_split (struct tab_table *tbl, - 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_double (tbl, 3, 0, TAB_RIGHT, rel->sc[1].alpha, NULL, RC_OTHER); + tab_double (tbl, 3, 2, TAB_RIGHT, rel->sc[2].alpha, NULL, RC_OTHER); - 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_double (tbl, 3, 1, TAB_RIGHT, rel->sc[1].n_items, NULL, RC_WEIGHT); + tab_double (tbl, 3, 3, TAB_RIGHT, rel->sc[2].n_items, NULL, RC_WEIGHT); tab_double (tbl, 3, 4, TAB_RIGHT, - rel->sc[1].n_items + rel->sc[2].n_items, wfmt); + rel->sc[1].n_items + rel->sc[2].n_items, NULL, RC_WEIGHT); { /* R is the correlation between the two parts */ @@ -843,12 +852,12 @@ reliability_statistics_model_split (struct tab_table *tbl, r /= sqrt (rel->sc[2].variance_of_sums); r /= 2.0; - tab_double (tbl, 3, 5, TAB_RIGHT, r, NULL); + tab_double (tbl, 3, 5, TAB_RIGHT, r, NULL, RC_OTHER); /* Equal length Spearman-Brown Coefficient */ - tab_double (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), NULL); + tab_double (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), NULL, RC_OTHER); - tab_double (tbl, 3, 8, TAB_RIGHT, g, NULL); + tab_double (tbl, 3, 8, TAB_RIGHT, g, NULL, RC_OTHER); tmp = (1.0 - r*r) * rel->sc[1].n_items * rel->sc[2].n_items / pow2 (rel->sc[0].n_items); @@ -857,7 +866,7 @@ reliability_statistics_model_split (struct tab_table *tbl, uly -= pow2 (r); uly /= 2 * tmp; - tab_double (tbl, 3, 7, TAB_RIGHT, uly, NULL); + tab_double (tbl, 3, 7, TAB_RIGHT, uly, NULL, RC_OTHER); } }