This increases type safety and so it's hard to see any downside.
case MEDIAN:
{
struct casereader *sorted_reader;
- struct order_stats *median = percentile_create (0.5, i->cc);
+ struct percentile *median = percentile_create (0.5, i->cc);
+ struct order_stats *os = &median->parent;
sorted_reader = casewriter_make_reader (i->writer);
- order_stats_accumulate (&median, 1,
+ order_stats_accumulate (&os, 1,
sorted_reader,
i->weight,
i->subject,
i->exclude);
- v->f = percentile_calculate ((struct percentile *) median,
- PC_HAVERAGE);
+ v->f = percentile_calculate (median, PC_HAVERAGE);
- statistic_destroy ((struct statistic *) median);
+ statistic_destroy (&median->parent.parent);
}
break;
case SD:
{
const struct dictionary *dict = dataset_dict (ds);
int v, i;
- struct one_sample_test *ost = (struct one_sample_test *) test;
struct chisquare_test *cst = (struct chisquare_test *) test;
+ struct one_sample_test *ost = &cst->parent;
int n_cells = 0;
double total_expected = 0.0;
const struct variable *wvar = dict_get_weight (dict);
struct percentile **ptl;
size_t n_ptiles;
- struct statistic *tukey_hinges;
- struct statistic *box_whisker;
- struct statistic *trimmed_mean;
- struct statistic *histogram;
- struct order_stats *np;
+ struct tukey_hinges *tukey_hinges;
+ struct box_whisker *box_whisker;
+ struct trimmed_mean *trimmed_mean;
+ struct histogram *histogram;
+ struct np *np;
/* Three quartiles indexing into PTL */
struct percentile **quartiles;
moments1_destroy (result->metrics[v].moments);
extrema_destroy (result->metrics[v].minima);
extrema_destroy (result->metrics[v].maxima);
- statistic_destroy (result->metrics[v].trimmed_mean);
- statistic_destroy (result->metrics[v].tukey_hinges);
- statistic_destroy (result->metrics[v].box_whisker);
- statistic_destroy (result->metrics[v].histogram);
+ statistic_destroy (&result->metrics[v].trimmed_mean->parent.parent);
+ statistic_destroy (&result->metrics[v].tukey_hinges->parent.parent);
+ statistic_destroy (&result->metrics[v].box_whisker->parent.parent);
+ statistic_destroy (&result->metrics[v].histogram->parent);
for (i = 0 ; i < result->metrics[v].n_ptiles; ++i)
- statistic_destroy ((struct statistic *) result->metrics[v].ptl[i]);
+ statistic_destroy (&result->metrics[v].ptl[i]->parent.parent);
free (result->metrics[v].ptl);
free (result->metrics[v].quartiles);
casereader_destroy (result->metrics[v].up_reader);
ds_put_format (&label, "%s ", var_get_name (dependent_var[v]));
factor_to_string (fctr, result, &label);
- np = (struct np *) result->metrics[v].np;
+ np = result->metrics[v].np;
reader = casewriter_make_reader (np->writer);
npp = np_plot_create (np, reader, ds_cstr (&label));
dnpp = dnp_plot_create (np, reader, ds_cstr (&label));
struct histogram *histogram;
double mean, var, n;
- histogram = (struct histogram *) result->metrics[v].histogram;
+ histogram = result->metrics[v].histogram;
if (histogram == NULL)
{
/* Probably all values are SYSMIS. */
factor_to_string (fctr, result, &str);
- moments1_calculate ((struct moments1 *) result->metrics[v].moments,
+ moments1_calculate (result->metrics[v].moments,
&n, &mean, &var, NULL, NULL);
chart_submit (histogram_chart_create (histogram, ds_cstr (&str),
n, mean, sqrt (var), false));
struct factor_metrics *metrics = &result->metrics[v];
struct string str = DS_EMPTY_INITIALIZER;
factor_to_string_concise (fctr, result, &str);
- boxplot_add_box (boxplot,
- (struct box_whisker *) metrics->box_whisker,
- ds_cstr (&str));
+ boxplot_add_box (boxplot, metrics->box_whisker, ds_cstr (&str));
metrics->box_whisker = NULL;
ds_destroy (&str);
}
for (v = 0; v < n_dep_var; ++v)
{
struct factor_metrics *metrics = &result->metrics[v];
- boxplot_add_box (boxplot,
- (struct box_whisker *) metrics->box_whisker,
+ boxplot_add_box (boxplot, metrics->box_whisker,
var_get_name (dependent_var[v]));
metrics->box_whisker = NULL;
}
metric->n_ptiles = percentile_list.n_data;
- metric->ptl = xcalloc (metric->n_ptiles,
- sizeof (struct percentile *));
+ metric->ptl = xcalloc (metric->n_ptiles, sizeof *metric->ptl);
metric->quartiles = xcalloc (3, sizeof (*metric->quartiles));
for (i = 0 ; i < metric->n_ptiles; ++i)
{
- metric->ptl[i] = (struct percentile *)
- percentile_create (percentile_list.data[i] / 100.0, metric->n_valid);
+ metric->ptl[i] = percentile_create (percentile_list.data[i] / 100.0, metric->n_valid);
if ( percentile_list.data[i] == 25)
metric->quartiles[0] = metric->ptl[i];
n_os ++;
}
- os = xcalloc (sizeof (struct order_stats *), n_os);
+ os = xcalloc (n_os, sizeof *os);
for (i = 0 ; i < metric->n_ptiles ; ++i )
{
- os[i] = (struct order_stats *) metric->ptl[i];
+ os[i] = &metric->ptl[i]->parent;
}
- os[i] = (struct order_stats *) metric->tukey_hinges;
- os[i+1] = (struct order_stats *) metric->trimmed_mean;
+ os[i] = &metric->tukey_hinges->parent;
+ os[i+1] = &metric->trimmed_mean->parent;
if (cmd->a_plot[XMN_PLT_NPPLOT])
- os[i+2] = metric->np;
+ os[i+2] = &metric->np->parent;
order_stats_accumulate (os, n_os,
casereader_clone (metric->up_reader),
{
struct factor_metrics *metric = &result->metrics[v];
if ( metric->histogram)
- histogram_add ((struct histogram *) metric->histogram,
+ histogram_add (metric->histogram,
case_data (c, dependent_vars[v])->f, weight);
}
case_unref (c);
struct factor_metrics *metric = &result->metrics[v];
int n_vals = caseproto_get_n_widths (casereader_get_proto (
metric->up_reader));
+ struct order_stats *os = &metric->box_whisker->parent;
metric->box_whisker =
- box_whisker_create ((struct tukey_hinges *) metric->tukey_hinges,
- cmd->v_id, n_vals - 1);
+ box_whisker_create ( metric->tukey_hinges, cmd->v_id, n_vals - 1);
- order_stats_accumulate ((struct order_stats **) &metric->box_whisker,
- 1,
+ order_stats_accumulate ( &os, 1,
casereader_clone (metric->up_reader),
wv, dependent_vars[v], MV_ANY);
}
tab_double (tbl, n_cols - 2,
heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
TAB_CENTER,
- trimmed_mean_calculate ((struct trimmed_mean *) result->metrics[v].trimmed_mean),
+ trimmed_mean_calculate (result->metrics[v].trimmed_mean),
NULL);
tab_vline (tbl, TAL_1, n_cols - n_percentiles -1, heading_rows, n_rows - 1);
- tukey_hinges_calculate ((struct tukey_hinges *) result->metrics[v].tukey_hinges,
- hinges);
+ tukey_hinges_calculate (result->metrics[v].tukey_hinges, hinges);
for (j = 0; j < n_percentiles; ++j)
{
d[frq_stddev],
normal));
- statistic_destroy ((struct statistic *)hist);
+ statistic_destroy (&hist->parent);
}
if ( chart == GFT_PIE)
double x_min = DBL_MAX;
double x_max = -DBL_MAX;
- struct statistic *hist;
+ struct histogram *hist;
const double bins = 11;
struct hsh_iterator hi;
for( i = 0 ; i < ft->n_valid ; ++i )
{
frq = &ft->valid[i];
- histogram_add ((struct histogram *)hist, frq->value.f, frq->count);
+ histogram_add (hist, frq->value.f, frq->count);
}
- return (struct histogram *)hist;
+ return hist;
}
struct npar_specs *specs = aux;
struct chisquare_test *cstp = pool_alloc(specs->pool, sizeof(*cstp));
- struct one_sample_test *tp = (struct one_sample_test *) cstp;
+ struct one_sample_test *tp = &cstp->parent;
+ struct npar_test *nt = &tp->parent;
- ((struct npar_test *)tp)->execute = chisquare_execute;
- ((struct npar_test *)tp)->insert_variables = one_sample_insert_variables;
+ nt->execute = chisquare_execute;
+ nt->insert_variables = one_sample_insert_variables;
if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
&tp->vars, &tp->n_vars,
specs->test,
sizeof(*specs->test) * specs->n_tests);
- specs->test[specs->n_tests - 1] = (struct npar_test *) tp;
+ specs->test[specs->n_tests - 1] = nt;
return 1;
}
{
struct npar_specs *specs = aux;
struct binomial_test *btp = pool_alloc(specs->pool, sizeof(*btp));
- struct one_sample_test *tp = (struct one_sample_test *) btp;
+ struct one_sample_test *tp = &btp->parent;
+ struct npar_test *nt = &tp->parent;
- ((struct npar_test *)tp)->execute = binomial_execute;
- ((struct npar_test *)tp)->insert_variables = one_sample_insert_variables;
+ nt->execute = binomial_execute;
+ nt->insert_variables = one_sample_insert_variables;
btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
specs->test,
sizeof(*specs->test) * specs->n_tests);
- specs->test[specs->n_tests - 1] = (struct npar_test *) tp;
+ specs->test[specs->n_tests - 1] = nt;
return 1;
}
const struct variable **vlist2;
size_t n_vlist2;
- ((struct npar_test *)test_parameters)->insert_variables = two_sample_insert_variables;
+ test_parameters->parent.insert_variables = two_sample_insert_variables;
if (!parse_variables_const_pool (lexer, pool,
dict,
struct npar_specs *specs = aux;
struct two_sample_test *tp = pool_alloc (specs->pool, sizeof(*tp));
- ((struct npar_test *)tp)->execute = wilcoxon_execute;
+ struct npar_test *nt = &tp->parent;
+ nt->execute = wilcoxon_execute;
if (!parse_two_sample_related_test (lexer, dataset_dict (ds), cmd,
tp, specs->pool) )
specs->test = pool_realloc (specs->pool,
specs->test,
sizeof(*specs->test) * specs->n_tests);
- specs->test[specs->n_tests - 1] = (struct npar_test *) tp;
+ specs->test[specs->n_tests - 1] = nt;
return 1;
}
struct npar_specs *specs = aux;
struct two_sample_test *tp = pool_alloc(specs->pool, sizeof(*tp));
- ((struct npar_test *)tp)->execute = NULL;
+ struct npar_test *nt = &tp->parent;
+ nt->execute = NULL;
if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
specs->test = pool_realloc (specs->pool,
specs->test,
sizeof(*specs->test) * specs->n_tests);
- specs->test[specs->n_tests - 1] = (struct npar_test *) tp;
+ specs->test[specs->n_tests - 1] = nt;
return 1;
}
struct npar_specs *specs = aux;
struct two_sample_test *tp = pool_alloc(specs->pool, sizeof(*tp));
- ((struct npar_test *) tp)->execute = sign_execute;
+ struct npar_test *nt = &tp->parent;
+
+ nt->execute = sign_execute;
if (!parse_two_sample_related_test (lexer, dataset_dict (ds), cmd,
tp, specs->pool) )
specs->test = pool_realloc (specs->pool,
specs->test,
sizeof(*specs->test) * specs->n_tests);
- specs->test[specs->n_tests - 1] = (struct npar_test *) tp;
+ specs->test[specs->n_tests - 1] = nt;
return 1;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
return &bw->outliers;
}
-struct statistic *
+struct box_whisker *
box_whisker_create (const struct tukey_hinges *th,
const struct variable *id_var, size_t casenumber_idx)
{
ll_init (&w->outliers);
- return stat;
+ return w;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
const struct variable *id_var;
};
-struct statistic * box_whisker_create (const struct tukey_hinges *,
+struct box_whisker * box_whisker_create (const struct tukey_hinges *,
const struct variable *, size_t);
void box_whisker_whiskers (const struct box_whisker *bw, double whiskers[2]);
/* PSPP - a program for statistical analysis.
- Copyright (C) 2004, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2008, 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
void
histogram_add (struct histogram *h, double y, double c)
{
- ((struct statistic *)h)->accumulate ((struct statistic *) h, NULL, c, 0, y);
+ struct statistic *stat = &h->parent;
+ stat->accumulate (stat, NULL, c, 0, y);
}
}
-struct statistic *
+struct histogram *
histogram_create (int bins, double min, double max)
{
struct histogram *h = xmalloc (sizeof *h);
- struct statistic *stat = (struct statistic *) h;
+ struct statistic *stat = &h->parent;
double upper_limit, lower_limit;
double bin_width = chart_rounded_tick ((max - min) / (double) bins);
stat->accumulate = acc;
stat->destroy = destroy;
- return stat;
+ return h;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
gsl_histogram *gsl_hist;
};
-struct statistic * histogram_create (int bins, double max, double min);
+struct histogram * histogram_create (int bins, double max, double min);
void histogram_add (struct histogram *h, double y, double c);
np->prev_cc = cc;
}
-struct order_stats *
+struct np *
np_create (const struct moments1 *m)
{
double variance;
struct np *np = xzalloc (sizeof (*np));
- struct statistic *stat = (struct statistic *) np;
- struct order_stats *os = (struct order_stats *) np;
+ struct order_stats *os = &np->parent;
+ struct statistic *stat = &os->parent;
struct caseproto *proto;
int i;
stat->destroy = destroy;
stat->accumulate = acc;
- return os;
+ return np;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
};
-struct order_stats * np_create (const struct moments1 *);
+struct np * np_create (const struct moments1 *);
#endif
{
int k;
struct order_stats *tos = os[j];
- struct statistic *stat = (struct statistic *) tos;
+ struct statistic *stat = &tos->parent;
for (k = 0 ; k < tos->n_k; ++k)
{
struct k *myk = &tos->k[k];
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
}
-struct order_stats *
+struct percentile *
percentile_create (double p, double W)
{
struct percentile *ptl = xzalloc (sizeof (*ptl));
- struct order_stats *os = (struct order_stats *) ptl;
- struct statistic *stat = (struct statistic *) ptl;
+ struct order_stats *os = &ptl->parent;
+ struct statistic *stat = &os->parent;
assert (p >= 0);
assert (p <= 1.0);
stat->destroy = destroy;
- return os;
+ return ptl;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2004, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2008, 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
/* Create the Pth percentile.
W is the total sum of weights in the data set
*/
-struct order_stats *percentile_create (double p, double W);
+struct percentile *percentile_create (double p, double W);
/* Return the value of the percentile */
double percentile_calculate (const struct percentile *ptl, enum pc_alg alg);
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
acc (struct statistic *s, const struct ccase *cx UNUSED, double c, double cc, double y)
{
struct trimmed_mean *tm = (struct trimmed_mean *) s;
- struct order_stats *os = (struct order_stats *) s;
+ struct order_stats *os = &tm->parent;
if ( cc > os->k[0].tc && cc < os->k[1].tc)
tm->sum += c * y;
free (s);
}
-struct statistic *
+struct trimmed_mean *
trimmed_mean_create (double W, double tail)
{
struct trimmed_mean *tm = xzalloc (sizeof (*tm));
- struct order_stats *os = (struct order_stats *) tm;
- struct statistic *stat = (struct statistic *) tm;
+ struct order_stats *os = &tm->parent;
+ struct statistic *stat = &os->parent;
os->n_k = 2;
os->k = xcalloc (sizeof (*os->k), 2);
tm->w = W;
tm->tail = tail;
- return stat;
+ return tm;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
double tail;
};
-struct statistic * trimmed_mean_create (double W, double c_min);
+struct trimmed_mean * trimmed_mean_create (double W, double c_min);
double trimmed_mean_calculate (const struct trimmed_mean *);
#endif
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
free (s);
};
-struct statistic *
+struct tukey_hinges *
tukey_hinges_create (double W, double c_min)
{
double d;
struct tukey_hinges *th = xzalloc (sizeof (*th));
- struct order_stats *os = (struct order_stats *) th;
- struct statistic *stat = (struct statistic *) th;
+ struct order_stats *os = &th->parent;
+ struct statistic *stat = &os->parent;
assert (c_min >= 0);
stat->destroy = destroy;
- return stat;
+ return th;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 2008 Free Software Foundation, Inc.
+ Copyright (C) 2008, 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
struct order_stats parent;
};
-struct statistic * tukey_hinges_create (double W, double c_min);
+struct tukey_hinges * tukey_hinges_create (double W, double c_min);
void tukey_hinges_calculate (const struct tukey_hinges *h, double hinge[3]);
const struct fmt_spec *fmt;
int width ;
struct value_comparator *vc = xzalloc (sizeof (*vc));
- struct comparator *cmptr = (struct comparator *) vc;
+ struct comparator *cmptr = &vc->parent;
cmptr->flags = 0;
cmptr->var = var;
enum string_cmp_flags flags)
{
struct string_comparator *ssc = xzalloc (sizeof (*ssc));
- struct comparator *cmptr = (struct comparator *) ssc;
+ struct comparator *cmptr = &ssc->parent;
cmptr->flags = flags;
cmptr->var = var;
{
int code;
struct regexp_comparator *rec = xzalloc (sizeof (*rec));
- struct comparator *cmptr = (struct comparator *) rec;
+ struct comparator *cmptr = &rec->parent;
cmptr->flags = flags;
cmptr->var = var;
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2006 Free Software Foundation
+ Copyright (C) 2006, 2009 Free Software Foundation
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
ses->parent.location = location;
- return (struct getl_interface *) ses;
+ return &ses->parent;
}
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 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
rlns->parent.read = read_interactive;
rlns->parent.close = readln_close;
- return (struct getl_interface *) rlns;
+ return &rlns->parent;
}