/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007, 2009, 2010, 2011 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 <language/stats/chisquare.h>
+#include "language/stats/chisquare.h"
#include <gsl/gsl_cdf.h>
#include <math.h>
#include <stdlib.h>
-#include "data/format.h"
#include "data/case.h"
#include "data/casereader.h"
+#include "data/dataset.h"
#include "data/dictionary.h"
-#include "data/procedure.h"
+#include "data/format.h"
#include "data/value-labels.h"
#include "data/variable.h"
#include "language/stats/freq.h"
}
}
+ free (entries);
+
return casereader_destroy (input);
}
struct tab_table *table ;
const struct variable *var = ost->vars[v];
+ const struct variable *wvar = dict_get_weight (dict);
+ const struct fmt_spec *wfmt = wvar ? var_get_print_format (wvar) : & F_8_0;
+
hmap_init (freq_hash);
if (!create_freq_hash (dict, input, var, freq_hash))
{
test->n_expected, n_cells,
var_get_name (var)
);
+ freq_hmap_destroy (freq_hash, var_get_width (var));
return NULL;
}
table = tab_create(4, n_cells + 2);
+ tab_set_format (table, RC_WEIGHT, wfmt);
tab_title (table, "%s", var_to_string(var));
tab_text (table, 1, 0, TAB_LEFT, _("Observed N"));
static struct tab_table *
-create_combo_frequency_table (const struct chisquare_test *test)
+create_combo_frequency_table (const struct dictionary *dict, const struct chisquare_test *test)
{
int i;
const struct one_sample_test *ost = (const struct one_sample_test*)test;
struct tab_table *table ;
+ const struct variable *wvar = dict_get_weight (dict);
+ const struct fmt_spec *wfmt = wvar ? var_get_print_format (wvar) : & F_8_0;
+
int n_cells = test->hi - test->lo + 1;
table = tab_create(1 + ost->n_vars * 4, n_cells + 3);
+ tab_set_format (table, RC_WEIGHT, wfmt);
tab_title (table, _("Frequencies"));
for ( i = 0 ; i < ost->n_vars ; ++i )
}
for ( i = test->lo ; i <= test->hi ; ++i )
- tab_fixed (table, 0, 2 + i - test->lo,
- TAB_LEFT, 1 + i - test->lo, 8, 0);
+ tab_double (table, 0, 2 + i - test->lo, TAB_LEFT, 1 + i - test->lo, NULL, RC_INTEGER);
tab_headers (table, 1, 0, 2, 0);
struct one_sample_test *ost = &cst->parent;
int n_cells = 0;
double total_expected = 0.0;
- const struct variable *wvar = dict_get_weight (dict);
- const struct fmt_spec *wfmt = wvar ?
- var_get_print_format (wvar) : & F_8_0;
double *df = xzalloc (sizeof (*df) * ost->n_vars);
double *xsq = xzalloc (sizeof (*df) * ost->n_vars);
&var, 1, exclude,
NULL, NULL);
struct tab_table *freq_table =
- create_variable_frequency_table(dict, reader, cst, v, &freq_hash);
+ create_variable_frequency_table (dict, reader, cst, v, &freq_hash);
struct freq **ff;
{
struct string str;
double exp;
- const union value *observed_value = &ff[i]->value;
+ const union value *observed_value = &ff[i]->values[0];
ds_init_empty (&str);
var_append_value_name (var, observed_value, &str);
/* The observed N */
tab_double (freq_table, 1, i + 1, TAB_NONE,
- ff[i]->count, wfmt);
+ ff[i]->count, NULL, RC_WEIGHT);
if ( cst->n_expected > 0 )
exp = cst->expected[i] * total_obs / total_expected ;
exp = total_obs / (double) n_cells;
tab_double (freq_table, 2, i + 1, TAB_NONE,
- exp, NULL);
+ exp, NULL, RC_OTHER);
/* The residual */
tab_double (freq_table, 3, i + 1, TAB_NONE,
- ff[i]->count - exp, NULL);
+ ff[i]->count - exp, NULL, RC_OTHER);
xsq[v] += (ff[i]->count - exp) * (ff[i]->count - exp) / exp;
}
df[v] = n_cells - 1.0;
tab_double (freq_table, 1, i + 1, TAB_NONE,
- total_obs, wfmt);
+ total_obs, NULL, RC_WEIGHT);
tab_submit (freq_table);
}
else /* ranged == true */
{
- struct tab_table *freq_table = create_combo_frequency_table (cst);
+ struct tab_table *freq_table = create_combo_frequency_table (dict, cst);
n_cells = cst->hi - cst->lo + 1;
struct string str;
double exp;
- const union value *observed_value = &ff[i]->value;
+ const union value *observed_value = &ff[i]->values[0];
ds_init_empty (&str);
var_append_value_name (ost->vars[v], observed_value, &str);
/* The observed N */
tab_double (freq_table, v * 4 + 2, i + 2 , TAB_NONE,
- ff[i]->count, wfmt);
+ ff[i]->count, NULL, RC_WEIGHT);
if ( cst->n_expected > 0 )
exp = cst->expected[i] * total_obs / total_expected ;
/* The expected N */
tab_double (freq_table, v * 4 + 3, i + 2 , TAB_NONE,
- exp, NULL);
+ exp, NULL, RC_OTHER);
/* The residual */
tab_double (freq_table, v * 4 + 4, i + 2 , TAB_NONE,
- ff[i]->count - exp, NULL);
+ ff[i]->count - exp, NULL, RC_OTHER);
xsq[v] += (ff[i]->count - exp) * (ff[i]->count - exp) / exp;
}
tab_double (freq_table, v * 4 + 2, tab_nr (freq_table) - 1, TAB_NONE,
- total_obs, wfmt);
+ total_obs, NULL, RC_WEIGHT);
df[v] = n_cells - 1.0;
tab_text (stats_table, 1 + v, 0, TAB_CENTER, var_get_name (var));
- tab_double (stats_table, 1 + v, 1, TAB_NONE, xsq[v], NULL);
- tab_fixed (stats_table, 1 + v, 2, TAB_NONE, df[v], 8, 0);
+ tab_double (stats_table, 1 + v, 1, TAB_NONE, xsq[v], NULL, RC_OTHER);
+ tab_double (stats_table, 1 + v, 2, TAB_NONE, df[v], NULL, RC_INTEGER);
tab_double (stats_table, 1 + v, 3, TAB_NONE,
- gsl_cdf_chisq_Q (xsq[v], df[v]), NULL);
+ gsl_cdf_chisq_Q (xsq[v], df[v]), NULL, RC_PVALUE);
}
tab_submit (stats_table);
}