#include "libpspp/assertion.h"
#include "libpspp/message.h"
+#include "libpspp/pool.h"
#include "data/dataset.h"
BP_VARIABLES
};
+
+/* Indices for the ex_proto member (below) */
+enum
+ {
+ EX_VAL, /* value */
+ EX_ID, /* identity */
+ EX_WT /* weight */
+ };
+
+
struct examine
{
+ struct pool *pool;
+
+ /* A caseproto used to contain the data subsets under examination,
+ see (enum above) */
+ struct caseproto *ex_proto;
+
size_t n_dep_vars;
const struct variable **dep_vars;
double identity;
};
-enum
- {
- EX_VAL, /* value */
- EX_ID, /* identity */
- EX_WT /* weight */
- };
-
struct exploratory_stats
{
double missing;
int ivar_idx;
const union value **prev_val = xcalloc (iact->n_vars, sizeof (*prev_val));
-
+
for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
prev_val[ivar_idx] = NULL;
{
int ivar_idx;
int diff_idx = -1;
+
for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
{
const struct variable *ivar = iact->vars[ivar_idx];
chart_item_submit (npp);
chart_item_submit (dnpp);
}
+ casereader_destroy (reader);
ds_destroy (&label);
}
);
}
- tab_vline (t, TAL_1, heading_columns - 1, heading_rows, nr - 1);
+ if (n_cats > 0)
+ {
+ tab_vline (t, TAL_1, heading_columns - 1, heading_rows, nr - 1);
+
for (v = 0; v < cmd->n_dep_vars; ++v)
{
- const union value **prev_val = xxx0 (iact);
+ const union value **prev_vals = xxx0 (iact);
int ivar_idx;
if ( v > 0 )
const struct exploratory_stats *es = ess + v;
- int diff_idx = xxx1 (iact, c, prev_val);
+ int diff_idx = xxx1 (iact, c, prev_vals);
double hinges[3];
int p;
_("Tukey's Hinges"));
}
- }
+ free (prev_vals);
+ }
+ }
tab_submit (t);
}
heading_rows + v * rows_per_var + i * rows_per_cat + 12,
0, calc_sekurt (m0), 0);
}
+
+ free (prev_val);
}
tab_submit (t);
}
0);
}
}
+ free (prev_val);
}
tab_submit (t);
for (v = 0; v < cmd->n_dep_vars; ++v)
{
int ivar_idx;
- const union value **prev_val = xxx0 (iact);
+ const union value **prev_values = xxx0 (iact);
if ( v > 0 )
tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * n_cats);
iact_idx, i);
if (c)
{
- int diff_idx = xxx1 (iact, c, prev_val);
+ int diff_idx = xxx1 (iact, c, prev_values);
if ( diff_idx != -1 && diff_idx < iact->n_vars - 1)
tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
- heading_rows + n_cats * v + i
- );
+ heading_rows + n_cats * v + i );
for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
{
}
}
+
es = categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
100.0 * (es[v].missing + es[v].non_missing)/ total
);
}
+ free (prev_values);
}
tab_hline (t, TAL_1, heading_columns, nc - 1, 1);
int v;
const struct examine *examine = aux1;
- struct exploratory_stats *es = xcalloc (examine->n_dep_vars, sizeof (*es));
-
- struct caseproto *proto = caseproto_create ();
- proto = caseproto_add_width (proto, 0); /* value */
- proto = caseproto_add_width (proto, 0); /* id */
- proto = caseproto_add_width (proto, 0); /* weight */
+ struct exploratory_stats *es = pool_calloc (examine->pool, examine->n_dep_vars, sizeof (*es));
+ struct subcase ordering;
+ subcase_init (&ordering, 0, 0, SC_ASCEND);
for (v = 0; v < examine->n_dep_vars; v++)
{
- struct subcase ordering;
-
- subcase_init (&ordering, 0, 0, SC_ASCEND);
-
- es[v].sorted_writer = sort_create_writer (&ordering, proto);
+ es[v].sorted_writer = sort_create_writer (&ordering, examine->ex_proto);
es[v].sorted_reader = NULL;
es[v].mom = moments_create (MOMENT_KURTOSIS);
es[v].maximum = -DBL_MAX;
es[v].minimum = DBL_MAX;
}
+
+ subcase_destroy (&ordering);
return es;
}
const struct examine *examine = aux1;
struct exploratory_stats *es = user_data;
- struct caseproto *proto = caseproto_create ();
- proto = caseproto_add_width (proto, 0); /* value */
- proto = caseproto_add_width (proto, 0); /* id */
- proto = caseproto_add_width (proto, 0); /* weight */
-
for (v = 0; v < examine->n_dep_vars; v++)
{
- struct ccase *outcase = case_create (proto);
const struct variable *var = examine->dep_vars[v];
const double x = case_data (c, var)->f;
continue;
}
+ struct ccase *outcase = case_create (examine->ex_proto);
+
if (x > es[v].maximum)
es[v].maximum = x;
}
es[v].sorted_reader = casewriter_make_reader (es[v].sorted_writer);
- total_cases = casereader_count_cases (casereader_clone (es[v].sorted_reader));
+ total_cases = casereader_count_cases (es[v].sorted_reader);
es[v].sorted_writer = NULL;
- es[v].maxima = xcalloc (examine->calc_extremes, sizeof (*es[v].maxima));
- es[v].minima = xcalloc (examine->calc_extremes, sizeof (*es[v].minima));
+ es[v].maxima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].maxima));
+ es[v].minima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].minima));
for (reader = casereader_clone (es[v].sorted_reader);
(c = casereader_read (reader)) != NULL; case_unref (c))
{
const int n_os = 5 + examine->n_percentiles;
struct order_stats **os ;
- es[v].percentiles = xcalloc (examine->n_percentiles, sizeof (*es[v].percentiles));
+ es[v].percentiles = pool_calloc (examine->pool, examine->n_percentiles, sizeof (*es[v].percentiles));
es[v].trimmed_mean = trimmed_mean_create (es[v].cc, 0.05);
order_stats_accumulate_idx (os, n_os,
casereader_clone (es[v].sorted_reader),
EX_WT, EX_VAL);
+
+ free (os);
}
if (examine->boxplot)
}
}
+static void
+cleanup_exploratory_stats (struct examine *cmd)
+{
+ int i;
+ for (i = 0; i < cmd->n_iacts; ++i)
+ {
+ int v;
+ const size_t n_cats = categoricals_n_count (cmd->cats, i);
+
+ for (v = 0; v < cmd->n_dep_vars; ++v)
+ {
+ int grp;
+ for (grp = 0; grp < n_cats; ++grp)
+ {
+ int q;
+ const struct exploratory_stats *es =
+ categoricals_get_user_data_by_category_real (cmd->cats, i, grp);
+
+ struct order_stats *os = es[v].hinges;
+ struct statistic *stat = &os->parent;
+ stat->destroy (stat);
+
+ for (q = 0; q < 3 ; q++)
+ {
+ os = es[v].quartiles[q];
+ stat = &os->parent;
+ stat->destroy (stat);
+ }
+
+ for (q = 0; q < cmd->n_percentiles ; q++)
+ {
+ os = es[v].percentiles[q];
+ stat = &os->parent;
+ stat->destroy (stat);
+ }
+
+ os = es[v].trimmed_mean;
+ stat = &os->parent;
+ stat->destroy (stat);
+
+ os = es[v].np;
+ if (os)
+ {
+ stat = &os->parent;
+ stat->destroy (stat);
+ }
+
+ os = es[v].histogram;
+ if (os)
+ {
+ stat = &os->parent;
+ stat->destroy (stat);
+ }
+
+ moments_destroy (es[v].mom);
+
+ casereader_destroy (es[v].sorted_reader);
+ }
+ }
+ }
+}
+
+
static void
run_examine (struct examine *cmd, struct casereader *input)
{
NULL,
NULL);
- for (reader = casereader_clone (input);
+ for (reader = input;
(c = casereader_read (reader)) != NULL; case_unref (c))
{
categoricals_update (cmd->cats, c);
if (cmd->descriptives)
descriptives_report (cmd, i);
}
+
+ cleanup_exploratory_stats (cmd);
+ categoricals_destroy (cmd->cats);
}
+
int
cmd_examine (struct lexer *lexer, struct dataset *ds)
{
+ int i;
bool nototals_seen = false;
bool totals_seen = false;
examine.id_var = 0;
examine.boxplot_mode = BP_GROUPS;
+ examine.ex_proto = caseproto_create ();
+ examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* value */
+ examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* id */
+ examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* weight */
+
+ examine.pool = pool_create ();
/* Allocate space for the first interaction.
This is interaction is an empty one (for the totals).
interaction.
*/
examine.n_iacts = 1;
- examine.iacts = iacts_mem = xzalloc (sizeof (struct interaction *));
+ examine.iacts = iacts_mem = pool_zalloc (examine.pool, sizeof (struct interaction *));
examine.iacts[0] = interaction_create (NULL);
examine.exclude = MV_ANY;
{
examine.n_iacts++;
iacts_mem =
- xrealloc (iacts_mem,
- sizeof (*iacts_mem) * examine.n_iacts);
+ pool_nrealloc (examine.pool, iacts_mem,
+ examine.n_iacts,
+ sizeof (*iacts_mem));
iacts_mem[examine.n_iacts - 1] = iact;
}
ok = proc_commit (ds) && ok;
}
+ caseproto_unref (examine.ex_proto);
+
+ for (i = 0; i < examine.n_iacts; ++i)
+ interaction_destroy (examine.iacts[i]);
+
+ free (examine.ptiles);
+ free (examine.dep_vars);
+ pool_destroy (examine.pool);
+
return CMD_SUCCESS;
error:
+ caseproto_unref (examine.ex_proto);
+ for (i = 0; i < examine.n_iacts; ++i)
+ interaction_destroy (examine.iacts[i]);
+ free (examine.dep_vars);
+ free (examine.ptiles);
+ pool_destroy (examine.pool);
+
return CMD_FAILURE;
}