projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Subcommand to export a model as a C function
[pspp-builds.git]
/
src
/
levene.c
diff --git
a/src/levene.c
b/src/levene.c
index e29e77629c110000b250a07667475e523522cda5..5de5220588564cb6674fd20aa04e21279dd3f0bf 100644
(file)
--- a/
src/levene.c
+++ b/
src/levene.c
@@
-16,14
+16,16
@@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
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., 5
9 Temple Place - Suite 330
, Boston, MA
- 0211
1-1307
, USA. */
+ Foundation, Inc., 5
1 Franklin Street, Fifth Floor
, Boston, MA
+ 0211
0-1301
, USA. */
#include <config.h>
#include "levene.h"
#include "error.h"
#include "case.h"
#include "casefile.h"
#include <config.h>
#include "levene.h"
#include "error.h"
#include "case.h"
#include "casefile.h"
+#include "dictionary.h"
+#include "group_proc.h"
#include "hash.h"
#include "str.h"
#include "var.h"
#include "hash.h"
#include "str.h"
#include "var.h"
@@
-66,7
+68,7
@@
struct levene_info
struct variable *v_indep;
/* Number of dependent variables */
struct variable *v_indep;
/* Number of dependent variables */
-
in
t n_dep;
+
size_
t n_dep;
/* The dependent variables */
struct variable **v_dep;
/* The dependent variables */
struct variable **v_dep;
@@
-75,8
+77,7
@@
struct levene_info
enum lev_missing missing;
/* Function to test for missing values */
enum lev_missing missing;
/* Function to test for missing values */
- is_missing_func is_missing;
-
+ is_missing_func *is_missing;
};
/* First pass */
};
/* First pass */
@@
-93,7
+94,7
@@
static void levene2_postcalc (void *);
void
levene(const struct casefile *cf,
void
levene(const struct casefile *cf,
- struct variable *v_indep,
in
t n_dep, struct variable **v_dep,
+ struct variable *v_indep,
size_
t n_dep, struct variable **v_dep,
enum lev_missing missing, is_missing_func value_is_missing)
{
struct casereader *r;
enum lev_missing missing, is_missing_func value_is_missing)
{
struct casereader *r;
@@
-155,17
+156,29
@@
static struct lz_stats *lz;
static void
levene_precalc (const struct levene_info *l)
{
static void
levene_precalc (const struct levene_info *l)
{
-
in
t i;
+
size_
t i;
- lz
= xmalloc (sizeof (struct lz_stats ) * l->n_dep )
;
+ lz
= xnmalloc (l->n_dep, sizeof *lz)
;
- for(i
=
0; i < l->n_dep ; ++i )
+ for(i
=
0; i < l->n_dep ; ++i )
{
{
- struct variable *v = l->v_dep[i];
+ struct variable *var = l->v_dep[i];
+ struct group_proc *gp = group_proc_get (var);
+ struct group_statistics *gs;
+ struct hsh_iterator hi;
lz[i].grand_total = 0;
lz[i].total_n = 0;
lz[i].grand_total = 0;
lz[i].total_n = 0;
- lz[i].n_groups = v->p.grp_data.n_groups ;
+ lz[i].n_groups = gp->n_groups ;
+
+
+ for ( gs = hsh_first(gp->group_hash, &hi);
+ gs != 0;
+ gs = hsh_next(gp->group_hash, &hi))
+ {
+ gs->lz_total = 0;
+ }
+
}
}
}
}
@@
-173,7
+186,7
@@
levene_precalc (const struct levene_info *l)
static int
levene_calc (const struct ccase *c, void *_l)
{
static int
levene_calc (const struct ccase *c, void *_l)
{
-
in
t i;
+
size_
t i;
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
const union value *gv = case_data (c, l->v_indep->fv);
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
const union value *gv = case_data (c, l->v_indep->fv);
@@
-188,7
+201,7
@@
levene_calc (const struct ccase *c, void *_l)
struct variable *v = l->v_dep[i];
const union value *val = case_data (c, v->fv);
struct variable *v = l->v_dep[i];
const union value *val = case_data (c, v->fv);
- if (l->is_missing
(val,v
) )
+ if (l->is_missing
(&v->miss, val
) )
{
return 0;
}
{
return 0;
}
@@
-201,16
+214,17
@@
levene_calc (const struct ccase *c, void *_l)
for (i = 0; i < l->n_dep; ++i)
{
struct variable *var = l->v_dep[i];
for (i = 0; i < l->n_dep; ++i)
{
struct variable *var = l->v_dep[i];
+ struct group_proc *gp = group_proc_get (var);
double levene_z;
const union value *v = case_data (c, var->fv);
struct group_statistics *gs;
double levene_z;
const union value *v = case_data (c, var->fv);
struct group_statistics *gs;
- gs = hsh_find(
var->p.grp_data.
group_hash,(void *) &key );
+ gs = hsh_find(
gp->
group_hash,(void *) &key );
if ( 0 == gs )
continue ;
if ( 0 == gs )
continue ;
- if ( ! l->is_missing(
v,var
))
+ if ( ! l->is_missing(
&var->miss, v
))
{
levene_z= fabs(v->f - gs->mean);
lz[i].grand_total += levene_z * weight;
{
levene_z= fabs(v->f - gs->mean);
lz[i].grand_total += levene_z * weight;
@@
-218,6
+232,7
@@
levene_calc (const struct ccase *c, void *_l)
gs->lz_total += levene_z * weight;
}
gs->lz_total += levene_z * weight;
}
+
}
return 0;
}
}
return 0;
}
@@
-226,7
+241,7
@@
levene_calc (const struct ccase *c, void *_l)
static void
levene_postcalc (void *_l)
{
static void
levene_postcalc (void *_l)
{
-
in
t v;
+
size_
t v;
struct levene_info *l = (struct levene_info *) _l;
struct levene_info *l = (struct levene_info *) _l;
@@
-236,6
+251,7
@@
levene_postcalc (void *_l)
lz[v].grand_mean = lz[v].grand_total / lz[v].total_n ;
}
lz[v].grand_mean = lz[v].grand_total / lz[v].total_n ;
}
+
}
}
@@
-245,11
+261,11
@@
static double *lz_denominator;
static void
levene2_precalc (void *_l)
{
static void
levene2_precalc (void *_l)
{
-
in
t v;
+
size_
t v;
struct levene_info *l = (struct levene_info *) _l;
struct levene_info *l = (struct levene_info *) _l;
- lz_denominator =
(double *) xmalloc(sizeof(double) * l->n_dep
);
+ lz_denominator =
xnmalloc (l->n_dep, sizeof *lz_denominator
);
/* This stuff could go in the first post calc . . . */
for (v = 0; v < l->n_dep; ++v)
/* This stuff could go in the first post calc . . . */
for (v = 0; v < l->n_dep; ++v)
@@
-258,14
+274,14
@@
levene2_precalc (void *_l)
struct group_statistics *g;
struct variable *var = l->v_dep[v] ;
struct group_statistics *g;
struct variable *var = l->v_dep[v] ;
- struct hsh_table *hash =
var->p.grp_data.
group_hash;
+ struct hsh_table *hash =
group_proc_get (var)->
group_hash;
for(g = (struct group_statistics *) hsh_first(hash,&hi);
g != 0 ;
g = (struct group_statistics *) hsh_next(hash,&hi) )
{
for(g = (struct group_statistics *) hsh_first(hash,&hi);
g != 0 ;
g = (struct group_statistics *) hsh_next(hash,&hi) )
{
- g->lz_mean = g->lz_total
/
g->n ;
+ g->lz_mean = g->lz_total
/
g->n ;
}
lz_denominator[v] = 0;
}
}
lz_denominator[v] = 0;
}
@@
-274,7
+290,7
@@
levene2_precalc (void *_l)
static int
levene2_calc (const struct ccase *c, void *_l)
{
static int
levene2_calc (const struct ccase *c, void *_l)
{
-
in
t i;
+
size_
t i;
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
int warn = 0;
struct levene_info *l = (struct levene_info *) _l;
@@
-292,7
+308,7
@@
levene2_calc (const struct ccase *c, void *_l)
struct variable *v = l->v_dep[i];
const union value *val = case_data (c, v->fv);
struct variable *v = l->v_dep[i];
const union value *val = case_data (c, v->fv);
- if (l->is_missing(
val,v
) )
+ if (l->is_missing(
&v->miss, val
) )
{
return 0;
}
{
return 0;
}
@@
-308,12
+324,12
@@
levene2_calc (const struct ccase *c, void *_l)
const union value *v = case_data (c, var->fv);
struct group_statistics *gs;
const union value *v = case_data (c, var->fv);
struct group_statistics *gs;
- gs = hsh_find(
var->p.grp_data.
group_hash,(void *) &key );
+ gs = hsh_find(
group_proc_get (var)->
group_hash,(void *) &key );
if ( 0 == gs )
continue;
if ( 0 == gs )
continue;
- if ( ! l->is_missing
(v,var
) )
+ if ( ! l->is_missing
(&var->miss, v
) )
{
levene_z = fabs(v->f - gs->mean);
lz_denominator[i] += weight * pow2(levene_z - gs->lz_mean);
{
levene_z = fabs(v->f - gs->mean);
lz_denominator[i] += weight * pow2(levene_z - gs->lz_mean);
@@
-327,7
+343,7
@@
levene2_calc (const struct ccase *c, void *_l)
static void
levene2_postcalc (void *_l)
{
static void
levene2_postcalc (void *_l)
{
-
in
t v;
+
size_
t v;
struct levene_info *l = (struct levene_info *) _l;
struct levene_info *l = (struct levene_info *) _l;
@@
-338,7
+354,8
@@
levene2_postcalc (void *_l)
struct group_statistics *g;
struct variable *var = l->v_dep[v] ;
struct group_statistics *g;
struct variable *var = l->v_dep[v] ;
- struct hsh_table *hash = var->p.grp_data.group_hash;
+ struct group_proc *gp = group_proc_get (var);
+ struct hsh_table *hash = gp->group_hash;
for(g = (struct group_statistics *) hsh_first(hash,&hi);
g != 0 ;
for(g = (struct group_statistics *) hsh_first(hash,&hi);
g != 0 ;
@@
-346,12
+363,11
@@
levene2_postcalc (void *_l)
{
lz_numerator += g->n * pow2(g->lz_mean - lz[v].grand_mean );
}
{
lz_numerator += g->n * pow2(g->lz_mean - lz[v].grand_mean );
}
- lz_numerator *= ( l->v_dep[v]->p.grp_data.ugs.n -
- l->v_dep[v]->p.grp_data.n_groups );
+ lz_numerator *= ( gp->ugs.n - gp->n_groups );
- lz_denominator[v] *= (
l->v_dep[v]->p.grp_data.
n_groups - 1);
-
-
l->v_dep[v]->p.grp_data.levene = lz_numerator/
lz_denominator[v] ;
+ lz_denominator[v] *= (
gp->
n_groups - 1);
+
+
gp->levene = lz_numerator /
lz_denominator[v] ;
}
}