projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Make cases simpler, faster, and easier to understand.
[pspp]
/
src
/
language
/
stats
/
chisquare.c
diff --git
a/src/language/stats/chisquare.c
b/src/language/stats/chisquare.c
index 1b8392724db880a3fdae76187a9e4b2a08ccbe57..19496d7ead9016de96949f5502abfdc6f7576eea 100644
(file)
--- a/
src/language/stats/chisquare.c
+++ b/
src/language/stats/chisquare.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2007
, 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
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
@@
-29,7
+29,6
@@
#include <data/variable.h>
#include <language/stats/freq.h>
#include <language/stats/npar.h>
#include <data/variable.h>
#include <language/stats/freq.h>
#include <language/stats/npar.h>
-#include <libpspp/alloc.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/hash.h>
#include <libpspp/assertion.h>
#include <libpspp/compiler.h>
#include <libpspp/hash.h>
@@
-39,6
+38,8
@@
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_cdf.h>
+#include "xalloc.h"
+
#include "gettext.h"
#define _(msgid) gettext (msgid)
#include "gettext.h"
#define _(msgid) gettext (msgid)
@@
-56,7
+57,7
@@
create_freq_hash_with_range (const struct dictionary *dict,
{
bool warn = true;
float i_d;
{
bool warn = true;
float i_d;
- struct ccase c;
+ struct ccase
*
c;
struct hsh_table *freq_hash =
hsh_create (4, compare_freq, hash_freq,
struct hsh_table *freq_hash =
hsh_create (4, compare_freq, hash_freq,
@@
-77,21
+78,21
@@
create_freq_hash_with_range (const struct dictionary *dict,
hsh_insert (freq_hash, fr);
}
hsh_insert (freq_hash, fr);
}
- while (
casereader_read (input, &c)
)
+ while (
(c = casereader_read (input)) != NULL
)
{
union value obs_value;
struct freq **existing_fr;
struct freq *fr = xmalloc(sizeof (*fr));
{
union value obs_value;
struct freq **existing_fr;
struct freq *fr = xmalloc(sizeof (*fr));
- fr->value = case_data (
&
c, var);
+ fr->value = case_data (c, var);
- fr->count = dict_get_case_weight (dict,
&
c, &warn);
+ fr->count = dict_get_case_weight (dict, c, &warn);
obs_value.f = trunc (fr->value->f);
if ( obs_value.f < lo || obs_value.f > hi)
{
free (fr);
obs_value.f = trunc (fr->value->f);
if ( obs_value.f < lo || obs_value.f > hi)
{
free (fr);
- case_
destroy (&
c);
+ case_
unref (
c);
continue;
}
continue;
}
@@
-106,7
+107,7
@@
create_freq_hash_with_range (const struct dictionary *dict,
(*existing_fr)->count += fr->count;
free (fr);
(*existing_fr)->count += fr->count;
free (fr);
- case_
destroy (&
c);
+ case_
unref (
c);
}
if (casereader_destroy (input))
return freq_hash;
}
if (casereader_destroy (input))
return freq_hash;
@@
-129,20
+130,20
@@
create_freq_hash (const struct dictionary *dict,
const struct variable *var)
{
bool warn = true;
const struct variable *var)
{
bool warn = true;
- struct ccase c;
+ struct ccase
*
c;
struct hsh_table *freq_hash =
hsh_create (4, compare_freq, hash_freq,
free_freq_mutable_hash,
(void *) var);
struct hsh_table *freq_hash =
hsh_create (4, compare_freq, hash_freq,
free_freq_mutable_hash,
(void *) var);
- for (;
casereader_read (input, &c); case_destroy (&
c))
+ for (;
(c = casereader_read (input)) != NULL; case_unref (
c))
{
struct freq **existing_fr;
struct freq *fr = xmalloc(sizeof (*fr));
{
struct freq **existing_fr;
struct freq *fr = xmalloc(sizeof (*fr));
- fr->value = case_data (
&
c, var);
+ fr->value = case_data (c, var);
- fr->count = dict_get_case_weight (dict,
&
c, &warn);
+ fr->count = dict_get_case_weight (dict, c, &warn);
existing_fr = (struct freq **) hsh_probe (freq_hash, fr);
if ( *existing_fr)
existing_fr = (struct freq **) hsh_probe (freq_hash, fr);
if ( *existing_fr)
@@
-319,7
+320,9
@@
void
chisquare_execute (const struct dataset *ds,
struct casereader *input,
enum mv_class exclude,
chisquare_execute (const struct dataset *ds,
struct casereader *input,
enum mv_class exclude,
- const struct npar_test *test)
+ const struct npar_test *test,
+ bool exact UNUSED,
+ double timer UNUSED)
{
const struct dictionary *dict = dataset_dict (ds);
int v, i;
{
const struct dictionary *dict = dataset_dict (ds);
int v, i;
@@
-343,7
+346,8
@@
chisquare_execute (const struct dataset *ds,
struct hsh_table *freq_hash = NULL;
struct casereader *reader =
casereader_create_filter_missing (casereader_clone (input),
struct hsh_table *freq_hash = NULL;
struct casereader *reader =
casereader_create_filter_missing (casereader_clone (input),
- &ost->vars[v], 1, exclude, NULL);
+ &ost->vars[v], 1, exclude,
+ NULL, NULL);
struct tab_table *freq_table =
create_variable_frequency_table(dict, reader, cst, v, &freq_hash);
struct tab_table *freq_table =
create_variable_frequency_table(dict, reader, cst, v, &freq_hash);
@@
-361,12
+365,17
@@
chisquare_execute (const struct dataset *ds,
xsq[v] = 0.0;
for ( i = 0 ; i < n_cells ; ++i )
{
xsq[v] = 0.0;
for ( i = 0 ; i < n_cells ; ++i )
{
+ struct string str;
double exp;
const union value *observed_value = ff[i]->value;
double exp;
const union value *observed_value = ff[i]->value;
+ ds_init_empty (&str);
+ var_append_value_name (ost->vars[v], observed_value, &str);
+
/* The key */
/* The key */
- tab_text (freq_table, 0, i + 1, TAB_LEFT,
- var_get_value_name (ost->vars[v], observed_value));
+ tab_text (freq_table, 0, i + 1, TAB_LEFT, ds_cstr (&str));
+ ds_destroy (&str);
+
/* The observed N */
tab_float (freq_table, 1, i + 1, TAB_NONE,
/* The observed N */
tab_float (freq_table, 1, i + 1, TAB_NONE,
@@
-408,7
+417,8
@@
chisquare_execute (const struct dataset *ds,
double total_obs = 0.0;
struct casereader *reader =
casereader_create_filter_missing (casereader_clone (input),
double total_obs = 0.0;
struct casereader *reader =
casereader_create_filter_missing (casereader_clone (input),
- &ost->vars[v], 1, exclude, NULL);
+ &ost->vars[v], 1, exclude,
+ NULL, NULL);
struct hsh_table *freq_hash =
create_freq_hash_with_range (dict, reader,
ost->vars[v], cst->lo, cst->hi);
struct hsh_table *freq_hash =
create_freq_hash_with_range (dict, reader,
ost->vars[v], cst->lo, cst->hi);
@@
-427,13
+437,17
@@
chisquare_execute (const struct dataset *ds,
xsq[v] = 0.0;
for ( i = 0 ; i < hsh_count (freq_hash) ; ++i )
{
xsq[v] = 0.0;
for ( i = 0 ; i < hsh_count (freq_hash) ; ++i )
{
+ struct string str;
double exp;
const union value *observed_value = ff[i]->value;
double exp;
const union value *observed_value = ff[i]->value;
+ ds_init_empty (&str);
+ var_append_value_name (ost->vars[v], observed_value, &str);
/* The key */
tab_text (freq_table, v * 4 + 1, i + 2 , TAB_LEFT,
/* The key */
tab_text (freq_table, v * 4 + 1, i + 2 , TAB_LEFT,
- var_get_value_name (ost->vars[v], observed_value));
+ ds_cstr (&str));
+ ds_destroy (&str);
/* The observed N */
tab_float (freq_table, v * 4 + 2, i + 2 , TAB_NONE,
/* The observed N */
tab_float (freq_table, v * 4 + 2, i + 2 , TAB_NONE,