#include <float.h>
#include <stdbool.h>
+#include <gsl/gsl_math.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_matrix.h>
#include <gl/intprops.h>
-#define REG_LARGE_DATA 1000
-
#define STATS_R 1
#define STATS_COEFF 2
#define STATS_ANOVA 4
return n_indep_vars;
}
-
static double
fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
const struct variable **vars,
/*
STATISTICS subcommand output functions.
*/
-static void reg_stats_r (const linreg *, const struct variable *);
-static void reg_stats_coeff (const linreg *, const gsl_matrix *, const struct variable *, const struct regression *);
-static void reg_stats_anova (const linreg *, const struct variable *);
-static void reg_stats_bcov (const linreg *, const struct variable *);
+static void reg_stats_r (const struct linreg *, const struct variable *);
+static void reg_stats_coeff (const struct linreg *, const gsl_matrix *, const struct variable *, const struct regression *);
+static void reg_stats_anova (const struct linreg *, const struct variable *);
+static void reg_stats_bcov (const struct linreg *, const struct variable *);
static void
-subcommand_statistics (const struct regression *cmd, const linreg * c, const gsl_matrix * cm,
+subcommand_statistics (const struct regression *cmd, const struct linreg * c, const gsl_matrix * cm,
const struct variable *var)
{
if (cmd->stats & STATS_R)
struct casereader *input)
{
size_t i;
- linreg **models;
+ struct linreg **models;
int k;
struct ccase *c;
double n_data = fill_covariance (this_cm, cov, vars, n_indep,
dep_var, all_vars, n_all_vars, means);
models[k] = linreg_alloc (dep_var, vars, n_data, n_indep, cmd->origin);
- models[k]->depvar = dep_var;
for (i = 0; i < n_indep; i++)
{
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 (n_data > sqrt (n_indep) && n_data > REG_LARGE_DATA)
- {
- models[k]->method = LINREG_QR;
- }
-
if (n_data > 0)
{
/*
if (cmd->resid)
{
- double obs = case_data (c, models[k]->depvar)->f;
+ double obs = case_data (c, linreg_dep_var (models[k]))->f;
double res = linreg_residual (models[k], obs, vals, n_indep);
case_data_rw_idx (outc, k * ws->extras + ws->res_idx)->f = res;
}
static void
-reg_stats_r (const linreg * c, const struct variable *var)
+reg_stats_r (const struct linreg * c, const struct variable *var)
{
struct tab_table *t;
int n_rows = 2;
Table showing estimated regression coefficients.
*/
static void
-reg_stats_coeff (const linreg * c, const gsl_matrix *cov, const struct variable *var, const struct regression *cmd)
+reg_stats_coeff (const struct linreg * c, const gsl_matrix *cov, const struct variable *var, const struct regression *cmd)
{
size_t j;
int n_cols = 7;
Display the ANOVA table.
*/
static void
-reg_stats_anova (const linreg * c, const struct variable *var)
+reg_stats_anova (const struct linreg * c, const struct variable *var)
{
int n_cols = 7;
int n_rows = 4;
const double msm = linreg_ssreg (c) / linreg_dfmodel (c);
const double mse = linreg_mse (c);
const double F = msm / mse;
- const double pval = gsl_cdf_fdist_Q (F, c->dfm, c->dfe);
+ const double pval = gsl_cdf_fdist_Q (F, linreg_dfmodel (c),
+ linreg_dferror (c));
struct tab_table *t;
/* Degrees of freedom */
- tab_text_format (t, 3, 1, TAB_RIGHT, "%.*g", DBL_DIG + 1, c->dfm);
- tab_text_format (t, 3, 2, TAB_RIGHT, "%.*g", DBL_DIG + 1, c->dfe);
- tab_text_format (t, 3, 3, TAB_RIGHT, "%.*g", DBL_DIG + 1, c->dft);
+ tab_text_format (t, 3, 1, TAB_RIGHT, "%.*g", DBL_DIG + 1, linreg_dfmodel (c));
+ tab_text_format (t, 3, 2, TAB_RIGHT, "%.*g", DBL_DIG + 1, linreg_dferror (c));
+ tab_text_format (t, 3, 3, TAB_RIGHT, "%.*g", DBL_DIG + 1, linreg_dftotal (c));
/* Mean Squares */
tab_double (t, 4, 1, TAB_RIGHT, msm, NULL, RC_OTHER);
static void
-reg_stats_bcov (const linreg * c, const struct variable *var)
+reg_stats_bcov (const struct linreg * c, const struct variable *var)
{
int n_cols;
int n_rows;
struct tab_table *t;
assert (c != NULL);
- n_cols = c->n_indeps + 1 + 2;
- n_rows = 2 * (c->n_indeps + 1);
+ n_cols = linreg_n_indeps (c) + 1 + 2;
+ n_rows = 2 * (linreg_n_indeps (c) + 1);
t = tab_create (n_cols, n_rows);
tab_headers (t, 2, 0, 1, 0);
tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
col = (i <= k) ? k : i;
row = (i <= k) ? i : k;
tab_double (t, k + 2, i, TAB_CENTER,
- gsl_matrix_get (c->cov, row, col), NULL, RC_OTHER);
+ gsl_matrix_get (linreg_cov (c), row, col), NULL, RC_OTHER);
}
}
tab_title (t, _("Coefficient Correlations (%s)"), var_to_string (var));