From e976a0fa28771a625ba29b86cc5883838d0f1c70 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 26 Oct 2004 10:45:42 +0000 Subject: [PATCH] Amalgamated t-test.h and oneway.h into a single group_proc.h file --- po/en_GB.po | 100 ++++++++++++++++----------------- po/pspp.pot | 100 ++++++++++++++++----------------- src/Makefile.am | 7 ++- src/{t-test.h => group.c} | 54 ++++++++++++------ src/group.h | 19 +++++++ src/{oneway.h => group_proc.h} | 16 ++++-- src/levene.c | 50 +++-------------- src/oneway.q | 100 +++++++++++++++------------------ src/t-test.q | 40 ++++++------- src/val.h | 1 + src/var.h | 6 +- 11 files changed, 248 insertions(+), 245 deletions(-) rename src/{t-test.h => group.c} (51%) rename src/{oneway.h => group_proc.h} (82%) diff --git a/po/en_GB.po b/po/en_GB.po index 5fba9783..1dd1270c 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PSPP 0.3.1\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2004-10-24 14:03+0800\n" +"POT-Creation-Date: 2004-10-26 18:37+0800\n" "PO-Revision-Date: 2004-01-23 13:04+0800\n" "Last-Translator: John Darrington \n" "Language-Team: John Darrington \n" @@ -957,8 +957,8 @@ msgstr "" msgid "Only USE ALL is currently implemented." msgstr "" -#: src/descript.c:98 src/frequencies.q:96 src/oneway.q:367 src/t-test.q:636 -#: src/t-test.q:659 src/t-test.q:748 src/t-test.q:1063 +#: src/descript.c:98 src/frequencies.q:96 src/oneway.q:367 src/t-test.q:634 +#: src/t-test.q:657 src/t-test.q:746 src/t-test.q:1061 msgid "Mean" msgstr "" @@ -4047,7 +4047,7 @@ msgid "Total" msgstr "" #: src/crosstabs.q:784 src/frequencies.q:1386 src/oneway.q:366 -#: src/t-test.q:635 src/t-test.q:658 src/t-test.q:749 src/t-test.q:1263 +#: src/t-test.q:633 src/t-test.q:656 src/t-test.q:747 src/t-test.q:1261 msgid "N" msgstr "" @@ -4093,8 +4093,8 @@ msgstr "" msgid "Statistic" msgstr "" -#: src/crosstabs.q:1069 src/oneway.q:249 src/oneway.q:664 src/t-test.q:900 -#: src/t-test.q:1069 src/t-test.q:1161 +#: src/crosstabs.q:1069 src/oneway.q:249 src/oneway.q:674 src/t-test.q:898 +#: src/t-test.q:1067 src/t-test.q:1159 msgid "df" msgstr "" @@ -4131,11 +4131,11 @@ msgstr "" msgid " 95%% Confidence Interval" msgstr "" -#: src/crosstabs.q:1116 src/t-test.q:904 src/t-test.q:1066 src/t-test.q:1164 +#: src/crosstabs.q:1116 src/t-test.q:902 src/t-test.q:1064 src/t-test.q:1162 msgid "Lower" msgstr "" -#: src/crosstabs.q:1117 src/t-test.q:905 src/t-test.q:1067 src/t-test.q:1165 +#: src/crosstabs.q:1117 src/t-test.q:903 src/t-test.q:1065 src/t-test.q:1163 msgid "Upper" msgstr "" @@ -4482,7 +4482,7 @@ msgstr "" msgid "Coefficients for contrast %d do not total zero" msgstr "" -#: src/oneway.q:213 src/t-test.q:331 src/t-test.q:408 +#: src/oneway.q:213 src/t-test.q:329 src/t-test.q:406 #, c-format msgid "`%s' is not a variable name" msgstr "" @@ -4495,7 +4495,7 @@ msgstr "" msgid "Mean Square" msgstr "" -#: src/oneway.q:251 src/t-test.q:897 +#: src/oneway.q:251 src/t-test.q:895 msgid "F" msgstr "" @@ -4515,12 +4515,12 @@ msgstr "" msgid "ANOVA" msgstr "" -#: src/oneway.q:368 src/t-test.q:637 src/t-test.q:660 src/t-test.q:750 -#: src/t-test.q:1064 +#: src/oneway.q:368 src/t-test.q:635 src/t-test.q:658 src/t-test.q:748 +#: src/t-test.q:1062 msgid "Std. Deviation" msgstr "" -#: src/oneway.q:369 src/oneway.q:662 +#: src/oneway.q:369 src/oneway.q:672 msgid "Std. Error" msgstr "" @@ -4557,35 +4557,35 @@ msgstr "" msgid "Test of Homogeneity of Variances" msgstr "" -#: src/oneway.q:587 +#: src/oneway.q:597 msgid "Contrast Coefficients" msgstr "" -#: src/oneway.q:589 src/oneway.q:660 +#: src/oneway.q:599 src/oneway.q:670 msgid "Contrast" msgstr "" -#: src/oneway.q:658 +#: src/oneway.q:668 msgid "Contrast Tests" msgstr "" -#: src/oneway.q:661 +#: src/oneway.q:671 msgid "Value of Contrast" msgstr "" -#: src/oneway.q:663 src/t-test.q:899 src/t-test.q:1068 src/t-test.q:1160 +#: src/oneway.q:673 src/t-test.q:897 src/t-test.q:1066 src/t-test.q:1158 msgid "t" msgstr "" -#: src/oneway.q:665 src/t-test.q:901 src/t-test.q:1070 src/t-test.q:1162 +#: src/oneway.q:675 src/t-test.q:899 src/t-test.q:1068 src/t-test.q:1160 msgid "Sig. (2-tailed)" msgstr "" -#: src/oneway.q:697 +#: src/oneway.q:723 msgid "Assume equal variances" msgstr "" -#: src/oneway.q:701 +#: src/oneway.q:727 msgid "Does not assume equal" msgstr "" @@ -4721,128 +4721,128 @@ msgstr "" msgid "data> " msgstr "" -#: src/t-test.q:235 +#: src/t-test.q:233 msgid "TESTVAL, GROUPS and PAIRS subcommands are mutually exclusive." msgstr "" -#: src/t-test.q:252 +#: src/t-test.q:250 msgid "VARIABLES subcommand is not appropriate with PAIRS" msgstr "" -#: src/t-test.q:289 +#: src/t-test.q:287 msgid "One or more VARIABLES must be specified." msgstr "" -#: src/t-test.q:344 +#: src/t-test.q:342 #, c-format msgid "Long string variable %s is not valid here." msgstr "" -#: src/t-test.q:361 +#: src/t-test.q:359 msgid "" "When applying GROUPS to a string variable, at least one value must be " "specified." msgstr "" -#: src/t-test.q:443 +#: src/t-test.q:441 #, c-format msgid "" "PAIRED was specified but the number of variables preceding WITH (%d) did not " "match the number following (%d)." msgstr "" -#: src/t-test.q:460 +#: src/t-test.q:458 msgid "At least two variables must be specified on PAIRS." msgstr "" -#: src/t-test.q:633 +#: src/t-test.q:631 msgid "One-Sample Statistics" msgstr "" -#: src/t-test.q:638 src/t-test.q:661 src/t-test.q:751 +#: src/t-test.q:636 src/t-test.q:659 src/t-test.q:749 msgid "SE. Mean" msgstr "" -#: src/t-test.q:655 +#: src/t-test.q:653 msgid "Group Statistics" msgstr "" -#: src/t-test.q:745 +#: src/t-test.q:743 msgid "Paired Sample Statistics" msgstr "" -#: src/t-test.q:767 src/t-test.q:1089 src/t-test.q:1280 +#: src/t-test.q:765 src/t-test.q:1087 src/t-test.q:1278 #, c-format msgid "Pair %d" msgstr "" -#: src/t-test.q:885 +#: src/t-test.q:883 msgid "Independent Samples Test" msgstr "" -#: src/t-test.q:893 +#: src/t-test.q:891 msgid "Levene's Test for Equality of Variances" msgstr "" -#: src/t-test.q:895 +#: src/t-test.q:893 msgid "t-test for Equality of Means" msgstr "" -#: src/t-test.q:898 src/t-test.q:1265 +#: src/t-test.q:896 src/t-test.q:1263 msgid "Sig." msgstr "" -#: src/t-test.q:902 src/t-test.q:1163 +#: src/t-test.q:900 src/t-test.q:1161 msgid "Mean Difference" msgstr "" -#: src/t-test.q:903 +#: src/t-test.q:901 msgid "Std. Error Difference" msgstr "" -#: src/t-test.q:908 src/t-test.q:1060 src/t-test.q:1155 +#: src/t-test.q:906 src/t-test.q:1058 src/t-test.q:1153 #, c-format msgid "%g%% Confidence Interval of the Difference" msgstr "" -#: src/t-test.q:939 +#: src/t-test.q:937 msgid "Equal variances assumed" msgstr "" -#: src/t-test.q:992 +#: src/t-test.q:990 msgid "Equal variances not assumed" msgstr "" -#: src/t-test.q:1050 +#: src/t-test.q:1048 msgid "Paired Samples Test" msgstr "" -#: src/t-test.q:1053 +#: src/t-test.q:1051 msgid "Paired Differences" msgstr "" -#: src/t-test.q:1065 +#: src/t-test.q:1063 msgid "Std. Error Mean" msgstr "" -#: src/t-test.q:1144 +#: src/t-test.q:1142 msgid "One-Sample Test" msgstr "" -#: src/t-test.q:1149 +#: src/t-test.q:1147 #, c-format msgid "Test Value = %f" msgstr "" -#: src/t-test.q:1260 +#: src/t-test.q:1258 msgid "Paired Samples Correlations" msgstr "" -#: src/t-test.q:1264 +#: src/t-test.q:1262 msgid "Correlation" msgstr "" -#: src/t-test.q:1283 +#: src/t-test.q:1281 #, c-format msgid "%s & %s" msgstr "" diff --git a/po/pspp.pot b/po/pspp.pot index 5fdca9b9..86af7879 100644 --- a/po/pspp.pot +++ b/po/pspp.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: pspp-dev@gnu.org\n" -"POT-Creation-Date: 2004-10-24 14:03+0800\n" +"POT-Creation-Date: 2004-10-26 18:37+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -958,8 +958,8 @@ msgstr "" msgid "Only USE ALL is currently implemented." msgstr "" -#: src/descript.c:98 src/frequencies.q:96 src/oneway.q:367 src/t-test.q:636 -#: src/t-test.q:659 src/t-test.q:748 src/t-test.q:1063 +#: src/descript.c:98 src/frequencies.q:96 src/oneway.q:367 src/t-test.q:634 +#: src/t-test.q:657 src/t-test.q:746 src/t-test.q:1061 msgid "Mean" msgstr "" @@ -4047,7 +4047,7 @@ msgid "Total" msgstr "" #: src/crosstabs.q:784 src/frequencies.q:1386 src/oneway.q:366 -#: src/t-test.q:635 src/t-test.q:658 src/t-test.q:749 src/t-test.q:1263 +#: src/t-test.q:633 src/t-test.q:656 src/t-test.q:747 src/t-test.q:1261 msgid "N" msgstr "" @@ -4093,8 +4093,8 @@ msgstr "" msgid "Statistic" msgstr "" -#: src/crosstabs.q:1069 src/oneway.q:249 src/oneway.q:664 src/t-test.q:900 -#: src/t-test.q:1069 src/t-test.q:1161 +#: src/crosstabs.q:1069 src/oneway.q:249 src/oneway.q:674 src/t-test.q:898 +#: src/t-test.q:1067 src/t-test.q:1159 msgid "df" msgstr "" @@ -4131,11 +4131,11 @@ msgstr "" msgid " 95%% Confidence Interval" msgstr "" -#: src/crosstabs.q:1116 src/t-test.q:904 src/t-test.q:1066 src/t-test.q:1164 +#: src/crosstabs.q:1116 src/t-test.q:902 src/t-test.q:1064 src/t-test.q:1162 msgid "Lower" msgstr "" -#: src/crosstabs.q:1117 src/t-test.q:905 src/t-test.q:1067 src/t-test.q:1165 +#: src/crosstabs.q:1117 src/t-test.q:903 src/t-test.q:1065 src/t-test.q:1163 msgid "Upper" msgstr "" @@ -4481,7 +4481,7 @@ msgstr "" msgid "Coefficients for contrast %d do not total zero" msgstr "" -#: src/oneway.q:213 src/t-test.q:331 src/t-test.q:408 +#: src/oneway.q:213 src/t-test.q:329 src/t-test.q:406 #, c-format msgid "`%s' is not a variable name" msgstr "" @@ -4494,7 +4494,7 @@ msgstr "" msgid "Mean Square" msgstr "" -#: src/oneway.q:251 src/t-test.q:897 +#: src/oneway.q:251 src/t-test.q:895 msgid "F" msgstr "" @@ -4514,12 +4514,12 @@ msgstr "" msgid "ANOVA" msgstr "" -#: src/oneway.q:368 src/t-test.q:637 src/t-test.q:660 src/t-test.q:750 -#: src/t-test.q:1064 +#: src/oneway.q:368 src/t-test.q:635 src/t-test.q:658 src/t-test.q:748 +#: src/t-test.q:1062 msgid "Std. Deviation" msgstr "" -#: src/oneway.q:369 src/oneway.q:662 +#: src/oneway.q:369 src/oneway.q:672 msgid "Std. Error" msgstr "" @@ -4556,35 +4556,35 @@ msgstr "" msgid "Test of Homogeneity of Variances" msgstr "" -#: src/oneway.q:587 +#: src/oneway.q:597 msgid "Contrast Coefficients" msgstr "" -#: src/oneway.q:589 src/oneway.q:660 +#: src/oneway.q:599 src/oneway.q:670 msgid "Contrast" msgstr "" -#: src/oneway.q:658 +#: src/oneway.q:668 msgid "Contrast Tests" msgstr "" -#: src/oneway.q:661 +#: src/oneway.q:671 msgid "Value of Contrast" msgstr "" -#: src/oneway.q:663 src/t-test.q:899 src/t-test.q:1068 src/t-test.q:1160 +#: src/oneway.q:673 src/t-test.q:897 src/t-test.q:1066 src/t-test.q:1158 msgid "t" msgstr "" -#: src/oneway.q:665 src/t-test.q:901 src/t-test.q:1070 src/t-test.q:1162 +#: src/oneway.q:675 src/t-test.q:899 src/t-test.q:1068 src/t-test.q:1160 msgid "Sig. (2-tailed)" msgstr "" -#: src/oneway.q:697 +#: src/oneway.q:723 msgid "Assume equal variances" msgstr "" -#: src/oneway.q:701 +#: src/oneway.q:727 msgid "Does not assume equal" msgstr "" @@ -4720,128 +4720,128 @@ msgstr "" msgid "data> " msgstr "" -#: src/t-test.q:235 +#: src/t-test.q:233 msgid "TESTVAL, GROUPS and PAIRS subcommands are mutually exclusive." msgstr "" -#: src/t-test.q:252 +#: src/t-test.q:250 msgid "VARIABLES subcommand is not appropriate with PAIRS" msgstr "" -#: src/t-test.q:289 +#: src/t-test.q:287 msgid "One or more VARIABLES must be specified." msgstr "" -#: src/t-test.q:344 +#: src/t-test.q:342 #, c-format msgid "Long string variable %s is not valid here." msgstr "" -#: src/t-test.q:361 +#: src/t-test.q:359 msgid "" "When applying GROUPS to a string variable, at least one value must be " "specified." msgstr "" -#: src/t-test.q:443 +#: src/t-test.q:441 #, c-format msgid "" "PAIRED was specified but the number of variables preceding WITH (%d) did not " "match the number following (%d)." msgstr "" -#: src/t-test.q:460 +#: src/t-test.q:458 msgid "At least two variables must be specified on PAIRS." msgstr "" -#: src/t-test.q:633 +#: src/t-test.q:631 msgid "One-Sample Statistics" msgstr "" -#: src/t-test.q:638 src/t-test.q:661 src/t-test.q:751 +#: src/t-test.q:636 src/t-test.q:659 src/t-test.q:749 msgid "SE. Mean" msgstr "" -#: src/t-test.q:655 +#: src/t-test.q:653 msgid "Group Statistics" msgstr "" -#: src/t-test.q:745 +#: src/t-test.q:743 msgid "Paired Sample Statistics" msgstr "" -#: src/t-test.q:767 src/t-test.q:1089 src/t-test.q:1280 +#: src/t-test.q:765 src/t-test.q:1087 src/t-test.q:1278 #, c-format msgid "Pair %d" msgstr "" -#: src/t-test.q:885 +#: src/t-test.q:883 msgid "Independent Samples Test" msgstr "" -#: src/t-test.q:893 +#: src/t-test.q:891 msgid "Levene's Test for Equality of Variances" msgstr "" -#: src/t-test.q:895 +#: src/t-test.q:893 msgid "t-test for Equality of Means" msgstr "" -#: src/t-test.q:898 src/t-test.q:1265 +#: src/t-test.q:896 src/t-test.q:1263 msgid "Sig." msgstr "" -#: src/t-test.q:902 src/t-test.q:1163 +#: src/t-test.q:900 src/t-test.q:1161 msgid "Mean Difference" msgstr "" -#: src/t-test.q:903 +#: src/t-test.q:901 msgid "Std. Error Difference" msgstr "" -#: src/t-test.q:908 src/t-test.q:1060 src/t-test.q:1155 +#: src/t-test.q:906 src/t-test.q:1058 src/t-test.q:1153 #, c-format msgid "%g%% Confidence Interval of the Difference" msgstr "" -#: src/t-test.q:939 +#: src/t-test.q:937 msgid "Equal variances assumed" msgstr "" -#: src/t-test.q:992 +#: src/t-test.q:990 msgid "Equal variances not assumed" msgstr "" -#: src/t-test.q:1050 +#: src/t-test.q:1048 msgid "Paired Samples Test" msgstr "" -#: src/t-test.q:1053 +#: src/t-test.q:1051 msgid "Paired Differences" msgstr "" -#: src/t-test.q:1065 +#: src/t-test.q:1063 msgid "Std. Error Mean" msgstr "" -#: src/t-test.q:1144 +#: src/t-test.q:1142 msgid "One-Sample Test" msgstr "" -#: src/t-test.q:1149 +#: src/t-test.q:1147 #, c-format msgid "Test Value = %f" msgstr "" -#: src/t-test.q:1260 +#: src/t-test.q:1258 msgid "Paired Samples Correlations" msgstr "" -#: src/t-test.q:1264 +#: src/t-test.q:1262 msgid "Correlation" msgstr "" -#: src/t-test.q:1283 +#: src/t-test.q:1281 #, c-format msgid "%s & %s" msgstr "" diff --git a/src/Makefile.am b/src/Makefile.am index e6ce5839..c4ad149a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -59,16 +59,17 @@ error.h expr-evl.c expr-opt.c expr-prs.c expr.h exprP.h expr.def \ file-handle.h \ file-type.c filename.c filename.h flip.c font.h format.c format.def \ format.h formats.c get.c getline.c getline.h glob.c glob.h \ -groff-font.c hash.c hash.h html.c htmlP.h include.c inpt-pgm.c lexer.c \ +groff-font.c group.c group.h group_proc.h \ +hash.c hash.h html.c htmlP.h include.c inpt-pgm.c lexer.c \ lexer.h levene.c levene.h log.h loop.c magic.c magic.h main.c main.h \ matrix-data.c mis-val.c misc.c misc.h modify-vars.c \ moments.c moments.h numeric.c output.c output.h pfm-read.c pfm-write.c \ pfm.h pool.c pool.h postscript.c print.c random.c random.h recode.c \ rename-vars.c repeat.c repeat.h sample.c sel-if.c settings.h \ sfm-read.c sfm-write.c sfm.h sfmP.h som.c som.h sort.c sort.h \ -split-file.c str.c str.h subclist.c \ +split-file.c str.c str.h subclist.c subclist.h \ sysfile-info.c tab.c tab.h temporary.c stat.h \ -title.c t-test.h val.h val-labs.c value-labels.c value-labels.h \ +title.c val.h val-labs.c value-labels.c value-labels.h \ var-labs.c var.h vars-atr.c vars-prs.c vector.c version.c version.h \ vfm.c vfm.h vfmP.h weight.c diff --git a/src/t-test.h b/src/group.c similarity index 51% rename from src/t-test.h rename to src/group.c index abae67e0..fb86295b 100644 --- a/src/t-test.h +++ b/src/group.c @@ -1,5 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. Written by John Darrington This program is free software; you can redistribute it and/or @@ -17,27 +17,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef T_TEST_H -#define T_TEST_H +#include "hash.h" +#include "group.h" +#include -#include "val.h" -#include "group.h" +/* Return -1 if the id of a is less than b; +1 if greater than and + 0 if equal */ +int +compare_group(const struct group_statistics *a, + const struct group_statistics *b, + int width) +{ + int id_cmp = compare_values(&a->id, &b->id, width); -/* T-TEST private data */ -struct t_test_proc + if (id_cmp == 0 ) + { + int c; + c= memcmp(&a->criterion,&b->criterion,sizeof(enum comparison)); + return c; + } + else + return id_cmp; +} + + +unsigned +hash_group(const struct group_statistics *g, int width) { - /* Stats for the `universal group' */ - struct group_statistics ugs; + unsigned id_hash; - /* Number of groups */ - int n_groups ; + if ( 0 == width ) + id_hash = hsh_hash_double (g->id.f); + else + id_hash = hsh_hash_bytes (g->id.s, width); - /* Stats for individual groups */ - struct group_statistics *gs; + return id_hash; +} - /* The levene statistic */ - double levene ; -}; -#endif +void +free_group(struct group_statistics *v, void *aux) +{ + free(v); +} diff --git a/src/group.h b/src/group.h index 951e58ed..a195f06a 100644 --- a/src/group.h +++ b/src/group.h @@ -17,9 +17,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + + #ifndef GROUP_H #define GROUP_H + #include "val.h" @@ -85,4 +88,20 @@ struct group_statistics }; + + +/* These funcs are usefull for hash tables */ + +/* Return -1 if the id of a is less than b; +1 if greater than and + 0 if equal */ +int compare_group(const struct group_statistics *a, + const struct group_statistics *b, + int width); + +unsigned hash_group(const struct group_statistics *g, int width); + +void free_group(struct group_statistics *v, void *aux); + + + #endif diff --git a/src/oneway.h b/src/group_proc.h similarity index 82% rename from src/oneway.h rename to src/group_proc.h index 491efaa9..7caf95e8 100644 --- a/src/oneway.h +++ b/src/group_proc.h @@ -19,11 +19,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef ONEWAY_H -#define ONEWAY_H +#ifndef GROUP_DATA_H +#define GROUP_DATA_H -/* ONEWAY private data */ -struct oneway_proc +#include "group.h" + +/* private data for commands dealing with grouped data*/ +struct group_proc { /* Stats for the `universal group' (ie the totals) */ struct group_statistics ugs; @@ -31,6 +33,12 @@ struct oneway_proc /* The number of groups */ int n_groups; + /* The levene statistic */ + double levene ; + + /* Stats for individual groups */ + struct group_statistics *gs; + /* A hash of group statistics keyed by the value of the independent variable */ struct hsh_table *group_hash; diff --git a/src/levene.c b/src/levene.c index 06f55f4e..67d8c374 100644 --- a/src/levene.c +++ b/src/levene.c @@ -30,7 +30,7 @@ #include "vfm.h" #include "alloc.h" #include "misc.h" - +#include "group.h" #include #include @@ -134,40 +134,6 @@ levene(const struct casefile *cf, static struct hsh_table **hash; - -/* Return -1 if the id of a is less than b; +1 if greater than and - 0 if equal */ -static int -compare_group(const struct group_statistics *a, - const struct group_statistics *b, - int width) -{ - int id_cmp = compare_values(&a->id, &b->id, width); - - if (id_cmp == 0 ) - { - int c; - c= memcmp(&a->criterion,&b->criterion,sizeof(enum comparison)); - return c; - } - else - return id_cmp; -} - - -static unsigned -hash_group(const struct group_statistics *g, int width) -{ - unsigned id_hash; - - if ( 0 == width ) - id_hash = hsh_hash_double (g->id.f); - else - id_hash = hsh_hash_bytes (g->id.s, width); - - return id_hash; -} - /* Internal variables used in calculating the Levene statistic */ /* Per variable statistics */ @@ -206,7 +172,7 @@ levene_precalc (const struct levene_info *l) { struct variable *v = l->v_dep[i]; int g; - int number_of_groups = v->p.t_t.n_groups ; + int number_of_groups = v->p.grp_data.n_groups ; hash[i] = hsh_create (l->n_dep * number_of_groups, (hsh_compare_func *) compare_group, @@ -217,9 +183,9 @@ levene_precalc (const struct levene_info *l) lz[i].total_n = 0; lz[i].n_groups = number_of_groups; - for (g = 0 ; g < v->p.t_t.n_groups ; ++g ) + for (g = 0 ; g < v->p.grp_data.n_groups ; ++g ) { - struct group_statistics *gs = &v->p.t_t.gs[g]; + struct group_statistics *gs = &v->p.grp_data.gs[g]; gs->lz_total = 0; hsh_insert(hash[i], gs); if ( gs->criterion != CMP_EQ ) @@ -400,12 +366,12 @@ levene2_postcalc (void *_l) } - lz_numerator *= ( l->v_dep[v]->p.t_t.ugs.n - - l->v_dep[v]->p.t_t.n_groups ); + lz_numerator *= ( l->v_dep[v]->p.grp_data.ugs.n - + l->v_dep[v]->p.grp_data.n_groups ); - lz_denominator[v] /= (l->v_dep[v]->p.t_t.n_groups - 1); + lz_denominator[v] /= (l->v_dep[v]->p.grp_data.n_groups - 1); - l->v_dep[v]->p.t_t.levene = lz_numerator/lz_denominator[v] ; + l->v_dep[v]->p.grp_data.levene = lz_numerator/lz_denominator[v] ; } /* Now clear up after ourselves */ diff --git a/src/oneway.q b/src/oneway.q index e05af541..dbbd79fb 100644 --- a/src/oneway.q +++ b/src/oneway.q @@ -39,7 +39,7 @@ #include "vfm.h" #include "hash.h" #include "casefile.h" -#include "oneway.h" +#include "group_proc.h" #include "group.h" #include "levene.h" @@ -166,7 +166,7 @@ cmd_oneway(void) /* Clean up */ for (i = 0 ; i < n_vars ; ++i ) { - struct hsh_table *group_hash = vars[i]->p.ww.group_hash; + struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash; hsh_destroy(group_hash); } @@ -254,8 +254,8 @@ show_anova_table(void) for ( i=0 ; i < n_vars ; ++i ) { - struct group_statistics *totals = &vars[i]->p.ww.ugs; - struct hsh_table *group_hash = vars[i]->p.ww.group_hash; + struct group_statistics *totals = &vars[i]->p.grp_data.ugs; + struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash; struct hsh_iterator g; struct group_statistics *gs; double ssa=0; @@ -283,11 +283,11 @@ show_anova_table(void) { const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ; - const double df1 = vars[i]->p.ww.n_groups - 1; - const double df2 = totals->n - vars[i]->p.ww.n_groups ; + const double df1 = vars[i]->p.grp_data.n_groups - 1; + const double df2 = totals->n - vars[i]->p.grp_data.n_groups ; const double msa = ssa / df1; - vars[i]->p.ww.mse = (sst - ssa) / df2; + vars[i]->p.grp_data.mse = (sst - ssa) / df2; /* Sums of Squares */ @@ -303,11 +303,11 @@ show_anova_table(void) /* Mean Squares */ tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3); - tab_float (t, 4, i * 3 + 2, TAB_RIGHT, vars[i]->p.ww.mse, 8, 3); + tab_float (t, 4, i * 3 + 2, TAB_RIGHT, vars[i]->p.grp_data.mse, 8, 3); { - const double F = msa/vars[i]->p.ww.mse ; + const double F = msa/vars[i]->p.grp_data.mse ; /* The F value */ tab_float (t, 5, i * 3 + 1, 0, F, 8, 3); @@ -345,7 +345,7 @@ show_descriptives(void) for ( v = 0 ; v < n_vars ; ++v ) - n_rows += vars[v]->p.ww.n_groups + 1; + n_rows += vars[v]->p.grp_data.n_groups + 1; t = tab_create (n_cols,n_rows,0); tab_headers (t, 2, 0, 2, 0); @@ -392,12 +392,12 @@ show_descriptives(void) struct hsh_iterator g; struct group_statistics *gs; - struct group_statistics *totals = &vars[v]->p.ww.ugs; + struct group_statistics *totals = &vars[v]->p.grp_data.ugs; int count = 0 ; char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name; - struct hsh_table *group_hash = vars[v]->p.ww.group_hash; + struct hsh_table *group_hash = vars[v]->p.grp_data.group_hash; tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s); @@ -480,7 +480,7 @@ show_descriptives(void) tab_float(t, 8, row + count, 0, totals->minimum, 8, 2); tab_float(t, 9, row + count, 0, totals->maximum, 8, 2); - row += vars[v]->p.ww.n_groups + 1; + row += vars[v]->p.grp_data.n_groups + 1; } @@ -527,8 +527,18 @@ show_homogeneity(void) for ( v=0 ; v < n_vars ; ++v ) { char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name; + struct group_statistics *totals = &vars[v]->p.grp_data.ugs; + + const double df1 = vars[v]->p.grp_data.n_groups - 1; + const double df2 = totals->n - vars[v]->p.grp_data.n_groups ; + tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s); + + + + tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0); + tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0); } tab_submit (t); @@ -680,8 +690,8 @@ show_contrast_tests(void) int ci; double contrast_value = 0.0; double coef_msq = 0.0; - struct oneway_proc *ww = &vars[v]->p.ww ; - struct hsh_table *group_hash = ww->group_hash; + struct group_proc *grp_data = &vars[v]->p.grp_data ; + struct hsh_table *group_hash = grp_data->group_hash; struct hsh_iterator g; struct group_statistics *gs; @@ -758,7 +768,7 @@ show_contrast_tests(void) TAB_RIGHT, contrast_value, 8,2); - std_error_contrast = sqrt(vars[v]->p.ww.mse * coef_msq); + std_error_contrast = sqrt(vars[v]->p.grp_data.mse * coef_msq); /* Std. Error */ tab_float (t, 4, (v * lines_per_variable) + i + 1, @@ -773,7 +783,7 @@ show_contrast_tests(void) TAB_RIGHT, T, 8,3); - df = ww->ugs.n - ww->n_groups; + df = grp_data->ugs.n - grp_data->n_groups; /* Degrees of Freedom */ tab_float (t, 6, (v * lines_per_variable) + i + 1, @@ -834,34 +844,6 @@ static void postcalc ( struct cmd_oneway *cmd UNUSED ); static void precalc ( struct cmd_oneway *cmd UNUSED ); -int compare_group_id (const struct group_statistics *a, - const struct group_statistics *b, int width); - -unsigned int hash_group_id(const struct group_statistics *v, int width); - -void free_group_id(struct group_statistics *v, void *aux UNUSED); - - - - -int -compare_group_id (const struct group_statistics *a, - const struct group_statistics *b, int width) -{ - return compare_values(&a->id, &b->id, width); -} - -unsigned int -hash_group_id(const struct group_statistics *v, int width) -{ - return hash_value ( &v->id, width); -} - -void -free_group_id(struct group_statistics *v, void *aux UNUSED) -{ - free(v); -} /* Pre calculations */ @@ -872,20 +854,21 @@ precalc ( struct cmd_oneway *cmd UNUSED ) for(i=0; i< n_vars ; ++i) { - struct group_statistics *totals = &vars[i]->p.ww.ugs; + struct group_statistics *totals = &vars[i]->p.grp_data.ugs; /* Create a hash for each of the dependent variables. The hash contains a group_statistics structure, and is keyed by value of the independent variable */ - vars[i]->p.ww.group_hash = + vars[i]->p.grp_data.group_hash = hsh_create(4, - (hsh_compare_func *) compare_group_id, - (hsh_hash_func *) hash_group_id, - (hsh_free_func *) free_group_id, + (hsh_compare_func *) compare_group, + (hsh_hash_func *) hash_group, + (hsh_free_func *) free_group, (void *) indep_var->width ); + totals->criterion = CMP_EQ; totals->sum=0; totals->n=0; totals->ssq=0; @@ -913,6 +896,8 @@ calculate(const struct casefile *cf, void *cmd_) precalc(cmd); + + for(r = casefile_get_reader (cf); casereader_read (r, &c) ; case_destroy (&c)) @@ -933,7 +918,7 @@ calculate(const struct casefile *cf, void *cmd_) const union value *val = case_data (&c, v->fv); - struct hsh_table *group_hash = vars[i]->p.ww.group_hash; + struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash; struct group_statistics *gs; @@ -944,6 +929,7 @@ calculate(const struct casefile *cf, void *cmd_) gs = (struct group_statistics *) xmalloc (sizeof(struct group_statistics)); + gs->criterion = CMP_EQ; gs->id = *indep_val; gs->sum=0; gs->n=0; @@ -957,7 +943,7 @@ calculate(const struct casefile *cf, void *cmd_) if (! value_is_missing(val,v) ) { - struct group_statistics *totals = &vars[i]->p.ww.ugs; + struct group_statistics *totals = &vars[i]->p.grp_data.ugs; totals->n+=weight; totals->sum+=weight * val->f; @@ -980,7 +966,7 @@ calculate(const struct casefile *cf, void *cmd_) gs->maximum = val->f * weight; } - vars[i]->p.ww.n_groups = hsh_count ( group_hash ); + vars[i]->p.grp_data.n_groups = hsh_count ( group_hash ); } } @@ -988,6 +974,10 @@ calculate(const struct casefile *cf, void *cmd_) postcalc(cmd); + /* + levene(cf, indep_var, n_vars, vars, LEV_LISTWISE, value_is_missing); + */ + ostensible_number_of_groups = hsh_count (global_group_hash); } @@ -1002,8 +992,8 @@ postcalc ( struct cmd_oneway *cmd UNUSED ) for(i = 0; i < n_vars ; ++i) { - struct hsh_table *group_hash = vars[i]->p.ww.group_hash; - struct group_statistics *totals = &vars[i]->p.ww.ugs; + struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash; + struct group_statistics *totals = &vars[i]->p.grp_data.ugs; struct hsh_iterator g; struct group_statistics *gs; diff --git a/src/t-test.q b/src/t-test.q index f2759c6e..2993ac91 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -39,7 +39,7 @@ #include "var.h" #include "vfm.h" #include "hash.h" -#include "t-test.h" +#include "group_proc.h" #include "casefile.h" #include "levene.h" @@ -309,7 +309,7 @@ cmd_t_test(void) /* Destroy any group statistics we created */ for (i= 0 ; i < cmd.n_variables ; ++i ) { - free(cmd.v_variables[i]->p.t_t.gs); + free(cmd.v_variables[i]->p.grp_data.gs); } } @@ -715,7 +715,7 @@ ssbox_independent_samples_populate(struct ssbox *ssb, /* Fill in the group statistics */ for ( g=0; g < 2 ; ++g ) { - struct group_statistics *gs = &cmd->v_variables[i]->p.t_t.gs[g]; + struct group_statistics *gs = &cmd->v_variables[i]->p.grp_data.gs[g]; tab_float(ssb->t, 2 ,i*2+g+1, TAB_RIGHT, gs->n, 2, 0); tab_float(ssb->t, 3 ,i*2+g+1, TAB_RIGHT, gs->mean, 8, 2); @@ -768,7 +768,7 @@ ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED) { struct group_statistics *gs; - gs=&pairs[i].v[j]->p.t_t.ugs; + gs=&pairs[i].v[j]->p.grp_data.ugs; /* Titles */ @@ -795,7 +795,7 @@ ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd) for (i=0; i < cmd->n_variables; ++i) { struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name); tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0); @@ -929,8 +929,8 @@ trbox_independent_samples_populate(struct trbox *self, double std_err_diff; double mean_diff; - struct group_statistics *gs0 = &cmd->v_variables[i]->p.t_t.gs[0]; - struct group_statistics *gs1 = &cmd->v_variables[i]->p.t_t.gs[1]; + struct group_statistics *gs0 = &cmd->v_variables[i]->p.grp_data.gs[0]; + struct group_statistics *gs1 = &cmd->v_variables[i]->p.grp_data.gs[1]; tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name); @@ -938,11 +938,11 @@ trbox_independent_samples_populate(struct trbox *self, tab_float(self->t, 2, i*2+3, TAB_CENTER, - cmd->v_variables[i]->p.t_t.levene, 8,3); + cmd->v_variables[i]->p.grp_data.levene, 8,3); /* Now work out the significance of the Levene test */ - df1 = 1; df2 = cmd->v_variables[i]->p.t_t.ugs.n - 2; - q = gsl_cdf_fdist_Q(cmd->v_variables[i]->p.t_t.levene, df1, df2); + df1 = 1; df2 = cmd->v_variables[i]->p.grp_data.ugs.n - 2; + q = gsl_cdf_fdist_Q(cmd->v_variables[i]->p.grp_data.levene, df1, df2); tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 ); @@ -1179,7 +1179,7 @@ trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd) double p,q; double df; struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name); @@ -1340,7 +1340,7 @@ common_calc (const struct ccase *c, void *_cmd) struct variable *v = cmd->v_variables[i]; const union value *val = case_data (c, v->fv); - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; if (! value_is_missing(val,v) ) { @@ -1361,7 +1361,7 @@ common_precalc ( struct cmd_t_test *cmd ) for(i=0; i< cmd->n_variables ; ++i) { struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; gs->sum=0; gs->n=0; @@ -1380,7 +1380,7 @@ common_postcalc ( struct cmd_t_test *cmd ) for(i=0; i< cmd->n_variables ; ++i) { struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; gs->mean=gs->sum / gs->n; gs->s_std_dev= sqrt( @@ -1428,7 +1428,7 @@ one_sample_calc (const struct ccase *c, void *cmd_) struct variable *v = cmd->v_variables[i]; const union value *val = case_data (c, v->fv); - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; if ( ! value_is_missing(val,v)) gs->sum_diff += weight * (val->f - cmd->n_testval); @@ -1446,7 +1446,7 @@ one_sample_precalc ( struct cmd_t_test *cmd ) for(i=0; i< cmd->n_variables ; ++i) { struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; gs->sum_diff=0; } @@ -1461,7 +1461,7 @@ one_sample_postcalc (struct cmd_t_test *cmd) for(i=0; i< cmd->n_variables ; ++i) { struct group_statistics *gs; - gs= &cmd->v_variables[i]->p.t_t.ugs; + gs= &cmd->v_variables[i]->p.grp_data.ugs; gs->mean_diff = gs->sum_diff / gs->n ; } @@ -1648,7 +1648,7 @@ group_precalc (struct cmd_t_test *cmd ) for(i=0; i< cmd->n_variables ; ++i) { - struct t_test_proc *ttpr = &cmd->v_variables[i]->p.t_t; + struct group_proc *ttpr = &cmd->v_variables[i]->p.grp_data; /* There's always 2 groups for a T - TEST */ ttpr->n_groups = 2; @@ -1714,7 +1714,7 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd) { struct variable *var = cmd->v_variables[i]; - struct group_statistics *gs = &var->p.t_t.gs[g]; + struct group_statistics *gs = &var->p.grp_data.gs[g]; const union value *val = case_data (c, var->fv); @@ -1741,7 +1741,7 @@ group_postcalc ( struct cmd_t_test *cmd ) for (j=0 ; j < 2 ; ++j) { struct group_statistics *gs; - gs=&cmd->v_variables[i]->p.t_t.gs[j]; + gs=&cmd->v_variables[i]->p.grp_data.gs[j]; gs->mean = gs->sum / gs->n; diff --git a/src/val.h b/src/val.h index fc098fda..c90cd198 100644 --- a/src/val.h +++ b/src/val.h @@ -21,6 +21,7 @@ #define val_h 1 #include +#include "config.h" /* Values. */ diff --git a/src/var.h b/src/var.h index cade9d3e..0e15598a 100644 --- a/src/var.h +++ b/src/var.h @@ -22,8 +22,7 @@ #include #include "format.h" -#include "t-test.h" -#include "oneway.h" +#include "group_proc.h" #include "val.h" /* Frequency tables. */ @@ -220,8 +219,7 @@ struct variable struct means_proc mns; struct matrix_data_proc mxd; struct match_files_proc mtf; - struct t_test_proc t_t; - struct oneway_proc ww; + struct group_proc grp_data; } p; }; -- 2.30.2