/* 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
#include <config.h>
-#include "xalloc.h"
-#include "xmalloca.h"
-
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-#define N_(msgid) msgid
+#include <math.h>
-#include <data/variable.h>
+#include <data/case.h>
+#include <data/casegrouper.h>
+#include <data/casereader.h>
#include <data/dictionary.h>
#include <data/procedure.h>
-#include <data/casereader.h>
-#include <data/casegrouper.h>
-#include <math/moments.h>
-#include <data/case.h>
-
+#include <data/variable.h>
#include <language/command.h>
-
+#include <libpspp/misc.h>
+#include <math/moments.h>
#include <output/manager.h>
#include <output/table.h>
+#include "xalloc.h"
+#include "xmalloca.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
/* (headers) */
/* (specification)
struct reliability
{
+ const struct dictionary *dict;
const struct variable **variables;
int n_variables;
enum mv_class exclude;
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};
goto done;
}
+ rel.dict = dataset_dict (ds);
rel.variables = cmd.v_variables;
rel.n_variables = cmd.n_variables;
rel.exclude = MV_ANY;
};
-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;
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 ++;
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);
{
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));
}
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] =
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"));
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"));
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);
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);
}
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,
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);
}
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"));
- 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 */
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);
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;
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"));
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);