1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2005, 2009, 2010, 2011, 2012, 2013, 2014,
3 2016, 2017 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include <gsl/gsl_math.h>
24 #include <gsl/gsl_cdf.h>
25 #include <gsl/gsl_matrix.h>
27 #include <data/dataset.h>
28 #include <data/casewriter.h>
30 #include "language/command.h"
31 #include "language/lexer/lexer.h"
32 #include "language/lexer/value-parser.h"
33 #include "language/lexer/variable-parser.h"
36 #include "data/casegrouper.h"
37 #include "data/casereader.h"
38 #include "data/dictionary.h"
40 #include "math/covariance.h"
41 #include "math/linreg.h"
42 #include "math/moments.h"
44 #include "libpspp/message.h"
45 #include "libpspp/taint.h"
47 #include "output/pivot-table.h"
49 #include "gl/intprops.h"
50 #include "gl/minmax.h"
53 #define _(msgid) gettext (msgid)
54 #define N_(msgid) msgid
64 #define STATS_DEFAULT (STATS_R | STATS_COEFF | STATS_ANOVA | STATS_OUTS)
72 const struct variable **vars;
75 const struct variable **dep_vars;
87 struct regression_workspace
89 /* The new variables which will be introduced by /SAVE */
90 const struct variable **predvars;
91 const struct variable **residvars;
93 /* A reader/writer pair to temporarily hold the
94 values of the new variables */
95 struct casewriter *writer;
96 struct casereader *reader;
98 /* Indeces of the new values in the reader/writer (-1 if not applicable) */
102 /* 0, 1 or 2 depending on what new variables are to be created */
106 static void run_regression (const struct regression *cmd,
107 struct regression_workspace *ws,
108 struct casereader *input);
111 /* Return a string based on PREFIX which may be used as the name
112 of a new variable in DICT */
114 reg_get_name (const struct dictionary *dict, const char *prefix)
119 /* XXX handle too-long prefixes */
120 name = xmalloc (strlen (prefix) + INT_BUFSIZE_BOUND (i) + 1);
123 sprintf (name, "%s%d", prefix, i);
124 if (dict_lookup_var (dict, name) == NULL)
130 static const struct variable *
131 create_aux_var (struct dataset *ds, const char *prefix)
133 struct variable *var;
134 struct dictionary *dict = dataset_dict (ds);
135 char *name = reg_get_name (dict, prefix);
136 var = dict_create_var_assert (dict, name, 0);
141 /* Auxiliary data for transformation when /SAVE is entered */
142 struct save_trans_data
145 struct regression_workspace *ws;
149 save_trans_free (void *aux)
151 struct save_trans_data *save_trans_data = aux;
152 free (save_trans_data->ws->predvars);
153 free (save_trans_data->ws->residvars);
155 casereader_destroy (save_trans_data->ws->reader);
156 free (save_trans_data->ws);
157 free (save_trans_data);
162 save_trans_func (void *aux, struct ccase **c, casenumber x UNUSED)
164 struct save_trans_data *save_trans_data = aux;
165 struct regression_workspace *ws = save_trans_data->ws;
166 struct ccase *in = casereader_read (ws->reader);
171 *c = case_unshare (*c);
173 for (k = 0; k < save_trans_data->n_dep_vars; ++k)
175 if (ws->pred_idx != -1)
177 double pred = case_data_idx (in, ws->extras * k + ws->pred_idx)->f;
178 case_data_rw (*c, ws->predvars[k])->f = pred;
181 if (ws->res_idx != -1)
183 double resid = case_data_idx (in, ws->extras * k + ws->res_idx)->f;
184 case_data_rw (*c, ws->residvars[k])->f = resid;
190 return TRNS_CONTINUE;
195 cmd_regression (struct lexer *lexer, struct dataset *ds)
197 struct regression_workspace workspace;
198 struct regression regression;
199 const struct dictionary *dict = dataset_dict (ds);
202 memset (®ression, 0, sizeof (struct regression));
204 regression.ci = 0.95;
205 regression.stats = STATS_DEFAULT;
206 regression.pred = false;
207 regression.resid = false;
210 regression.origin = false;
212 bool variables_seen = false;
213 bool method_seen = false;
214 bool dependent_seen = false;
215 while (lex_token (lexer) != T_ENDCMD)
217 lex_match (lexer, T_SLASH);
219 if (lex_match_id (lexer, "VARIABLES"))
223 msg (SE, _("VARIABLES may not appear after %s"), "METHOD");
228 msg (SE, _("VARIABLES may not appear after %s"), "DEPENDENT");
231 variables_seen = true;
232 lex_match (lexer, T_EQUALS);
234 if (!parse_variables_const (lexer, dict,
235 ®ression.vars, ®ression.n_vars,
236 PV_NO_DUPLICATE | PV_NUMERIC))
239 else if (lex_match_id (lexer, "DEPENDENT"))
241 dependent_seen = true;
242 lex_match (lexer, T_EQUALS);
244 free (regression.dep_vars);
245 regression.n_dep_vars = 0;
247 if (!parse_variables_const (lexer, dict,
248 ®ression.dep_vars,
249 ®ression.n_dep_vars,
250 PV_NO_DUPLICATE | PV_NUMERIC))
253 else if (lex_match_id (lexer, "ORIGIN"))
255 regression.origin = true;
257 else if (lex_match_id (lexer, "NOORIGIN"))
259 regression.origin = false;
261 else if (lex_match_id (lexer, "METHOD"))
264 lex_match (lexer, T_EQUALS);
266 if (!lex_force_match_id (lexer, "ENTER"))
271 if (! variables_seen)
273 if (!parse_variables_const (lexer, dict,
274 ®ression.vars, ®ression.n_vars,
275 PV_NO_DUPLICATE | PV_NUMERIC))
279 else if (lex_match_id (lexer, "STATISTICS"))
281 unsigned long statistics = 0;
282 lex_match (lexer, T_EQUALS);
284 while (lex_token (lexer) != T_ENDCMD
285 && lex_token (lexer) != T_SLASH)
287 if (lex_match (lexer, T_ALL))
291 else if (lex_match_id (lexer, "DEFAULTS"))
293 statistics |= STATS_DEFAULT;
295 else if (lex_match_id (lexer, "R"))
297 statistics |= STATS_R;
299 else if (lex_match_id (lexer, "COEFF"))
301 statistics |= STATS_COEFF;
303 else if (lex_match_id (lexer, "ANOVA"))
305 statistics |= STATS_ANOVA;
307 else if (lex_match_id (lexer, "BCOV"))
309 statistics |= STATS_BCOV;
311 else if (lex_match_id (lexer, "CI"))
313 statistics |= STATS_CI;
315 if (lex_match (lexer, T_LPAREN) &&
316 lex_force_num (lexer))
318 regression.ci = lex_number (lexer) / 100.0;
320 if (! lex_force_match (lexer, T_RPAREN))
326 lex_error (lexer, NULL);
332 regression.stats = statistics;
335 else if (lex_match_id (lexer, "SAVE"))
337 lex_match (lexer, T_EQUALS);
339 while (lex_token (lexer) != T_ENDCMD
340 && lex_token (lexer) != T_SLASH)
342 if (lex_match_id (lexer, "PRED"))
344 regression.pred = true;
346 else if (lex_match_id (lexer, "RESID"))
348 regression.resid = true;
352 lex_error (lexer, NULL);
359 lex_error (lexer, NULL);
364 if (!regression.vars)
366 dict_get_vars (dict, ®ression.vars, ®ression.n_vars, 0);
369 save = regression.pred || regression.resid;
370 workspace.extras = 0;
371 workspace.res_idx = -1;
372 workspace.pred_idx = -1;
373 workspace.writer = NULL;
374 workspace.reader = NULL;
375 workspace.residvars = NULL;
376 workspace.predvars = NULL;
380 struct caseproto *proto = caseproto_create ();
382 if (regression.resid)
384 workspace.res_idx = workspace.extras ++;
385 workspace.residvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.residvars));
387 for (i = 0; i < regression.n_dep_vars; ++i)
389 workspace.residvars[i] = create_aux_var (ds, "RES");
390 proto = caseproto_add_width (proto, 0);
396 workspace.pred_idx = workspace.extras ++;
397 workspace.predvars = xcalloc (regression.n_dep_vars, sizeof (*workspace.predvars));
399 for (i = 0; i < regression.n_dep_vars; ++i)
401 workspace.predvars[i] = create_aux_var (ds, "PRED");
402 proto = caseproto_add_width (proto, 0);
406 if (proc_make_temporary_transformations_permanent (ds))
407 msg (SW, _("REGRESSION with SAVE ignores TEMPORARY. "
408 "Temporary transformations will be made permanent."));
410 if (dict_get_filter (dict))
411 msg (SW, _("REGRESSION with SAVE ignores FILTER. "
412 "All cases will be processed."));
414 workspace.writer = autopaging_writer_create (proto);
415 caseproto_unref (proto);
420 struct casegrouper *grouper;
421 struct casereader *group;
424 grouper = casegrouper_create_splits (proc_open_filtering (ds, !save), dict);
427 while (casegrouper_get_next_group (grouper, &group))
429 run_regression (®ression,
434 ok = casegrouper_destroy (grouper);
435 ok = proc_commit (ds) && ok;
438 if (workspace.writer)
440 struct save_trans_data *save_trans_data = xmalloc (sizeof *save_trans_data);
441 struct casereader *r = casewriter_make_reader (workspace.writer);
442 workspace.writer = NULL;
443 workspace.reader = r;
444 save_trans_data->ws = xmalloc (sizeof (workspace));
445 memcpy (save_trans_data->ws, &workspace, sizeof (workspace));
446 save_trans_data->n_dep_vars = regression.n_dep_vars;
448 add_transformation (ds, save_trans_func, save_trans_free, save_trans_data);
452 free (regression.vars);
453 free (regression.dep_vars);
458 free (regression.vars);
459 free (regression.dep_vars);
463 /* Return the size of the union of dependent and independent variables */
465 get_n_all_vars (const struct regression *cmd)
467 size_t result = cmd->n_vars;
471 result += cmd->n_dep_vars;
472 for (i = 0; i < cmd->n_dep_vars; i++)
474 for (j = 0; j < cmd->n_vars; j++)
476 if (cmd->vars[j] == cmd->dep_vars[i])
485 /* Fill VARS with the union of dependent and independent variables */
487 fill_all_vars (const struct variable **vars, const struct regression *cmd)
491 for (i = 0; i < cmd->n_vars; i++)
493 vars[i] = cmd->vars[i];
496 for (i = 0; i < cmd->n_dep_vars; i++)
500 for (j = 0; j < cmd->n_vars; j++)
502 if (cmd->dep_vars[i] == cmd->vars[j])
510 vars[cmd->n_vars + x++] = cmd->dep_vars[i];
516 Is variable k the dependent variable?
519 is_depvar (const struct regression *cmd, size_t k, const struct variable *v)
521 return v == cmd->vars[k];
525 /* Identify the explanatory variables in v_variables. Returns
526 the number of independent variables. */
528 identify_indep_vars (const struct regression *cmd,
529 const struct variable **indep_vars,
530 const struct variable *depvar)
532 int n_indep_vars = 0;
535 for (i = 0; i < cmd->n_vars; i++)
536 if (!is_depvar (cmd, i, depvar))
537 indep_vars[n_indep_vars++] = cmd->vars[i];
538 if ((n_indep_vars < 1) && is_depvar (cmd, 0, depvar))
541 There is only one independent variable, and it is the same
542 as the dependent variable. Print a warning and continue.
546 ("The dependent variable is equal to the independent variable. "
547 "The least squares line is therefore Y=X. "
548 "Standard errors and related statistics may be meaningless."));
550 indep_vars[0] = cmd->vars[0];
556 fill_covariance (gsl_matrix * cov, struct covariance *all_cov,
557 const struct variable **vars,
558 size_t n_vars, const struct variable *dep_var,
559 const struct variable **all_vars, size_t n_all_vars,
564 size_t dep_subscript;
566 const gsl_matrix *ssizes;
567 const gsl_matrix *mean_matrix;
568 const gsl_matrix *ssize_matrix;
571 const gsl_matrix *cm = covariance_calculate_unnormalized (all_cov);
576 rows = xnmalloc (cov->size1 - 1, sizeof (*rows));
578 for (i = 0; i < n_all_vars; i++)
580 for (j = 0; j < n_vars; j++)
582 if (vars[j] == all_vars[i])
587 if (all_vars[i] == dep_var)
592 mean_matrix = covariance_moments (all_cov, MOMENT_MEAN);
593 ssize_matrix = covariance_moments (all_cov, MOMENT_NONE);
594 for (i = 0; i < cov->size1 - 1; i++)
596 means[i] = gsl_matrix_get (mean_matrix, rows[i], 0)
597 / gsl_matrix_get (ssize_matrix, rows[i], 0);
598 for (j = 0; j < cov->size2 - 1; j++)
600 gsl_matrix_set (cov, i, j, gsl_matrix_get (cm, rows[i], rows[j]));
601 gsl_matrix_set (cov, j, i, gsl_matrix_get (cm, rows[j], rows[i]));
604 means[cov->size1 - 1] = gsl_matrix_get (mean_matrix, dep_subscript, 0)
605 / gsl_matrix_get (ssize_matrix, dep_subscript, 0);
606 ssizes = covariance_moments (all_cov, MOMENT_NONE);
607 result = gsl_matrix_get (ssizes, dep_subscript, rows[0]);
608 for (i = 0; i < cov->size1 - 1; i++)
610 gsl_matrix_set (cov, i, cov->size1 - 1,
611 gsl_matrix_get (cm, rows[i], dep_subscript));
612 gsl_matrix_set (cov, cov->size1 - 1, i,
613 gsl_matrix_get (cm, rows[i], dep_subscript));
614 if (result > gsl_matrix_get (ssizes, rows[i], dep_subscript))
616 result = gsl_matrix_get (ssizes, rows[i], dep_subscript);
619 gsl_matrix_set (cov, cov->size1 - 1, cov->size1 - 1,
620 gsl_matrix_get (cm, dep_subscript, dep_subscript));
628 STATISTICS subcommand output functions.
630 static void reg_stats_r (const struct linreg *, const struct variable *);
631 static void reg_stats_coeff (const struct linreg *, const gsl_matrix *, const struct variable *, const struct regression *);
632 static void reg_stats_anova (const struct linreg *, const struct variable *);
633 static void reg_stats_bcov (const struct linreg *, const struct variable *);
637 subcommand_statistics (const struct regression *cmd, const struct linreg * c, const gsl_matrix * cm,
638 const struct variable *var)
640 if (cmd->stats & STATS_R)
641 reg_stats_r (c, var);
643 if (cmd->stats & STATS_ANOVA)
644 reg_stats_anova (c, var);
646 if (cmd->stats & STATS_COEFF)
647 reg_stats_coeff (c, cm, var, cmd);
649 if (cmd->stats & STATS_BCOV)
650 reg_stats_bcov (c, var);
655 run_regression (const struct regression *cmd,
656 struct regression_workspace *ws,
657 struct casereader *input)
660 struct linreg **models;
664 struct covariance *cov;
665 struct casereader *reader;
666 size_t n_all_vars = get_n_all_vars (cmd);
667 const struct variable **all_vars = xnmalloc (n_all_vars, sizeof (*all_vars));
669 double *means = xnmalloc (n_all_vars, sizeof (*means));
671 fill_all_vars (all_vars, cmd);
672 cov = covariance_1pass_create (n_all_vars, all_vars,
673 dict_get_weight (dataset_dict (cmd->ds)),
674 MV_ANY, cmd->origin == false);
676 reader = casereader_clone (input);
677 reader = casereader_create_filter_missing (reader, all_vars, n_all_vars,
682 struct casereader *r = casereader_clone (reader);
684 for (; (c = casereader_read (r)) != NULL; case_unref (c))
686 covariance_accumulate (cov, c);
688 casereader_destroy (r);
691 models = xcalloc (cmd->n_dep_vars, sizeof (*models));
692 for (k = 0; k < cmd->n_dep_vars; k++)
694 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
695 const struct variable *dep_var = cmd->dep_vars[k];
696 int n_indep = identify_indep_vars (cmd, vars, dep_var);
697 gsl_matrix *this_cm = gsl_matrix_alloc (n_indep + 1, n_indep + 1);
698 double n_data = fill_covariance (this_cm, cov, vars, n_indep,
699 dep_var, all_vars, n_all_vars, means);
700 models[k] = linreg_alloc (dep_var, vars, n_data, n_indep, cmd->origin);
701 for (i = 0; i < n_indep; i++)
703 linreg_set_indep_variable_mean (models[k], i, means[i]);
705 linreg_set_depvar_mean (models[k], means[i]);
709 Find the least-squares estimates and other statistics.
711 linreg_fit (this_cm, models[k]);
713 if (!taint_has_tainted_successor (casereader_get_taint (input)))
715 subcommand_statistics (cmd, models[k], this_cm, dep_var);
720 msg (SE, _("No valid data found. This command was skipped."));
722 gsl_matrix_free (this_cm);
729 struct casereader *r = casereader_clone (reader);
731 for (; (c = casereader_read (r)) != NULL; case_unref (c))
733 struct ccase *outc = case_create (casewriter_get_proto (ws->writer));
734 for (k = 0; k < cmd->n_dep_vars; k++)
736 const struct variable **vars = xnmalloc (cmd->n_vars, sizeof (*vars));
737 const struct variable *dep_var = cmd->dep_vars[k];
738 int n_indep = identify_indep_vars (cmd, vars, dep_var);
739 double *vals = xnmalloc (n_indep, sizeof (*vals));
740 for (i = 0; i < n_indep; i++)
742 const union value *tmp = case_data (c, vars[i]);
748 double pred = linreg_predict (models[k], vals, n_indep);
749 case_data_rw_idx (outc, k * ws->extras + ws->pred_idx)->f = pred;
754 double obs = case_data (c, linreg_dep_var (models[k]))->f;
755 double res = linreg_residual (models[k], obs, vals, n_indep);
756 case_data_rw_idx (outc, k * ws->extras + ws->res_idx)->f = res;
761 casewriter_write (ws->writer, outc);
763 casereader_destroy (r);
766 casereader_destroy (reader);
768 for (k = 0; k < cmd->n_dep_vars; k++)
770 linreg_unref (models[k]);
776 casereader_destroy (input);
777 covariance_destroy (cov);
784 reg_stats_r (const struct linreg * c, const struct variable *var)
786 struct pivot_table *table = pivot_table_create__ (
787 pivot_value_new_text_format (N_("Model Summary (%s)"),
788 var_to_string (var)));
790 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
791 N_("R"), N_("R Square"), N_("Adjusted R Square"),
792 N_("Std. Error of the Estimate"));
794 double rsq = linreg_ssreg (c) / linreg_sst (c);
795 double adjrsq = (rsq -
796 (1.0 - rsq) * linreg_n_coeffs (c)
797 / (linreg_n_obs (c) - linreg_n_coeffs (c) - 1));
798 double std_error = sqrt (linreg_mse (c));
801 sqrt (rsq), rsq, adjrsq, std_error
803 for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
804 pivot_table_put1 (table, i, pivot_value_new_number (entries[i]));
806 pivot_table_submit (table);
810 Table showing estimated regression coefficients.
813 reg_stats_coeff (const struct linreg * c, const gsl_matrix *cov, const struct variable *var, const struct regression *cmd)
815 struct pivot_table *table = pivot_table_create__ (
816 pivot_value_new_text_format (N_("Coefficients (%s)"),
817 var_to_string (var)));
819 struct pivot_dimension *statistics = pivot_dimension_create (
820 table, PIVOT_AXIS_COLUMN, N_("Statistics"));
821 pivot_category_create_group (statistics->root,
822 N_("Unstandardized Coefficients"),
823 N_("B"), N_("Std. Error"));
824 pivot_category_create_group (statistics->root,
825 N_("Standardized Coefficients"), N_("Beta"));
826 pivot_category_create_leaves (statistics->root, N_("t"),
827 N_("Sig."), PIVOT_RC_SIGNIFICANCE);
828 if (cmd->stats & STATS_CI)
830 struct pivot_category *interval = pivot_category_create_group__ (
831 statistics->root, pivot_value_new_text_format (
832 N_("%g%% Confidence Interval for B"),
834 pivot_category_create_leaves (interval, N_("Lower Bound"),
838 struct pivot_dimension *variables = pivot_dimension_create (
839 table, PIVOT_AXIS_ROW, N_("Variables"));
841 double df = linreg_n_obs (c) - linreg_n_coeffs (c) - 1;
842 double q = (1 - cmd->ci) / 2.0; /* 2-tailed test */
843 double tval = gsl_cdf_tdist_Qinv (q, df);
847 int var_idx = pivot_category_create_leaf (
848 variables->root, pivot_value_new_text (N_("(Constant)")));
850 double std_err = sqrt (gsl_matrix_get (linreg_cov (c), 0, 0));
851 double t_stat = linreg_intercept (c) / std_err;
853 linreg_intercept (c),
857 2.0 * gsl_cdf_tdist_Q (fabs (t_stat),
858 linreg_n_obs (c) - linreg_n_coeffs (c)),
859 linreg_intercept (c) - tval * std_err,
860 linreg_intercept (c) + tval * std_err,
862 for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
863 pivot_table_put2 (table, i, var_idx,
864 pivot_value_new_number (entries[i]));
867 for (size_t j = 0; j < linreg_n_coeffs (c); j++)
869 const struct variable *v = linreg_indep_var (c, j);
870 int var_idx = pivot_category_create_leaf (
871 variables->root, pivot_value_new_variable (v));
873 double std_err = sqrt (gsl_matrix_get (linreg_cov (c), j + 1, j + 1));
874 double t_stat = linreg_coeff (c, j) / std_err;
877 sqrt (gsl_matrix_get (linreg_cov (c), j + 1, j + 1)),
878 (sqrt (gsl_matrix_get (cov, j, j)) * linreg_coeff (c, j) /
879 sqrt (gsl_matrix_get (cov, cov->size1 - 1, cov->size2 - 1))),
881 2 * gsl_cdf_tdist_Q (fabs (t_stat), df),
882 linreg_coeff (c, j) - tval * std_err,
883 linreg_coeff (c, j) + tval * std_err,
885 for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
886 pivot_table_put2 (table, i, var_idx,
887 pivot_value_new_number (entries[i]));
890 pivot_table_submit (table);
894 Display the ANOVA table.
897 reg_stats_anova (const struct linreg * c, const struct variable *var)
899 struct pivot_table *table = pivot_table_create__ (
900 pivot_value_new_text_format (N_("ANOVA (%s)"), var_to_string (var)));
902 pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Statistics"),
903 N_("Sum of Squares"), PIVOT_RC_OTHER,
904 N_("df"), PIVOT_RC_INTEGER,
905 N_("Mean Square"), PIVOT_RC_OTHER,
906 N_("F"), PIVOT_RC_OTHER,
907 N_("Sig."), PIVOT_RC_SIGNIFICANCE);
909 pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Source"),
910 N_("Regression"), N_("Residual"), N_("Total"));
912 double msm = linreg_ssreg (c) / linreg_dfmodel (c);
913 double mse = linreg_mse (c);
914 double F = msm / mse;
923 /* Sums of Squares. */
924 { 0, 0, linreg_ssreg (c) },
925 { 0, 1, linreg_sse (c) },
926 { 0, 2, linreg_sst (c) },
927 /* Degrees of freedom. */
928 { 1, 0, linreg_dfmodel (c) },
929 { 1, 1, linreg_dferror (c) },
930 { 1, 2, linreg_dftotal (c) },
937 { 4, 0, gsl_cdf_fdist_Q (F, linreg_dfmodel (c), linreg_dferror (c)) },
939 for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
941 const struct entry *e = &entries[i];
942 pivot_table_put2 (table, e->stat_idx, e->source_idx,
943 pivot_value_new_number (e->x));
946 pivot_table_submit (table);
951 reg_stats_bcov (const struct linreg * c, const struct variable *var)
953 struct pivot_table *table = pivot_table_create__ (
954 pivot_value_new_text_format (N_("Coefficient Correlations (%s)"),
955 var_to_string (var)));
957 for (size_t i = 0; i < 2; i++)
959 struct pivot_dimension *models = pivot_dimension_create (
960 table, i ? PIVOT_AXIS_ROW : PIVOT_AXIS_COLUMN, N_("Models"));
961 for (size_t j = 0; j < linreg_n_coeffs (c); j++)
962 pivot_category_create_leaf (
963 models->root, pivot_value_new_variable (
964 linreg_indep_var (c, j)));
967 pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Statistics"),
970 for (size_t i = 0; i < linreg_n_coeffs (c); i++)
971 for (size_t k = 0; k < linreg_n_coeffs (c); k++)
973 double cov = gsl_matrix_get (linreg_cov (c), MIN (i, k), MAX (i, k));
974 pivot_table_put3 (table, k, i, 0, pivot_value_new_number (cov));
977 pivot_table_submit (table);