X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flanguage%2Fstats%2Foneway.q;h=46cdd56649773d6b5166d79aa358bcc77f609eca;hb=08590721e2938b1a7db320bfac2d4f1f86afa717;hp=e09e8b84559bd382d94288e9083bcfc52ffc09ea;hpb=f5c108becd49d78f4898cab11352291f5689d24e;p=pspp-builds.git diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index e09e8b84..46cdd566 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -1,21 +1,18 @@ -/* PSPP - One way ANOVA. -*-c-*- +/* PSPP - a program for statistical analysis. + Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc. -Copyright (C) 1997-9, 2000, 2007 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -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 the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA -02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include @@ -34,10 +31,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include #include -#include #include #include -#include #include #include #include @@ -49,6 +44,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA #include #include "sort-criteria.h" +#include "xalloc.h" + #include "gettext.h" #define _(msgid) gettext (msgid) @@ -178,8 +175,7 @@ output_oneway(void) sum += subc_list_double_at(&cmd.dl_contrast[i],j); if ( sum != 0.0 ) - msg(SW,_("Coefficients for contrast %d do not total zero"), - (int) i + 1); + msg(SW,_("Coefficients for contrast %zu do not total zero"), i + 1); } if ( stat_tables & STAT_DESC ) @@ -292,17 +288,17 @@ show_anova_table(void) struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash; struct hsh_iterator g; struct group_statistics *gs; - double ssa=0; + double ssa = 0; const char *s = var_to_string(vars[i]); for (gs = hsh_first (group_hash,&g); gs != 0; gs = hsh_next(group_hash,&g)) { - ssa += (gs->sum * gs->sum)/gs->n; + ssa += pow2 (gs->sum) / gs->n; } - ssa -= ( totals->sum * totals->sum ) / totals->n ; + ssa -= pow2 (totals->sum) / totals->n; tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s); tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups")); @@ -314,7 +310,7 @@ show_anova_table(void) { struct group_proc *gp = group_proc_get (vars[i]); - const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ; + const double sst = totals->ssq - pow2 (totals->sum) / totals->n ; const double df1 = gp->n_groups - 1; const double df2 = totals->n - gp->n_groups ; const double msa = ssa / df1; @@ -337,7 +333,6 @@ show_anova_table(void) tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3); tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3); - { const double F = msa/gp->mse ; @@ -347,9 +342,7 @@ show_anova_table(void) /* The significance */ tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3); } - } - } @@ -435,27 +428,33 @@ show_descriptives(void) for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count) { + struct string vstr; + ds_init_empty (&vstr); gs = gs_array[count]; + var_append_value_name (indep_var, &gs->id, &vstr); + tab_text (t, 1, row + count, - TAB_LEFT | TAT_TITLE, var_get_value_name(indep_var, - &gs->id)); + TAB_LEFT | TAT_TITLE, + ds_cstr (&vstr)); + + ds_destroy (&vstr); /* Now fill in the numbers ... */ tab_float (t, 2, row + count, 0, gs->n, 8,0); - tab_float (t, 3, row + count, 0, gs->mean,8,2); + tab_float (t, 3, row + count, 0, gs->mean, 8, 2); - tab_float (t, 4, row + count, 0, gs->std_dev,8,2); + tab_float (t, 4, row + count, 0, gs->std_dev, 8, 2); std_error = gs->std_dev/sqrt(gs->n) ; tab_float (t, 5, row + count, 0, - std_error, 8,2); + std_error, 8, 2); /* Now the confidence interval */ - T = gsl_cdf_tdist_Qinv(q,gs->n - 1); + T = gsl_cdf_tdist_Qinv(q, gs->n - 1); tab_float(t, 6, row + count, 0, gs->mean - T * std_error, 8, 2); @@ -622,10 +621,18 @@ show_contrast_coeffs (short *bad_contrast) ++count) { int i; + struct string vstr; group_value = group_values[count]; + ds_init_empty (&vstr); + + var_append_value_name (indep_var, group_value, &vstr); + tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE, - var_get_value_name (indep_var, group_value)); + ds_cstr (&vstr)); + + ds_destroy (&vstr); + for (i = 0 ; i < cmd.sbc_contrast ; ++i ) { @@ -751,13 +758,13 @@ show_contrast_tests(short *bad_contrast) const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci); struct group_statistics *gs = group_stat_array[ci]; - const double winv = (gs->std_dev * gs->std_dev) / gs->n; + const double winv = pow2 (gs->std_dev) / gs->n; contrast_value += coef * gs->mean; coef_msq += (coef * coef) / gs->n ; - sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ; + sec_vneq += (coef * coef) * pow2 (gs->std_dev) /gs->n ; df_numerator += (coef * coef) * winv; df_denominator += pow2((coef * coef) * winv) / (gs->n - 1); @@ -773,7 +780,7 @@ show_contrast_tests(short *bad_contrast) cmd.sbc_contrast, TAB_RIGHT, contrast_value, 8,2); - std_error_contrast = sqrt(grp_data->mse * coef_msq); + std_error_contrast = sqrt (grp_data->mse * coef_msq); /* Std. Error */ tab_float (t, 4, (v * lines_per_variable) + i + 1, @@ -902,7 +909,10 @@ run_oneway (struct cmd_oneway *cmd, struct ccase c; if (!casereader_peek (input, 0, &c)) - return; + { + casereader_destroy (input); + return; + } output_split_file_values (ds, &c); case_destroy (&c); @@ -918,10 +928,10 @@ run_oneway (struct cmd_oneway *cmd, exclude = cmd->incl != ONEWAY_INCLUDE ? MV_ANY : MV_SYSTEM; input = casereader_create_filter_missing (input, &indep_var, 1, - exclude, NULL); + exclude, NULL, NULL); if (cmd->miss == ONEWAY_LISTWISE) input = casereader_create_filter_missing (input, vars, n_vars, - exclude, NULL); + exclude, NULL, NULL); input = casereader_create_filter_weight (input, dict, NULL, NULL); reader = casereader_clone (input); @@ -967,9 +977,9 @@ run_oneway (struct cmd_oneway *cmd, { struct group_statistics *totals = &gp->ugs; - totals->n+=weight; - totals->sum+=weight * val->f; - totals->ssq+=weight * val->f * val->f; + totals->n += weight; + totals->sum += weight * val->f; + totals->ssq += weight * pow2 (val->f); if ( val->f * weight < totals->minimum ) totals->minimum = val->f * weight; @@ -977,9 +987,9 @@ run_oneway (struct cmd_oneway *cmd, if ( val->f * weight > totals->maximum ) totals->maximum = val->f * weight; - gs->n+=weight; - gs->sum+=weight * val->f; - gs->ssq+=weight * val->f * val->f; + gs->n += weight; + gs->sum += weight * val->f; + gs->ssq += weight * pow2 (val->f); if ( val->f * weight < gs->minimum ) gs->minimum = val->f * weight; @@ -1030,30 +1040,32 @@ postcalc ( struct cmd_oneway *cmd UNUSED ) gs != 0; gs = hsh_next(group_hash,&g)) { - gs->mean=gs->sum / gs->n; + gs->mean = gs->sum / gs->n; gs->s_std_dev= sqrt( - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + gs->ssq / gs->n - pow2 (gs->mean) ) ; gs->std_dev= sqrt( - gs->n/(gs->n-1) * - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + gs->n / (gs->n - 1) * + ( gs->ssq / gs->n - pow2 (gs->mean)) ) ; - gs->se_mean = gs->std_dev / sqrt(gs->n); - gs->mean_diff= gs->sum_diff / gs->n; - + gs->se_mean = gs->std_dev / sqrt (gs->n); + gs->mean_diff = gs->sum_diff / gs->n; } - - totals->mean = totals->sum / totals->n; totals->std_dev= sqrt( - totals->n/(totals->n-1) * - ( (totals->ssq / totals->n ) - totals->mean * totals->mean ) + totals->n / (totals->n - 1) * + (totals->ssq / totals->n - pow2 (totals->mean)) ) ; - totals->se_mean = totals->std_dev / sqrt(totals->n); - + totals->se_mean = totals->std_dev / sqrt (totals->n); } } + +/* + Local Variables: + mode: c + End: +*/