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
59 const struct variable **vars;
62 const struct variable **dep_vars;
80 struct regression_workspace
82 struct per_split_ws *psw;
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 per_split_ws *psw,
103 struct regression_workspace *ws,
104 struct casereader *input);
107 /* Return a string based on PREFIX which may be used as the name
108 of a new variable in DICT */
110 reg_get_name (const struct dictionary *dict, const char *prefix)
115 /* XXX handle too-long prefixes */
116 name = xmalloc (strlen (prefix) + INT_BUFSIZE_BOUND (i) + 1);
119 sprintf (name, "%s%d", prefix, i);
120 if (dict_lookup_var (dict, name) == NULL)
126 static const struct variable *
127 create_aux_var (struct dataset *ds, const char *prefix)
129 struct variable *var;
130 struct dictionary *dict = dataset_dict (ds);
131 char *name = reg_get_name (dict, prefix);
132 var = dict_create_var_assert (dict, name, 0);
137 /* Auxilliary data for transformation when /SAVE is entered */
138 struct save_trans_data
141 struct regression_workspace *ws;
145 save_trans_free (void *aux)
147 struct save_trans_data *save_trans_data = aux;
148 free (save_trans_data->ws->predvars);
149 free (save_trans_data->ws->residvars);
151 casereader_destroy (save_trans_data->ws->reader);
152 free (save_trans_data->ws);
153 free (save_trans_data);
158 save_trans_func (void *aux, struct ccase **c, casenumber x UNUSED)
160 struct save_trans_data *save_trans_data = aux;
161 struct regression_workspace *ws = save_trans_data->ws;
162 struct ccase *in = casereader_read (ws->reader);
167 *c = case_unshare (*c);
169 for (k = 0; k < save_trans_data->n_dep_vars; ++k)
171 if (ws->pred_idx != -1)
173 double pred = case_data_idx (in, ws->extras * k + ws->pred_idx)->f;
174 case_data_rw (*c, ws->predvars[k])->f = pred;
177 if (ws->res_idx != -1)
179 double resid = case_data_idx (in, ws->extras * k + ws->res_idx)->f;
180 case_data_rw (*c, ws->residvars[k])->f = resid;
186 return TRNS_CONTINUE;
191 cmd_regression (struct lexer *lexer, struct dataset *ds)
195 struct regression_workspace workspace;
196 struct regression regression;
197 const struct dictionary *dict = dataset_dict (ds);
199 workspace.psw = NULL;
201 memset (®ression, 0, sizeof (struct regression));
203 regression.anova = true;
204 regression.coeff = true;
207 regression.pred = false;
208 regression.resid = false;
212 /* Accept an optional, completely pointless "/VARIABLES=" */
213 lex_match (lexer, T_SLASH);
214 if (lex_match_id (lexer, "VARIABLES"))
216 if (!lex_force_match (lexer, T_EQUALS))
220 if (!parse_variables_const (lexer, dict,
221 ®ression.vars, ®ression.n_vars,
222 PV_NO_DUPLICATE | PV_NUMERIC))
226 while (lex_token (lexer) != T_ENDCMD)
228 lex_match (lexer, T_SLASH);
230 if (lex_match_id (lexer, "DEPENDENT"))
232 if (!lex_force_match (lexer, T_EQUALS))
235 if (!parse_variables_const (lexer, dict,
236 ®ression.dep_vars,
237 ®ression.n_dep_vars,
238 PV_NO_DUPLICATE | PV_NUMERIC))
241 else if (lex_match_id (lexer, "METHOD"))
243 lex_match (lexer, T_EQUALS);
245 if (!lex_force_match_id (lexer, "ENTER"))
250 else if (lex_match_id (lexer, "STATISTICS"))
252 lex_match (lexer, T_EQUALS);
254 while (lex_token (lexer) != T_ENDCMD
255 && lex_token (lexer) != T_SLASH)
257 if (lex_match (lexer, T_ALL))
260 else if (lex_match_id (lexer, "DEFAULTS"))
263 else if (lex_match_id (lexer, "R"))
266 else if (lex_match_id (lexer, "COEFF"))
269 else if (lex_match_id (lexer, "ANOVA"))
272 else if (lex_match_id (lexer, "BCOV"))
277 lex_error (lexer, NULL);
282 else if (lex_match_id (lexer, "SAVE"))
284 lex_match (lexer, T_EQUALS);
286 while (lex_token (lexer) != T_ENDCMD
287 && lex_token (lexer) != T_SLASH)
289 if (lex_match_id (lexer, "PRED"))
291 regression.pred = true;
293 else if (lex_match_id (lexer, "RESID"))
295 regression.resid = true;
299 lex_error (lexer, NULL);
306 lex_error (lexer, NULL);
311 if (!regression.vars)
313 dict_get_vars (dict, ®ression.vars, ®ression.n_vars, 0);
316 save = regression.pred || regression.resid;
317 workspace.extras = 0;
318 workspace.res_idx = -1;
319 workspace.pred_idx = -1;
320 workspace.writer = NULL;
321 workspace.reader = NULL;
325 struct caseproto *proto = caseproto_create ();
327 if (regression.resid)
330 workspace.res_idx = 0;
331 workspace.residvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.residvars));
333 for (i = 0; i < regression.n_dep_vars; ++i)
335 workspace.residvars[i] = create_aux_var (ds, "RES");
336 proto = caseproto_add_width (proto, 0);
343 workspace.pred_idx = 1;
344 workspace.predvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.predvars));
346 for (i = 0; i < regression.n_dep_vars; ++i)
348 workspace.predvars[i] = create_aux_var (ds, "PRED");
349 proto = caseproto_add_width (proto, 0);
353 if (proc_make_temporary_transformations_permanent (ds))
354 msg (SW, _("REGRESSION with SAVE ignores TEMPORARY. "
355 "Temporary transformations will be made permanent."));
357 workspace.writer = autopaging_writer_create (proto);
358 caseproto_unref (proto);
364 struct casegrouper *grouper;
365 struct casereader *group;
368 grouper = casegrouper_create_splits (proc_open_filtering (ds, !save), dict);
371 while (casegrouper_get_next_group (grouper, &group))
373 workspace.psw = xrealloc (workspace.psw, ++n_splits * sizeof (*workspace.psw));
375 run_regression (®ression, &workspace.psw[n_splits - 1],
380 ok = casegrouper_destroy (grouper);
381 ok = proc_commit (ds) && ok;
384 if (workspace.writer)
386 struct save_trans_data *save_trans_data = xmalloc (sizeof *save_trans_data);
387 struct casereader *r = casewriter_make_reader (workspace.writer);
388 workspace.writer = NULL;
389 workspace.reader = r;
390 save_trans_data->ws = xmalloc (sizeof (workspace));
391 memcpy (save_trans_data->ws, &workspace, sizeof (workspace));
392 save_trans_data->n_dep_vars = regression.n_dep_vars;
394 add_transformation (ds, save_trans_func, save_trans_free, save_trans_data);
397 for (i = 0; i < n_splits; ++i)
401 for (k = 0; k < regression.n_dep_vars; ++k)
402 linreg_unref (workspace.psw[i].models[k]);
404 free (workspace.psw[i].models);
406 free (workspace.psw);
409 free (regression.vars);
410 free (regression.dep_vars);
415 free (regression.vars);
416 free (regression.dep_vars);
420 /* Return the size of the union of dependent and independent variables */
422 get_n_all_vars (const struct regression *cmd)
424 size_t result = cmd->n_vars;
428 result += cmd->n_dep_vars;
429 for (i = 0; i < cmd->n_dep_vars; i++)
431 for (j = 0; j < cmd->n_vars; j++)
433 if (cmd->vars[j] == cmd->dep_vars[i])
442 /* Fill VARS with the union of dependent and independent variables */
444 fill_all_vars (const struct variable **vars, const struct regression *cmd)
450 for (i = 0; i < cmd->n_vars; i++)
452 vars[i] = cmd->vars[i];
454 for (i = 0; i < cmd->n_dep_vars; i++)
457 for (j = 0; j < cmd->n_vars; j++)
459 if (cmd->dep_vars[i] == cmd->vars[j])
467 vars[i + cmd->n_vars] = cmd->dep_vars[i];
473 Is variable k the dependent variable?
476 is_depvar (const struct regression *cmd, size_t k, const struct variable *v)
478 return v == cmd->vars[k];
482 /* Identify the explanatory variables in v_variables. Returns
483 the number of independent variables. */
485 identify_indep_vars (const struct regression *cmd,
486 const struct variable **indep_vars,
487 const struct variable *depvar)
489 int n_indep_vars = 0;
492 for (i = 0; i < cmd->n_vars; i++)
493 if (!is_depvar (cmd, i, depvar))
494 indep_vars[n_indep_vars++] = cmd->vars[i];
495 if ((n_indep_vars < 1) && is_depvar (cmd, 0, depvar))
498 There is only one independent variable, and it is the same
499 as the dependent variable. Print a warning and continue.
503 ("The dependent variable is equal to the independent variable."
504 "The least squares line is therefore Y=X."
505 "Standard errors and related statistics may be meaningless."));
507 indep_vars[0] = cmd->vars[0];
514 fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
515 const struct variable **vars,
516 size_t n_vars, const struct variable *dep_var,
517 const struct variable **all_vars, size_t n_all_vars,
522 size_t dep_subscript;
524 const gsl_matrix *ssizes;
525 const gsl_matrix *mean_matrix;
526 const gsl_matrix *ssize_matrix;
529 const gsl_matrix *cm = covariance_calculate_unnormalized (all_cov);
534 rows = xnmalloc (cov->size1 - 1, sizeof (*rows));
536 for (i = 0; i < n_all_vars; i++)
538 for (j = 0; j < n_vars; j++)
540 if (vars[j] == all_vars[i])
545 if (all_vars[i] == dep_var)
550 mean_matrix = covariance_moments (all_cov, MOMENT_MEAN);
551 ssize_matrix = covariance_moments (all_cov, MOMENT_NONE);
552 for (i = 0; i < cov->size1 - 1; i++)
554 means[i] = gsl_matrix_get (mean_matrix, rows[i], 0)
555 / gsl_matrix_get (ssize_matrix, rows[i], 0);
556 for (j = 0; j < cov->size2 - 1; j++)
558 gsl_matrix_set (cov, i, j, gsl_matrix_get (cm, rows[i], rows[j]));
559 gsl_matrix_set (cov, j, i, gsl_matrix_get (cm, rows[j], rows[i]));
562 means[cov->size1 - 1] = gsl_matrix_get (mean_matrix, dep_subscript, 0)
563 / gsl_matrix_get (ssize_matrix, dep_subscript, 0);
564 ssizes = covariance_moments (all_cov, MOMENT_NONE);
565 result = gsl_matrix_get (ssizes, dep_subscript, rows[0]);
566 for (i = 0; i < cov->size1 - 1; i++)
568 gsl_matrix_set (cov, i, cov->size1 - 1,
569 gsl_matrix_get (cm, rows[i], dep_subscript));
570 gsl_matrix_set (cov, cov->size1 - 1, i,
571 gsl_matrix_get (cm, rows[i], dep_subscript));
572 if (result > gsl_matrix_get (ssizes, rows[i], dep_subscript))
574 result = gsl_matrix_get (ssizes, rows[i], dep_subscript);
577 gsl_matrix_set (cov, cov->size1 - 1, cov->size1 - 1,
578 gsl_matrix_get (cm, dep_subscript, dep_subscript));
586 STATISTICS subcommand output functions.
588 static void reg_stats_r (const linreg *, const struct variable *);
589 static void reg_stats_coeff (const linreg *, const gsl_matrix *, const struct variable *);
590 static void reg_stats_anova (const linreg *, const struct variable *);
591 static void reg_stats_bcov (const linreg *, const struct variable *);
595 subcommand_statistics (const struct regression *cmd, const linreg * c, const gsl_matrix * cm,
596 const struct variable *var)
599 reg_stats_r (c, var);
602 reg_stats_anova (c, var);
605 reg_stats_coeff (c, cm, var);
608 reg_stats_bcov (c, var);
613 run_regression (const struct regression *cmd,
614 struct per_split_ws *psw,
615 struct regression_workspace *ws,
616 struct casereader *input)
622 struct covariance *cov;
623 struct casereader *reader;
624 size_t n_all_vars = get_n_all_vars (cmd);
625 const struct variable **all_vars = xnmalloc (n_all_vars, sizeof (*all_vars));
627 double *means = xnmalloc (n_all_vars, sizeof (*means));
629 fill_all_vars (all_vars, cmd);
630 cov = covariance_1pass_create (n_all_vars, all_vars,
631 dict_get_weight (dataset_dict (cmd->ds)),
634 reader = casereader_clone (input);
635 reader = casereader_create_filter_missing (reader, all_vars, n_all_vars,
640 struct casereader *r = casereader_clone (reader);
642 for (; (c = casereader_read (r)) != NULL; case_unref (c))
644 covariance_accumulate (cov, c);
646 casereader_destroy (r);
649 psw->models = xcalloc (cmd->n_dep_vars, sizeof (*psw->models));
650 for (k = 0; k < cmd->n_dep_vars; k++)
653 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
654 const struct variable *dep_var = cmd->dep_vars[k];
655 int n_indep = identify_indep_vars (cmd, vars, dep_var);
656 gsl_matrix *this_cm = gsl_matrix_alloc (n_indep + 1, n_indep + 1);
657 double n_data = fill_covariance (this_cm, cov, vars, n_indep,
658 dep_var, all_vars, n_all_vars, means);
659 psw->models[k] = linreg_alloc (dep_var, vars, n_data, n_indep);
660 psw->models[k]->depvar = dep_var;
661 for (i = 0; i < n_indep; i++)
663 linreg_set_indep_variable_mean (psw->models[k], i, means[i]);
665 linreg_set_depvar_mean (psw->models[k], means[i]);
667 For large data sets, use QR decomposition.
669 if (n_data > sqrt (n_indep) && n_data > REG_LARGE_DATA)
671 psw->models[k]->method = LINREG_QR;
677 Find the least-squares estimates and other statistics.
679 linreg_fit (this_cm, psw->models[k]);
681 if (!taint_has_tainted_successor (casereader_get_taint (input)))
683 subcommand_statistics (cmd, psw->models[k], this_cm, dep_var);
688 msg (SE, _("No valid data found. This command was skipped."));
690 gsl_matrix_free (this_cm);
697 struct casereader *r = casereader_clone (reader);
699 for (; (c = casereader_read (r)) != NULL; case_unref (c))
701 struct ccase *outc = case_clone (c);
702 for (k = 0; k < cmd->n_dep_vars; k++)
704 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
705 const struct variable *dep_var = cmd->dep_vars[k];
706 int n_indep = identify_indep_vars (cmd, vars, dep_var);
707 double *vals = xnmalloc (n_indep, sizeof (*vals));
708 for (i = 0; i < n_indep; i++)
710 const union value *tmp = case_data (c, vars[i]);
716 double pred = linreg_predict (psw->models[k], vals, n_indep);
717 case_data_rw_idx (outc, k * ws->extras + ws->pred_idx)->f = pred;
722 double obs = case_data (c, psw->models[k]->depvar)->f;
723 double res = linreg_residual (psw->models[k], obs, vals, n_indep);
724 case_data_rw_idx (outc, k * ws->extras + ws->res_idx)->f = res;
729 casewriter_write (ws->writer, outc);
731 casereader_destroy (r);
734 casereader_destroy (reader);
739 casereader_destroy (input);
740 covariance_destroy (cov);
748 reg_stats_r (const linreg * c, const struct variable *var)
758 rsq = linreg_ssreg (c) / linreg_sst (c);
760 (1.0 - rsq) * linreg_n_coeffs (c) / (linreg_n_obs (c) -
761 linreg_n_coeffs (c) - 1);
762 std_error = sqrt (linreg_mse (c));
763 t = tab_create (n_cols, n_rows);
764 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
765 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
766 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
767 tab_vline (t, TAL_0, 1, 0, 0);
769 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("R"));
770 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("R Square"));
771 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Adjusted R Square"));
772 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error of the Estimate"));
773 tab_double (t, 1, 1, TAB_RIGHT, sqrt (rsq), NULL);
774 tab_double (t, 2, 1, TAB_RIGHT, rsq, NULL);
775 tab_double (t, 3, 1, TAB_RIGHT, adjrsq, NULL);
776 tab_double (t, 4, 1, TAB_RIGHT, std_error, NULL);
777 tab_title (t, _("Model Summary (%s)"), var_to_string (var));
782 Table showing estimated regression coefficients.
785 reg_stats_coeff (const linreg * c, const gsl_matrix *cov, const struct variable *var)
797 const struct variable *v;
801 n_rows = linreg_n_coeffs (c) + 3;
803 t = tab_create (n_cols, n_rows);
804 tab_headers (t, 2, 0, 1, 0);
805 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
806 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
807 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
808 tab_vline (t, TAL_0, 1, 0, 0);
810 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("B"));
811 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
812 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Beta"));
813 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
814 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
815 tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("(Constant)"));
816 tab_double (t, 2, 1, 0, linreg_intercept (c), NULL);
817 std_err = sqrt (gsl_matrix_get (linreg_cov (c), 0, 0));
818 tab_double (t, 3, 1, 0, std_err, NULL);
819 tab_double (t, 4, 1, 0, 0.0, NULL);
820 t_stat = linreg_intercept (c) / std_err;
821 tab_double (t, 5, 1, 0, t_stat, NULL);
823 2 * gsl_cdf_tdist_Q (fabs (t_stat),
824 (double) (linreg_n_obs (c) - linreg_n_coeffs (c)));
825 tab_double (t, 6, 1, 0, pval, NULL);
826 for (j = 0; j < linreg_n_coeffs (c); j++)
829 ds_init_empty (&tstr);
832 v = linreg_indep_var (c, j);
833 label = var_to_string (v);
834 /* Do not overwrite the variable's name. */
835 ds_put_cstr (&tstr, label);
836 tab_text (t, 1, this_row, TAB_CENTER, ds_cstr (&tstr));
838 Regression coefficients.
840 tab_double (t, 2, this_row, 0, linreg_coeff (c, j), NULL);
842 Standard error of the coefficients.
844 std_err = sqrt (gsl_matrix_get (linreg_cov (c), j + 1, j + 1));
845 tab_double (t, 3, this_row, 0, std_err, NULL);
847 Standardized coefficient, i.e., regression coefficient
848 if all variables had unit variance.
850 beta = sqrt (gsl_matrix_get (cov, j, j));
851 beta *= linreg_coeff (c, j) /
852 sqrt (gsl_matrix_get (cov, cov->size1 - 1, cov->size2 - 1));
853 tab_double (t, 4, this_row, 0, beta, NULL);
856 Test statistic for H0: coefficient is 0.
858 t_stat = linreg_coeff (c, j) / std_err;
859 tab_double (t, 5, this_row, 0, t_stat, NULL);
861 P values for the test statistic above.
864 2 * gsl_cdf_tdist_Q (fabs (t_stat),
865 (double) (linreg_n_obs (c) -
866 linreg_n_coeffs (c) - 1));
867 tab_double (t, 6, this_row, 0, pval, NULL);
870 tab_title (t, _("Coefficients (%s)"), var_to_string (var));
875 Display the ANOVA table.
878 reg_stats_anova (const linreg * c, const struct variable *var)
882 const double msm = linreg_ssreg (c) / linreg_dfmodel (c);
883 const double mse = linreg_mse (c);
884 const double F = msm / mse;
885 const double pval = gsl_cdf_fdist_Q (F, c->dfm, c->dfe);
890 t = tab_create (n_cols, n_rows);
891 tab_headers (t, 2, 0, 1, 0);
893 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
895 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
896 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
897 tab_vline (t, TAL_0, 1, 0, 0);
899 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
900 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
901 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
902 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
903 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
905 tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("Regression"));
906 tab_text (t, 1, 2, TAB_LEFT | TAT_TITLE, _("Residual"));
907 tab_text (t, 1, 3, TAB_LEFT | TAT_TITLE, _("Total"));
909 /* Sums of Squares */
910 tab_double (t, 2, 1, 0, linreg_ssreg (c), NULL);
911 tab_double (t, 2, 3, 0, linreg_sst (c), NULL);
912 tab_double (t, 2, 2, 0, linreg_sse (c), NULL);
915 /* Degrees of freedom */
916 tab_text_format (t, 3, 1, TAB_RIGHT, "%g", c->dfm);
917 tab_text_format (t, 3, 2, TAB_RIGHT, "%g", c->dfe);
918 tab_text_format (t, 3, 3, TAB_RIGHT, "%g", c->dft);
921 tab_double (t, 4, 1, TAB_RIGHT, msm, NULL);
922 tab_double (t, 4, 2, TAB_RIGHT, mse, NULL);
924 tab_double (t, 5, 1, 0, F, NULL);
926 tab_double (t, 6, 1, 0, pval, NULL);
928 tab_title (t, _("ANOVA (%s)"), var_to_string (var));
934 reg_stats_bcov (const linreg * c, const struct variable *var)
946 n_cols = c->n_indeps + 1 + 2;
947 n_rows = 2 * (c->n_indeps + 1);
948 t = tab_create (n_cols, n_rows);
949 tab_headers (t, 2, 0, 1, 0);
950 tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1);
951 tab_hline (t, TAL_2, 0, n_cols - 1, 1);
952 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
953 tab_vline (t, TAL_0, 1, 0, 0);
954 tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Model"));
955 tab_text (t, 1, 1, TAB_CENTER | TAT_TITLE, _("Covariances"));
956 for (i = 0; i < linreg_n_coeffs (c); i++)
958 const struct variable *v = linreg_indep_var (c, i);
959 label = var_to_string (v);
960 tab_text (t, 2, i, TAB_CENTER, label);
961 tab_text (t, i + 2, 0, TAB_CENTER, label);
962 for (k = 1; k < linreg_n_coeffs (c); k++)
964 col = (i <= k) ? k : i;
965 row = (i <= k) ? i : k;
966 tab_double (t, k + 2, i, TAB_CENTER,
967 gsl_matrix_get (c->cov, row, col), NULL);
970 tab_title (t, _("Coefficient Correlations (%s)"), var_to_string (var));