Fix some typos (found by codespell)
[pspp] / src / language / stats / regression.c
index b2ba15d63a7add4638301929f8bd1d10e7283bcd..72649ba4ac633667d678f188927cbf0cb339dc6e 100644 (file)
@@ -20,6 +20,7 @@
 #include <float.h>
 #include <stdbool.h>
 
+#include <gsl/gsl_math.h>
 #include <gsl/gsl_cdf.h>
 #include <gsl/gsl_matrix.h>
 
@@ -52,8 +53,6 @@
 
 #include <gl/intprops.h>
 
-#define REG_LARGE_DATA 1000
-
 #define STATS_R      1
 #define STATS_COEFF  2
 #define STATS_ANOVA  4
@@ -138,7 +137,7 @@ create_aux_var (struct dataset *ds, const char *prefix)
   return var;
 }
 
-/* Auxilliary data for transformation when /SAVE is entered */
+/* Auxiliary data for transformation when /SAVE is entered */
 struct save_trans_data
 {
   int n_dep_vars;
@@ -552,7 +551,6 @@ identify_indep_vars (const struct regression *cmd,
   return n_indep_vars;
 }
 
-
 static double
 fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
                  const struct variable **vars,
@@ -628,14 +626,14 @@ fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
 /*
   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)
@@ -658,7 +656,7 @@ run_regression (const struct regression *cmd,
                 struct casereader *input)
 {
   size_t i;
-  linreg **models;
+  struct linreg **models;
 
   int k;
   struct ccase *c;
@@ -699,20 +697,11 @@ run_regression (const struct regression *cmd,
       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)
         {
           /*
@@ -761,7 +750,7 @@ run_regression (const struct regression *cmd,
 
               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;
                 }
@@ -791,7 +780,7 @@ run_regression (const struct regression *cmd,
 
 
 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;
@@ -828,7 +817,7 @@ reg_stats_r (const linreg * c, const struct variable *var)
   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;
@@ -958,14 +947,15 @@ reg_stats_coeff (const linreg * c, const gsl_matrix *cov, const struct variable
   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;
 
@@ -996,9 +986,9 @@ reg_stats_anova (const linreg * c, const struct variable *var)
 
 
   /* 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);
@@ -1014,7 +1004,7 @@ reg_stats_anova (const linreg * c, const struct variable *var)
 
 
 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;
@@ -1026,8 +1016,8 @@ reg_stats_bcov (const linreg * c, const struct variable *var)
   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);
@@ -1047,7 +1037,7 @@ reg_stats_bcov (const linreg * c, const struct variable *var)
           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));