static void reliability_summary_total (const struct reliability *rel) { int i; const int n_cols = 5; const int heading_columns = 1; 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); tab_headers (tbl, heading_columns, 0, heading_rows, 0); tab_title (tbl, _("Item-Total Statistics")); /* Vertical lines for the data only */ tab_box (tbl, -1, -1, -1, TAL_1, heading_columns, 0, n_cols - 1, n_rows - 1); /* Box around table */ tab_box (tbl, TAL_2, TAL_2, -1, -1, 0, 0, n_cols - 1, n_rows - 1); tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows); tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1); tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE, _("Scale Mean if Item Deleted")); tab_text (tbl, 2, 0, TAB_CENTER | TAT_TITLE, _("Scale Variance if Item Deleted")); tab_text (tbl, 3, 0, TAB_CENTER | TAT_TITLE, _("Corrected Item-Total Correlation")); tab_text (tbl, 4, 0, TAB_CENTER | TAT_TITLE, _("Cronbach's Alpha if Item Deleted")); for (i = 0 ; i < rel->sc[0].n_items; ++i) { double cov, item_to_total_r; double mean, weight, var; const struct cronbach *s = &rel->sc[rel->total_start + i]; tab_text (tbl, 0, heading_rows + i, TAB_LEFT| TAT_TITLE, var_to_string (rel->sc[0].items[i])); moments1_calculate (s->total, &weight, &mean, &var, 0, 0); tab_double (tbl, 1, heading_rows + i, TAB_RIGHT, mean, NULL); tab_double (tbl, 2, heading_rows + i, TAB_RIGHT, s->variance_of_sums, NULL); tab_double (tbl, 4, heading_rows + i, TAB_RIGHT, s->alpha, NULL); moments1_calculate (rel->sc[0].m[i], &weight, &mean, &var, 0,0); cov = rel->sc[0].variance_of_sums + var - s->variance_of_sums; cov /= 2.0; item_to_total_r = (cov - var) / (sqrt(var) * sqrt (s->variance_of_sums)); tab_double (tbl, 3, heading_rows + i, TAB_RIGHT, item_to_total_r, NULL); } tab_submit (tbl); }
/* Writes an aggregated record to OUTPUT. */ static void dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, const struct ccase *break_case) { struct ccase *c = case_create (dict_get_proto (agr->dict)); if ( agr->add_variables) { case_copy (c, 0, break_case, 0, dict_get_var_cnt (agr->src_dict)); } else { int value_idx = 0; int i; for (i = 0; i < agr->break_var_cnt; i++) { const struct variable *v = agr->break_vars[i]; value_copy (case_data_rw_idx (c, value_idx), case_data (break_case, v), var_get_width (v)); value_idx++; } } { struct agr_var *i; for (i = agr->agr_vars; i; i = i->next) { union value *v = case_data_rw (c, i->dest); int width = var_get_width (i->dest); if (agr->missing == COLUMNWISE && i->saw_missing && (i->function & FUNC) != N && (i->function & FUNC) != NU && (i->function & FUNC) != NMISS && (i->function & FUNC) != NUMISS) { value_set_missing (v, width); casewriter_destroy (i->writer); continue; } switch (i->function) { case SUM: v->f = i->int1 ? i->dbl[0] : SYSMIS; break; case MEAN: v->f = i->dbl[1] != 0.0 ? i->dbl[0] / i->dbl[1] : SYSMIS; break; case MEDIAN: { if ( i->writer) { struct percentile *median = percentile_create (0.5, i->cc); struct order_stats *os = &median->parent; struct casereader *sorted_reader = casewriter_make_reader (i->writer); i->writer = NULL; order_stats_accumulate (&os, 1, sorted_reader, i->weight, i->subject, i->exclude); i->dbl[0] = percentile_calculate (median, PC_HAVERAGE); statistic_destroy (&median->parent.parent); } v->f = i->dbl[0]; } break; case SD: { double variance; /* FIXME: we should use two passes. */ moments1_calculate (i->moments, NULL, NULL, &variance, NULL, NULL); if (variance != SYSMIS) v->f = sqrt (variance); else v->f = SYSMIS; } break; case MAX: case MIN: v->f = i->int1 ? i->dbl[0] : SYSMIS; break; case MAX | FSTRING: case MIN | FSTRING: if (i->int1) memcpy (value_str_rw (v, width), i->string, width); else value_set_missing (v, width); break; case FGT: case FGT | FSTRING: case FLT: case FLT | FSTRING: case FIN: case FIN | FSTRING: case FOUT: case FOUT | FSTRING: v->f = i->dbl[1] ? i->dbl[0] / i->dbl[1] : SYSMIS; break; case PGT: case PGT | FSTRING: case PLT: case PLT | FSTRING: case PIN: case PIN | FSTRING: case POUT: case POUT | FSTRING: v->f = i->dbl[1] ? i->dbl[0] / i->dbl[1] * 100.0 : SYSMIS; break; case N: case N | FSTRING: v->f = i->dbl[0]; break; case NU: case NU | FSTRING: v->f = i->int1; break; case FIRST: case LAST: v->f = i->int1 ? i->dbl[0] : SYSMIS; break; case FIRST | FSTRING: case LAST | FSTRING: if (i->int1) memcpy (value_str_rw (v, width), i->string, width); else value_set_missing (v, width); break; case NMISS: case NMISS | FSTRING: v->f = i->dbl[0]; break; case NUMISS: case NUMISS | FSTRING: v->f = i->int1; break; default: NOT_REACHED (); } } } casewriter_write (output, c); }
static void do_reliability (struct casereader *input, struct dataset *ds, const struct reliability *rel) { int i; int si; struct ccase *c; casenumber n_missing ; casenumber n_valid = 0; for (si = 0 ; si < rel->n_sc; ++si) { struct cronbach *s = &rel->sc[si]; 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); } input = casereader_create_filter_missing (input, rel->variables, rel->n_variables, rel->exclude, &n_missing, NULL); for (si = 0 ; si < rel->n_sc; ++si) { struct cronbach *s = &rel->sc[si]; s->totals_idx = caseproto_get_n_widths (casereader_get_proto (input)); input = casereader_create_append_numeric (input, append_sum, s, NULL); } for (; (c = casereader_read (input)) != NULL; case_unref (c)) { double weight = 1.0; n_valid ++; for (si = 0; si < rel->n_sc; ++si) { 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->total, case_data_idx (c, s->totals_idx)->f, weight); } } casereader_destroy (input); for (si = 0; si < rel->n_sc; ++si) { struct cronbach *s = &rel->sc[si]; s->sum_of_variances = 0; for (i = 0 ; i < s->n_items ; ++i ) { double weight, mean, variance; moments1_calculate (s->m[i], &weight, &mean, &variance, NULL, NULL); s->sum_of_variances += variance; } moments1_calculate (s->total, NULL, NULL, &s->variance_of_sums, NULL, NULL); s->alpha = 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))); case_processing_summary (n_valid, n_missing, dataset_dict (ds)); }