1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2005, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include <gsl/gsl_cdf.h>
22 #include <gsl/gsl_matrix.h>
24 #include <data/dataset.h>
25 #include <data/casewriter.h>
27 #include "language/command.h"
28 #include "language/lexer/lexer.h"
29 #include "language/lexer/value-parser.h"
30 #include "language/lexer/variable-parser.h"
33 #include "data/casegrouper.h"
34 #include "data/casereader.h"
35 #include "data/dictionary.h"
37 #include "math/covariance.h"
38 #include "math/linreg.h"
39 #include "math/moments.h"
41 #include "libpspp/message.h"
42 #include "libpspp/taint.h"
44 #include "output/tab.h"
47 #define _(msgid) gettext (msgid)
48 #define N_(msgid) msgid
51 #include <gl/intprops.h>
53 #define REG_LARGE_DATA 1000
62 #define STATS_DEFAULT (STATS_R | STATS_COEFF | STATS_ANOVA | STATS_OUTS)
70 const struct variable **vars;
73 const struct variable **dep_vars;
82 struct regression_workspace
84 /* The new variables which will be introduced by /SAVE */
85 const struct variable **predvars;
86 const struct variable **residvars;
88 /* A reader/writer pair to temporarily hold the
89 values of the new variables */
90 struct casewriter *writer;
91 struct casereader *reader;
93 /* Indeces of the new values in the reader/writer (-1 if not applicable) */
97 /* 0, 1 or 2 depending on what new variables are to be created */
101 static void run_regression (const struct regression *cmd,
102 struct regression_workspace *ws,
103 struct casereader *input);
106 /* Return a string based on PREFIX which may be used as the name
107 of a new variable in DICT */
109 reg_get_name (const struct dictionary *dict, const char *prefix)
114 /* XXX handle too-long prefixes */
115 name = xmalloc (strlen (prefix) + INT_BUFSIZE_BOUND (i) + 1);
118 sprintf (name, "%s%d", prefix, i);
119 if (dict_lookup_var (dict, name) == NULL)
125 static const struct variable *
126 create_aux_var (struct dataset *ds, const char *prefix)
128 struct variable *var;
129 struct dictionary *dict = dataset_dict (ds);
130 char *name = reg_get_name (dict, prefix);
131 var = dict_create_var_assert (dict, name, 0);
136 /* Auxilliary data for transformation when /SAVE is entered */
137 struct save_trans_data
140 struct regression_workspace *ws;
144 save_trans_free (void *aux)
146 struct save_trans_data *save_trans_data = aux;
147 free (save_trans_data->ws->predvars);
148 free (save_trans_data->ws->residvars);
150 casereader_destroy (save_trans_data->ws->reader);
151 free (save_trans_data->ws);
152 free (save_trans_data);
157 save_trans_func (void *aux, struct ccase **c, casenumber x UNUSED)
159 struct save_trans_data *save_trans_data = aux;
160 struct regression_workspace *ws = save_trans_data->ws;
161 struct ccase *in = casereader_read (ws->reader);
166 *c = case_unshare (*c);
168 for (k = 0; k < save_trans_data->n_dep_vars; ++k)
170 if (ws->pred_idx != -1)
172 double pred = case_data_idx (in, ws->extras * k + ws->pred_idx)->f;
173 case_data_rw (*c, ws->predvars[k])->f = pred;
176 if (ws->res_idx != -1)
178 double resid = case_data_idx (in, ws->extras * k + ws->res_idx)->f;
179 case_data_rw (*c, ws->residvars[k])->f = resid;
185 return TRNS_CONTINUE;
190 cmd_regression (struct lexer *lexer, struct dataset *ds)
192 struct regression_workspace workspace;
193 struct regression regression;
194 const struct dictionary *dict = dataset_dict (ds);
197 memset (®ression, 0, sizeof (struct regression));
199 regression.stats = STATS_DEFAULT;
200 regression.pred = false;
201 regression.resid = false;
205 /* Accept an optional, completely pointless "/VARIABLES=" */
206 lex_match (lexer, T_SLASH);
207 if (lex_match_id (lexer, "VARIABLES"))
209 if (!lex_force_match (lexer, T_EQUALS))
213 if (!parse_variables_const (lexer, dict,
214 ®ression.vars, ®ression.n_vars,
215 PV_NO_DUPLICATE | PV_NUMERIC))
219 while (lex_token (lexer) != T_ENDCMD)
221 lex_match (lexer, T_SLASH);
223 if (lex_match_id (lexer, "DEPENDENT"))
225 if (!lex_force_match (lexer, T_EQUALS))
228 free (regression.dep_vars);
229 regression.n_dep_vars = 0;
231 if (!parse_variables_const (lexer, dict,
232 ®ression.dep_vars,
233 ®ression.n_dep_vars,
234 PV_NO_DUPLICATE | PV_NUMERIC))
237 else if (lex_match_id (lexer, "METHOD"))
239 lex_match (lexer, T_EQUALS);
241 if (!lex_force_match_id (lexer, "ENTER"))
246 else if (lex_match_id (lexer, "STATISTICS"))
248 lex_match (lexer, T_EQUALS);
250 while (lex_token (lexer) != T_ENDCMD
251 && lex_token (lexer) != T_SLASH)
253 if (lex_match (lexer, T_ALL))
255 regression.stats = ~0;
257 else if (lex_match_id (lexer, "DEFAULTS"))
259 regression.stats |= STATS_DEFAULT;
261 else if (lex_match_id (lexer, "R"))
263 regression.stats |= STATS_R;
265 else if (lex_match_id (lexer, "COEFF"))
267 regression.stats |= STATS_COEFF;
269 else if (lex_match_id (lexer, "ANOVA"))
271 regression.stats |= STATS_ANOVA;
273 else if (lex_match_id (lexer, "BCOV"))
275 regression.stats |= STATS_BCOV;
277 else if (lex_match_id (lexer, "CI"))
279 regression.stats |= STATS_CI;
281 if (lex_match (lexer, T_LPAREN))
285 lex_force_match (lexer, T_RPAREN);
290 lex_error (lexer, NULL);
295 else if (lex_match_id (lexer, "SAVE"))
297 lex_match (lexer, T_EQUALS);
299 while (lex_token (lexer) != T_ENDCMD
300 && lex_token (lexer) != T_SLASH)
302 if (lex_match_id (lexer, "PRED"))
304 regression.pred = true;
306 else if (lex_match_id (lexer, "RESID"))
308 regression.resid = true;
312 lex_error (lexer, NULL);
319 lex_error (lexer, NULL);
324 if (!regression.vars)
326 dict_get_vars (dict, ®ression.vars, ®ression.n_vars, 0);
329 save = regression.pred || regression.resid;
330 workspace.extras = 0;
331 workspace.res_idx = -1;
332 workspace.pred_idx = -1;
333 workspace.writer = NULL;
334 workspace.reader = NULL;
338 struct caseproto *proto = caseproto_create ();
340 if (regression.resid)
343 workspace.res_idx = 0;
344 workspace.residvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.residvars));
346 for (i = 0; i < regression.n_dep_vars; ++i)
348 workspace.residvars[i] = create_aux_var (ds, "RES");
349 proto = caseproto_add_width (proto, 0);
356 workspace.pred_idx = 1;
357 workspace.predvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.predvars));
359 for (i = 0; i < regression.n_dep_vars; ++i)
361 workspace.predvars[i] = create_aux_var (ds, "PRED");
362 proto = caseproto_add_width (proto, 0);
366 if (proc_make_temporary_transformations_permanent (ds))
367 msg (SW, _("REGRESSION with SAVE ignores TEMPORARY. "
368 "Temporary transformations will be made permanent."));
370 workspace.writer = autopaging_writer_create (proto);
371 caseproto_unref (proto);
376 struct casegrouper *grouper;
377 struct casereader *group;
380 grouper = casegrouper_create_splits (proc_open_filtering (ds, !save), dict);
383 while (casegrouper_get_next_group (grouper, &group))
385 run_regression (®ression,
390 ok = casegrouper_destroy (grouper);
391 ok = proc_commit (ds) && ok;
394 if (workspace.writer)
396 struct save_trans_data *save_trans_data = xmalloc (sizeof *save_trans_data);
397 struct casereader *r = casewriter_make_reader (workspace.writer);
398 workspace.writer = NULL;
399 workspace.reader = r;
400 save_trans_data->ws = xmalloc (sizeof (workspace));
401 memcpy (save_trans_data->ws, &workspace, sizeof (workspace));
402 save_trans_data->n_dep_vars = regression.n_dep_vars;
404 add_transformation (ds, save_trans_func, save_trans_free, save_trans_data);
408 free (regression.vars);
409 free (regression.dep_vars);
414 free (regression.vars);
415 free (regression.dep_vars);
419 /* Return the size of the union of dependent and independent variables */
421 get_n_all_vars (const struct regression *cmd)
423 size_t result = cmd->n_vars;
427 result += cmd->n_dep_vars;
428 for (i = 0; i < cmd->n_dep_vars; i++)
430 for (j = 0; j < cmd->n_vars; j++)
432 if (cmd->vars[j] == cmd->dep_vars[i])
441 /* Fill VARS with the union of dependent and independent variables */
443 fill_all_vars (const struct variable **vars, const struct regression *cmd)
447 for (i = 0; i < cmd->n_vars; i++)
449 vars[i] = cmd->vars[i];
452 for (i = 0; i < cmd->n_dep_vars; i++)
456 for (j = 0; j < cmd->n_vars; j++)
458 if (cmd->dep_vars[i] == cmd->vars[j])
466 vars[cmd->n_vars + x++] = cmd->dep_vars[i];
472 Is variable k the dependent variable?
475 is_depvar (const struct regression *cmd, size_t k, const struct variable *v)
477 return v == cmd->vars[k];
481 /* Identify the explanatory variables in v_variables. Returns
482 the number of independent variables. */
484 identify_indep_vars (const struct regression *cmd,
485 const struct variable **indep_vars,
486 const struct variable *depvar)
488 int n_indep_vars = 0;
491 for (i = 0; i < cmd->n_vars; i++)
492 if (!is_depvar (cmd, i, depvar))
493 indep_vars[n_indep_vars++] = cmd->vars[i];
494 if ((n_indep_vars < 1) && is_depvar (cmd, 0, depvar))
497 There is only one independent variable, and it is the same
498 as the dependent variable. Print a warning and continue.
502 ("The dependent variable is equal to the independent variable. "
503 "The least squares line is therefore Y=X. "
504 "Standard errors and related statistics may be meaningless."));
506 indep_vars[0] = cmd->vars[0];
513 fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
514 const struct variable **vars,
515 size_t n_vars, const struct variable *dep_var,
516 const struct variable **all_vars, size_t n_all_vars,
521 size_t dep_subscript;
523 const gsl_matrix *ssizes;
524 const gsl_matrix *mean_matrix;
525 const gsl_matrix *ssize_matrix;
528 const gsl_matrix *cm = covariance_calculate_unnormalized (all_cov);
533 rows = xnmalloc (cov->size1 - 1, sizeof (*rows));
535 for (i = 0; i < n_all_vars; i++)
537 for (j = 0; j < n_vars; j++)
539 if (vars[j] == all_vars[i])
544 if (all_vars[i] == dep_var)
549 mean_matrix = covariance_moments (all_cov, MOMENT_MEAN);
550 ssize_matrix = covariance_moments (all_cov, MOMENT_NONE);
551 for (i = 0; i < cov->size1 - 1; i++)
553 means[i] = gsl_matrix_get (mean_matrix, rows[i], 0)
554 / gsl_matrix_get (ssize_matrix, rows[i], 0);
555 for (j = 0; j < cov->size2 - 1; j++)
557 gsl_matrix_set (cov, i, j, gsl_matrix_get (cm, rows[i], rows[j]));
558 gsl_matrix_set (cov, j, i, gsl_matrix_get (cm, rows[j], rows[i]));
561 means[cov->size1 - 1] = gsl_matrix_get (mean_matrix, dep_subscript, 0)
562 / gsl_matrix_get (ssize_matrix, dep_subscript, 0);
563 ssizes = covariance_moments (all_cov, MOMENT_NONE);
564 result = gsl_matrix_get (ssizes, dep_subscript, rows[0]);
565 for (i = 0; i < cov->size1 - 1; i++)
567 gsl_matrix_set (cov, i, cov->size1 - 1,
568 gsl_matrix_get (cm, rows[i], dep_subscript));
569 gsl_matrix_set (cov, cov->size1 - 1, i,
570 gsl_matrix_get (cm, rows[i], dep_subscript));
571 if (result > gsl_matrix_get (ssizes, rows[i], dep_subscript))
573 result = gsl_matrix_get (ssizes, rows[i], dep_subscript);
576 gsl_matrix_set (cov, cov->size1 - 1, cov->size1 - 1,
577 gsl_matrix_get (cm, dep_subscript, dep_subscript));
585 STATISTICS subcommand output functions.
587 static void reg_stats_r (const linreg *, const struct variable *);
588 static void reg_stats_coeff (const linreg *, const gsl_matrix *, const struct variable *);
589 static void reg_stats_anova (const linreg *, const struct variable *);
590 static void reg_stats_bcov (const linreg *, const struct variable *);
594 subcommand_statistics (const struct regression *cmd, const linreg * c, const gsl_matrix * cm,
595 const struct variable *var)
597 if (cmd->stats & STATS_R)
598 reg_stats_r (c, var);
600 if (cmd->stats & STATS_ANOVA)
601 reg_stats_anova (c, var);
603 if (cmd->stats & STATS_COEFF)
604 reg_stats_coeff (c, cm, var);
606 if (cmd->stats & STATS_BCOV)
607 reg_stats_bcov (c, var);
612 run_regression (const struct regression *cmd,
613 struct regression_workspace *ws,
614 struct casereader *input)
621 struct covariance *cov;
622 struct casereader *reader;
623 size_t n_all_vars = get_n_all_vars (cmd);
624 const struct variable **all_vars = xnmalloc (n_all_vars, sizeof (*all_vars));
626 double *means = xnmalloc (n_all_vars, sizeof (*means));
628 fill_all_vars (all_vars, cmd);
629 cov = covariance_1pass_create (n_all_vars, all_vars,
630 dict_get_weight (dataset_dict (cmd->ds)),
633 reader = casereader_clone (input);
634 reader = casereader_create_filter_missing (reader, all_vars, n_all_vars,
639 struct casereader *r = casereader_clone (reader);
641 for (; (c = casereader_read (r)) != NULL; case_unref (c))
643 covariance_accumulate (cov, c);
645 casereader_destroy (r);
648 models = xcalloc (cmd->n_dep_vars, sizeof (*models));
649 for (k = 0; k < cmd->n_dep_vars; k++)
651 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
652 const struct variable *dep_var = cmd->dep_vars[k];
653 int n_indep = identify_indep_vars (cmd, vars, dep_var);
654 gsl_matrix *this_cm = gsl_matrix_alloc (n_indep + 1, n_indep + 1);
655 double n_data = fill_covariance (this_cm, cov, vars, n_indep,
656 dep_var, all_vars, n_all_vars, means);
657 models[k] = linreg_alloc (dep_var, vars, n_data, n_indep);
658 models[k]->depvar = dep_var;
659 for (i = 0; i < n_indep; i++)
661 linreg_set_indep_variable_mean (models[k], i, means[i]);
663 linreg_set_depvar_mean (models[k], means[i]);
665 For large data sets, use QR decomposition.
667 if (n_data > sqrt (n_indep) && n_data > REG_LARGE_DATA)
669 models[k]->method = LINREG_QR;
675 Find the least-squares estimates and other statistics.
677 linreg_fit (this_cm, models[k]);
679 if (!taint_has_tainted_successor (casereader_get_taint (input)))
681 subcommand_statistics (cmd, models[k], this_cm, dep_var);
686 msg (SE, _("No valid data found. This command was skipped."));
688 gsl_matrix_free (this_cm);
695 struct casereader *r = casereader_clone (reader);
697 for (; (c = casereader_read (r)) != NULL; case_unref (c))
699 struct ccase *outc = case_clone (c);
700 for (k = 0; k < cmd->n_dep_vars; k++)
702 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
703 const struct variable *dep_var = cmd->dep_vars[k];
704 int n_indep = identify_indep_vars (cmd, vars, dep_var);
705 double *vals = xnmalloc (n_indep, sizeof (*vals));
706 for (i = 0; i < n_indep; i++)
708 const union value *tmp = case_data (c, vars[i]);
714 double pred = linreg_predict (models[k], vals, n_indep);
715 case_data_rw_idx (outc, k * ws->extras + ws->pred_idx)->f = pred;
720 double obs = case_data (c, models[k]->depvar)->f;
721 double res = linreg_residual (models[k], obs, vals, n_indep);
722 case_data_rw_idx (outc, k * ws->extras + ws->res_idx)->f = res;
727 casewriter_write (ws->writer, outc);
729 casereader_destroy (r);
732 casereader_destroy (reader);
734 for (k = 0; k < cmd->n_dep_vars; k++)
736 linreg_unref (models[k]);
742 casereader_destroy (input);
743 covariance_destroy (cov);
750 reg_stats_r (const linreg * c, const struct variable *var)
760 rsq = linreg_ssreg (c) / linreg_sst (c);
762 (1.0 - rsq) * linreg_n_coeffs (c) / (linreg_n_obs (c) -
763 linreg_n_coeffs (c) - 1);
764 std_error = sqrt (linreg_mse (c));
765 t = tab_create (n_cols, n_rows);
766 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
767 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
768 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
769 tab_vline (t, TAL_0, 1, 0, 0);
771 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("R"));
772 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("R Square"));
773 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Adjusted R Square"));
774 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error of the Estimate"));
775 tab_double (t, 1, 1, TAB_RIGHT, sqrt (rsq), NULL);
776 tab_double (t, 2, 1, TAB_RIGHT, rsq, NULL);
777 tab_double (t, 3, 1, TAB_RIGHT, adjrsq, NULL);
778 tab_double (t, 4, 1, TAB_RIGHT, std_error, NULL);
779 tab_title (t, _("Model Summary (%s)"), var_to_string (var));
784 Table showing estimated regression coefficients.
787 reg_stats_coeff (const linreg * c, const gsl_matrix *cov, const struct variable *var)
799 const struct variable *v;
803 n_rows = linreg_n_coeffs (c) + 3;
805 t = tab_create (n_cols, n_rows);
806 tab_headers (t, 2, 0, 1, 0);
807 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
808 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
809 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
810 tab_vline (t, TAL_0, 1, 0, 0);
812 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("B"));
813 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
814 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Beta"));
815 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
816 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Sig."));
817 tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("(Constant)"));
818 tab_double (t, 2, 1, 0, linreg_intercept (c), NULL);
819 std_err = sqrt (gsl_matrix_get (linreg_cov (c), 0, 0));
820 tab_double (t, 3, 1, 0, std_err, NULL);
821 tab_double (t, 4, 1, 0, 0.0, NULL);
822 t_stat = linreg_intercept (c) / std_err;
823 tab_double (t, 5, 1, 0, t_stat, NULL);
825 2 * gsl_cdf_tdist_Q (fabs (t_stat),
826 (double) (linreg_n_obs (c) - linreg_n_coeffs (c)));
827 tab_double (t, 6, 1, 0, pval, NULL);
828 for (j = 0; j < linreg_n_coeffs (c); j++)
831 ds_init_empty (&tstr);
834 v = linreg_indep_var (c, j);
835 label = var_to_string (v);
836 /* Do not overwrite the variable's name. */
837 ds_put_cstr (&tstr, label);
838 tab_text (t, 1, this_row, TAB_CENTER, ds_cstr (&tstr));
840 Regression coefficients.
842 tab_double (t, 2, this_row, 0, linreg_coeff (c, j), NULL);
844 Standard error of the coefficients.
846 std_err = sqrt (gsl_matrix_get (linreg_cov (c), j + 1, j + 1));
847 tab_double (t, 3, this_row, 0, std_err, NULL);
849 Standardized coefficient, i.e., regression coefficient
850 if all variables had unit variance.
852 beta = sqrt (gsl_matrix_get (cov, j, j));
853 beta *= linreg_coeff (c, j) /
854 sqrt (gsl_matrix_get (cov, cov->size1 - 1, cov->size2 - 1));
855 tab_double (t, 4, this_row, 0, beta, NULL);
858 Test statistic for H0: coefficient is 0.
860 t_stat = linreg_coeff (c, j) / std_err;
861 tab_double (t, 5, this_row, 0, t_stat, NULL);
863 P values for the test statistic above.
866 2 * gsl_cdf_tdist_Q (fabs (t_stat),
867 (double) (linreg_n_obs (c) -
868 linreg_n_coeffs (c) - 1));
869 tab_double (t, 6, this_row, 0, pval, NULL);
872 tab_title (t, _("Coefficients (%s)"), var_to_string (var));
877 Display the ANOVA table.
880 reg_stats_anova (const linreg * c, const struct variable *var)
884 const double msm = linreg_ssreg (c) / linreg_dfmodel (c);
885 const double mse = linreg_mse (c);
886 const double F = msm / mse;
887 const double pval = gsl_cdf_fdist_Q (F, c->dfm, c->dfe);
892 t = tab_create (n_cols, n_rows);
893 tab_headers (t, 2, 0, 1, 0);
895 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
897 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
898 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
899 tab_vline (t, TAL_0, 1, 0, 0);
901 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
902 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
903 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
904 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
905 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Sig."));
907 tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("Regression"));
908 tab_text (t, 1, 2, TAB_LEFT | TAT_TITLE, _("Residual"));
909 tab_text (t, 1, 3, TAB_LEFT | TAT_TITLE, _("Total"));
911 /* Sums of Squares */
912 tab_double (t, 2, 1, 0, linreg_ssreg (c), NULL);
913 tab_double (t, 2, 3, 0, linreg_sst (c), NULL);
914 tab_double (t, 2, 2, 0, linreg_sse (c), NULL);
917 /* Degrees of freedom */
918 tab_text_format (t, 3, 1, TAB_RIGHT, "%g", c->dfm);
919 tab_text_format (t, 3, 2, TAB_RIGHT, "%g", c->dfe);
920 tab_text_format (t, 3, 3, TAB_RIGHT, "%g", c->dft);
923 tab_double (t, 4, 1, TAB_RIGHT, msm, NULL);
924 tab_double (t, 4, 2, TAB_RIGHT, mse, NULL);
926 tab_double (t, 5, 1, 0, F, NULL);
928 tab_double (t, 6, 1, 0, pval, NULL);
930 tab_title (t, _("ANOVA (%s)"), var_to_string (var));
936 reg_stats_bcov (const linreg * c, const struct variable *var)
948 n_cols = c->n_indeps + 1 + 2;
949 n_rows = 2 * (c->n_indeps + 1);
950 t = tab_create (n_cols, n_rows);
951 tab_headers (t, 2, 0, 1, 0);
952 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
953 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
954 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
955 tab_vline (t, TAL_0, 1, 0, 0);
956 tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Model"));
957 tab_text (t, 1, 1, TAB_CENTER | TAT_TITLE, _("Covariances"));
958 for (i = 0; i < linreg_n_coeffs (c); i++)
960 const struct variable *v = linreg_indep_var (c, i);
961 label = var_to_string (v);
962 tab_text (t, 2, i, TAB_CENTER, label);
963 tab_text (t, i + 2, 0, TAB_CENTER, label);
964 for (k = 1; k < linreg_n_coeffs (c); k++)
966 col = (i <= k) ? k : i;
967 row = (i <= k) ? i : k;
968 tab_double (t, k + 2, i, TAB_CENTER,
969 gsl_matrix_get (c->cov, row, col), NULL);
972 tab_title (t, _("Coefficient Correlations (%s)"), var_to_string (var));