#include <data/case.h>
#include <data/casegrouper.h>
#include <data/casereader.h>
-#include <data/category.h>
#include <data/dictionary.h>
#include <data/missing-values.h>
#include <data/procedure.h>
#include <math/covariance.h>
#include <math/linreg.h>
#include <math/moments.h>
-#include <output/table.h>
+#include <output/tab.h>
#include "xalloc.h"
/*
STATISTICS subcommand output functions.
*/
-static void reg_stats_r (linreg *);
-static void reg_stats_coeff (linreg *);
-static void reg_stats_anova (linreg *);
-static void reg_stats_outs (linreg *);
-static void reg_stats_zpp (linreg *);
-static void reg_stats_label (linreg *);
-static void reg_stats_sha (linreg *);
-static void reg_stats_ci (linreg *);
-static void reg_stats_f (linreg *);
-static void reg_stats_bcov (linreg *);
-static void reg_stats_ses (linreg *);
-static void reg_stats_xtx (linreg *);
-static void reg_stats_collin (linreg *);
-static void reg_stats_tol (linreg *);
-static void reg_stats_selection (linreg *);
-static void statistics_keyword_output (void (*)(linreg *),
- int, linreg *);
+static void reg_stats_r (linreg *, void *);
+static void reg_stats_coeff (linreg *, void *);
+static void reg_stats_anova (linreg *, void *);
+static void reg_stats_outs (linreg *, void *);
+static void reg_stats_zpp (linreg *, void *);
+static void reg_stats_label (linreg *, void *);
+static void reg_stats_sha (linreg *, void *);
+static void reg_stats_ci (linreg *, void *);
+static void reg_stats_f (linreg *, void *);
+static void reg_stats_bcov (linreg *, void *);
+static void reg_stats_ses (linreg *, void *);
+static void reg_stats_xtx (linreg *, void *);
+static void reg_stats_collin (linreg *, void *);
+static void reg_stats_tol (linreg *, void *);
+static void reg_stats_selection (linreg *, void *);
+static void statistics_keyword_output (void (*)(linreg *, void *),
+ int, linreg *, void *);
static void
-reg_stats_r (linreg * c)
+reg_stats_r (linreg *c, void *aux UNUSED)
{
struct tab_table *t;
int n_rows = 2;
double std_error;
assert (c != NULL);
- rsq = c->ssm / c->sst;
- adjrsq = 1.0 - (1.0 - rsq) * (c->n_obs - 1.0) / (c->n_obs - c->n_indeps);
+ rsq = linreg_ssreg (c) / linreg_sst (c);
+ adjrsq = 1.0 - (1.0 - rsq) * (linreg_n_obs (c) - 1.0) / (linreg_n_obs (c) - linreg_n_coeffs (c));
std_error = sqrt (linreg_mse (c));
- t = tab_create (n_cols, n_rows, 0);
- tab_dim (t, tab_natural_dimensions, NULL);
+ t = tab_create (n_cols, n_rows);
tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
tab_hline (t, TAL_2, 0, n_cols - 1, 1);
tab_vline (t, TAL_2, 2, 0, n_rows - 1);
Table showing estimated regression coefficients.
*/
static void
-reg_stats_coeff (linreg * c)
+reg_stats_coeff (linreg * c, void *aux_)
{
size_t j;
int n_cols = 7;
const struct variable *v;
struct tab_table *t;
+ gsl_matrix *cov = aux_;
assert (c != NULL);
n_rows = linreg_n_coeffs (c) + 3;
- t = tab_create (n_cols, n_rows, 0);
+ t = tab_create (n_cols, n_rows);
tab_headers (t, 2, 0, 1, 0);
- tab_dim (t, tab_natural_dimensions, NULL);
tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
tab_hline (t, TAL_2, 0, n_cols - 1, 1);
tab_vline (t, TAL_2, 2, 0, n_rows - 1);
Standardized coefficient, i.e., regression coefficient
if all variables had unit variance.
*/
- beta = sqrt (gsl_matrix_get (linreg_cov (c), j, j));
- beta *= linreg_coeff (c, j) / c->depvar_std;
+ beta = sqrt (gsl_matrix_get (cov, j, j));
+ beta *= linreg_coeff (c, j) /
+ sqrt (gsl_matrix_get (cov, cov->size1 - 1, cov->size2 - 1));
tab_double (t, 4, this_row, 0, beta, NULL);
/*
Display the ANOVA table.
*/
static void
-reg_stats_anova (linreg * c)
+reg_stats_anova (linreg * c, void *aux UNUSED)
{
int n_cols = 7;
int n_rows = 4;
struct tab_table *t;
assert (c != NULL);
- t = tab_create (n_cols, n_rows, 0);
+ t = tab_create (n_cols, n_rows);
tab_headers (t, 2, 0, 1, 0);
- tab_dim (t, tab_natural_dimensions, NULL);
tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
tab_text (t, 1, 3, TAB_LEFT | TAT_TITLE, _("Total"));
/* Sums of Squares */
- tab_double (t, 2, 1, 0, c->ssm, NULL);
- tab_double (t, 2, 3, 0, c->sst, NULL);
- tab_double (t, 2, 2, 0, c->sse, NULL);
+ tab_double (t, 2, 1, 0, linreg_ssreg (c), NULL);
+ tab_double (t, 2, 3, 0, linreg_sst (c), NULL);
+ tab_double (t, 2, 2, 0, linreg_sse (c), NULL);
/* Degrees of freedom */
}
static void
-reg_stats_outs (linreg * c)
+reg_stats_outs (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_zpp (linreg * c)
+reg_stats_zpp (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_label (linreg * c)
+reg_stats_label (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_sha (linreg * c)
+reg_stats_sha (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_ci (linreg * c)
+reg_stats_ci (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_f (linreg * c)
+reg_stats_f (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_bcov (linreg * c)
+reg_stats_bcov (linreg * c, void *aux UNUSED)
{
int n_cols;
int n_rows;
assert (c != NULL);
n_cols = c->n_indeps + 1 + 2;
n_rows = 2 * (c->n_indeps + 1);
- t = tab_create (n_cols, n_rows, 0);
+ t = tab_create (n_cols, n_rows);
tab_headers (t, 2, 0, 1, 0);
- tab_dim (t, tab_natural_dimensions, NULL);
tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
tab_hline (t, TAL_2, 0, n_cols - 1, 1);
tab_vline (t, TAL_2, 2, 0, n_rows - 1);
tab_submit (t);
}
static void
-reg_stats_ses (linreg * c)
+reg_stats_ses (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_xtx (linreg * c)
+reg_stats_xtx (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_collin (linreg * c)
+reg_stats_collin (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_tol (linreg * c)
+reg_stats_tol (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-reg_stats_selection (linreg * c)
+reg_stats_selection (linreg * c, void *aux UNUSED)
{
assert (c != NULL);
}
static void
-statistics_keyword_output (void (*function) (linreg *),
- int keyword, linreg * c)
+statistics_keyword_output (void (*function) (linreg *, void *),
+ int keyword, linreg * c, void *aux)
{
if (keyword)
{
- (*function) (c);
+ (*function) (c, aux);
}
}
static void
-subcommand_statistics (int *keywords, linreg * c)
+subcommand_statistics (int *keywords, linreg * c, void *aux)
{
/*
The order here must match the order in which the STATISTICS
keywords[r] = 1;
}
}
- statistics_keyword_output (reg_stats_r, keywords[r], c);
- statistics_keyword_output (reg_stats_anova, keywords[anova], c);
- statistics_keyword_output (reg_stats_coeff, keywords[coeff], c);
- statistics_keyword_output (reg_stats_outs, keywords[outs], c);
- statistics_keyword_output (reg_stats_zpp, keywords[zpp], c);
- statistics_keyword_output (reg_stats_label, keywords[label], c);
- statistics_keyword_output (reg_stats_sha, keywords[sha], c);
- statistics_keyword_output (reg_stats_ci, keywords[ci], c);
- statistics_keyword_output (reg_stats_f, keywords[f], c);
- statistics_keyword_output (reg_stats_bcov, keywords[bcov], c);
- statistics_keyword_output (reg_stats_ses, keywords[ses], c);
- statistics_keyword_output (reg_stats_xtx, keywords[xtx], c);
- statistics_keyword_output (reg_stats_collin, keywords[collin], c);
- statistics_keyword_output (reg_stats_tol, keywords[tol], c);
- statistics_keyword_output (reg_stats_selection, keywords[selection], c);
+ statistics_keyword_output (reg_stats_r, keywords[r], c, aux);
+ statistics_keyword_output (reg_stats_anova, keywords[anova], c, aux);
+ statistics_keyword_output (reg_stats_coeff, keywords[coeff], c, aux);
+ statistics_keyword_output (reg_stats_outs, keywords[outs], c, aux);
+ statistics_keyword_output (reg_stats_zpp, keywords[zpp], c, aux);
+ statistics_keyword_output (reg_stats_label, keywords[label], c, aux);
+ statistics_keyword_output (reg_stats_sha, keywords[sha], c, aux);
+ statistics_keyword_output (reg_stats_ci, keywords[ci], c, aux);
+ statistics_keyword_output (reg_stats_f, keywords[f], c, aux);
+ statistics_keyword_output (reg_stats_bcov, keywords[bcov], c, aux);
+ statistics_keyword_output (reg_stats_ses, keywords[ses], c, aux);
+ statistics_keyword_output (reg_stats_xtx, keywords[xtx], c, aux);
+ statistics_keyword_output (reg_stats_collin, keywords[collin], c, aux);
+ statistics_keyword_output (reg_stats_tol, keywords[tol], c, aux);
+ statistics_keyword_output (reg_stats_selection, keywords[selection], c, aux);
}
/*
const gsl_matrix *ssizes;
const gsl_matrix *cm;
const gsl_matrix *mean_matrix;
+ const gsl_matrix *ssize_matrix;
double result = 0.0;
- cm = covariance_calculate (all_cov);
+ cm = covariance_calculate_unnormalized (all_cov);
rows = xnmalloc (cov->size1 - 1, sizeof (*rows));
for (i = 0; i < n_all_vars; i++)
}
}
mean_matrix = covariance_moments (all_cov, MOMENT_MEAN);
+ ssize_matrix = covariance_moments (all_cov, MOMENT_NONE);
for (i = 0; i < cov->size1 - 1; i++)
{
- means[i] = gsl_matrix_get (mean_matrix, rows[i], 0);
+ means[i] = gsl_matrix_get (mean_matrix, rows[i], 0)
+ / gsl_matrix_get (ssize_matrix, rows[i], 0);
for (j = 0; j < cov->size2 - 1; j++)
{
gsl_matrix_set (cov, i, j, gsl_matrix_get (cm, rows[i], rows[j]));
gsl_matrix_set (cov, j, i, gsl_matrix_get (cm, rows[j], rows[i]));
}
}
- means[cov->size1 - 1] = gsl_matrix_get (mean_matrix, dep_subscript, 0);
+ means[cov->size1 - 1] = gsl_matrix_get (mean_matrix, dep_subscript, 0)
+ / gsl_matrix_get (ssize_matrix, dep_subscript, 0);
ssizes = covariance_moments (all_cov, MOMENT_NONE);
result = gsl_matrix_get (ssizes, dep_subscript, rows[0]);
for (i = 0; i < cov->size1 - 1; i++)
result = gsl_matrix_get (ssizes, rows[i], dep_subscript);
}
}
+ gsl_matrix_set (cov, cov->size1 - 1, cov->size1 - 1,
+ gsl_matrix_get (cm, dep_subscript, dep_subscript));
free (rows);
return result;
}
{
linreg_set_indep_variable_mean (models[k], i, means[i]);
}
+ linreg_set_depvar_mean (models[k], means[i]);
/*
For large data sets, use QR decomposition.
*/
if (!taint_has_tainted_successor (casereader_get_taint (input)))
{
- subcommand_statistics (cmd->a_statistics, models[k]);
+ subcommand_statistics (cmd->a_statistics, models[k], this_cm);
}
}
else