1 /* PSPP - A program for statistical analysis . -*-c-*-
3 Copyright (C) 2004 Free Software Foundation, Inc.
4 Author: John Darrington 2004
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 #include "factor_stats.h"
30 metrics_precalc(struct metrics *fs)
40 metrics_calc(struct metrics *fs, double x, double weight)
43 fs->ssq += x * x * weight;
44 fs->sum += x * weight;
46 if ( x < fs->min) fs->min = x;
47 if ( x > fs->max) fs->max = x;
52 metrics_postcalc(struct metrics *fs)
55 fs->mean = fs->sum / fs->n;
57 sample_var = ( fs->ssq / fs->n - fs->mean * fs->mean );
59 fs->var = fs->n * sample_var / ( fs->n - 1) ;
60 fs->stddev = sqrt(fs->var);
63 /* FIXME: Check this is correct ???
64 Shouldn't we use the sample variance ??? */
65 fs->stderr = sqrt (fs->var / fs->n) ;
70 /* Functions for hashes */
73 free_factor_stats(struct factor_statistics *f, int width UNUSED)
79 compare_indep_values(const struct factor_statistics *f1,
80 const struct factor_statistics *f2,
83 return compare_values(f1->id, f2->id, width);
88 hash_indep_value(const struct factor_statistics *f, int width)
90 return hash_value(f->id, width);