X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fregression.q;h=32ac1815ea95c42d471ba3a4c280469a14a36113;hb=46912334775c83a23902bd5c7d72cd4ad8d23c95;hp=86d102d7c7037166752a9570d2d547c09016180a;hpb=c3943790b7598402bdc16fe90d6d6bdf22489b35;p=pspp-builds.git diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 86d102d7..32ac1815 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -148,7 +148,7 @@ reg_stats_r (pspp_linreg_cache * c) assert (c != NULL); rsq = c->ssm / c->sst; adjrsq = 1.0 - (1.0 - rsq) * (c->n_obs - 1.0) / (c->n_obs - c->n_indeps); - std_error = sqrt ((c->n_indeps - 1.0) / (c->n_obs - 1.0)); + std_error = sqrt (pspp_linreg_mse (c)); t = tab_create (n_cols, n_rows, 0); tab_dim (t, tab_natural_dimensions); tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, n_cols - 1, n_rows - 1); @@ -160,10 +160,10 @@ reg_stats_r (pspp_linreg_cache * c) tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("R Square")); tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Adjusted R Square")); tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error of the Estimate")); - tab_float (t, 1, 1, TAB_RIGHT, sqrt (rsq), 10, 2); - tab_float (t, 2, 1, TAB_RIGHT, rsq, 10, 2); - tab_float (t, 3, 1, TAB_RIGHT, adjrsq, 10, 2); - tab_float (t, 4, 1, TAB_RIGHT, std_error, 10, 2); + tab_double (t, 1, 1, TAB_RIGHT, sqrt (rsq), NULL); + tab_double (t, 2, 1, TAB_RIGHT, rsq, NULL); + tab_double (t, 3, 1, TAB_RIGHT, adjrsq, NULL); + tab_double (t, 4, 1, TAB_RIGHT, std_error, NULL); tab_title (t, _("Model Summary")); tab_submit (t); } @@ -180,7 +180,6 @@ reg_stats_coeff (pspp_linreg_cache * c) int this_row; double t_stat; double pval; - double coeff; double std_err; double beta; const char *label; @@ -206,15 +205,14 @@ reg_stats_coeff (pspp_linreg_cache * c) tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t")); tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance")); tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("(Constant)")); - tab_float (t, 2, 1, 0, c->intercept, 10, 2); + tab_double (t, 2, 1, 0, c->intercept, NULL); std_err = sqrt (gsl_matrix_get (c->cov, 0, 0)); - tab_float (t, 3, 1, 0, std_err, 10, 2); - beta = c->intercept / c->depvar_std; - tab_float (t, 4, 1, 0, beta, 10, 2); + tab_double (t, 3, 1, 0, std_err, NULL); + tab_double (t, 4, 1, 0, 0.0, NULL); t_stat = c->intercept / std_err; - tab_float (t, 5, 1, 0, t_stat, 10, 2); + tab_double (t, 5, 1, 0, t_stat, NULL); pval = 2 * gsl_cdf_tdist_Q (fabs (t_stat), 1.0); - tab_float (t, 6, 1, 0, pval, 10, 2); + tab_double (t, 6, 1, 0, pval, NULL); for (j = 0; j < c->n_coeffs; j++) { struct string tstr; @@ -242,33 +240,32 @@ reg_stats_coeff (pspp_linreg_cache * c) /* Regression coefficients. */ - coeff = c->coeff[j]->estimate; - tab_float (t, 2, this_row, 0, coeff, 10, 2); + tab_double (t, 2, this_row, 0, c->coeff[j]->estimate, NULL); /* Standard error of the coefficients. */ std_err = sqrt (gsl_matrix_get (c->cov, j + 1, j + 1)); - tab_float (t, 3, this_row, 0, std_err, 10, 2); + tab_double (t, 3, this_row, 0, std_err, NULL); /* - 'Standardized' coefficient, i.e., regression coefficient + Standardized coefficient, i.e., regression coefficient if all variables had unit variance. */ - beta = gsl_vector_get (c->indep_std, j + 1); - beta *= coeff / c->depvar_std; - tab_float (t, 4, this_row, 0, beta, 10, 2); + beta = pspp_coeff_get_sd (c->coeff[j]); + beta *= c->coeff[j]->estimate / c->depvar_std; + tab_double (t, 4, this_row, 0, beta, NULL); /* Test statistic for H0: coefficient is 0. */ - t_stat = coeff / std_err; - tab_float (t, 5, this_row, 0, t_stat, 10, 2); + t_stat = c->coeff[j]->estimate / std_err; + tab_double (t, 5, this_row, 0, t_stat, NULL); /* P values for the test statistic above. */ pval = 2 * gsl_cdf_tdist_Q (fabs (t_stat), (double) (c->n_obs - c->n_coeffs)); - tab_float (t, 6, this_row, 0, pval, 10, 2); + tab_double (t, 6, this_row, 0, pval, NULL); ds_destroy (&tstr); } tab_title (t, _("Coefficients")); @@ -284,7 +281,7 @@ reg_stats_anova (pspp_linreg_cache * c) int n_cols = 7; int n_rows = 4; const double msm = c->ssm / c->dfm; - const double mse = c->sse / c->dfe; + const double mse = pspp_linreg_mse (c); const double F = msm / mse; const double pval = gsl_cdf_fdist_Q (F, c->dfm, c->dfe); @@ -312,43 +309,46 @@ reg_stats_anova (pspp_linreg_cache * c) tab_text (t, 1, 3, TAB_LEFT | TAT_TITLE, _("Total")); /* Sums of Squares */ - tab_float (t, 2, 1, 0, c->ssm, 10, 2); - tab_float (t, 2, 3, 0, c->sst, 10, 2); - tab_float (t, 2, 2, 0, c->sse, 10, 2); + tab_double (t, 2, 1, 0, c->ssm, NULL); + tab_double (t, 2, 3, 0, c->sst, NULL); + tab_double (t, 2, 2, 0, c->sse, NULL); /* Degrees of freedom */ - tab_float (t, 3, 1, 0, c->dfm, 4, 0); - tab_float (t, 3, 2, 0, c->dfe, 4, 0); - tab_float (t, 3, 3, 0, c->dft, 4, 0); + tab_text (t, 3, 1, TAB_RIGHT | TAT_PRINTF, "%g", c->dfm); + tab_text (t, 3, 2, TAB_RIGHT | TAT_PRINTF, "%g", c->dfe); + tab_text (t, 3, 3, TAB_RIGHT | TAT_PRINTF, "%g", c->dft); /* Mean Squares */ + tab_double (t, 4, 1, TAB_RIGHT, msm, NULL); + tab_double (t, 4, 2, TAB_RIGHT, mse, NULL); - tab_float (t, 4, 1, TAB_RIGHT, msm, 8, 3); - tab_float (t, 4, 2, TAB_RIGHT, mse, 8, 3); + tab_double (t, 5, 1, 0, F, NULL); - tab_float (t, 5, 1, 0, F, 8, 3); - - tab_float (t, 6, 1, 0, pval, 8, 3); + tab_double (t, 6, 1, 0, pval, NULL); tab_title (t, _("ANOVA")); tab_submit (t); } + static void reg_stats_outs (pspp_linreg_cache * c) { assert (c != NULL); } + static void reg_stats_zpp (pspp_linreg_cache * c) { assert (c != NULL); } + static void reg_stats_label (pspp_linreg_cache * c) { assert (c != NULL); } + static void reg_stats_sha (pspp_linreg_cache * c) { @@ -398,8 +398,8 @@ reg_stats_bcov (pspp_linreg_cache * c) { col = (i <= k) ? k : i; row = (i <= k) ? i : k; - tab_float (t, k + 2, i, TAB_CENTER, - gsl_matrix_get (c->cov, row, col), 8, 3); + tab_double (t, k + 2, i, TAB_CENTER, + gsl_matrix_get (c->cov, row, col), NULL); } } tab_title (t, _("Coefficient Correlations")); @@ -797,7 +797,7 @@ identify_indep_vars (const struct variable **indep_vars, for (i = 0; i < n_variables; i++) if (!is_depvar (i, depvar)) indep_vars[n_indep_vars++] = v_variables[i]; - if ((n_indep_vars < 2) && is_depvar (0, depvar)) + if ((n_indep_vars < 1) && is_depvar (0, depvar)) { /* There is only one independent variable, and it is the same @@ -887,8 +887,8 @@ compute_moments (pspp_linreg_cache * c, struct moments_var *mom, { moments1_calculate ((mom + j)->m, &weight, &mean, &variance, &skewness, &kurtosis); - gsl_vector_set (c->indep_means, i, mean); - gsl_vector_set (c->indep_std, i, sqrt (variance)); + pspp_linreg_set_indep_variable_mean (c, (mom + j)->v, mean); + pspp_linreg_set_indep_variable_sd (c, (mom + j)->v, sqrt (variance)); } } } @@ -941,7 +941,7 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, } lopts.get_depvar_mean_std = 1; - lopts.get_indep_mean_std = xnmalloc (n_variables, sizeof (int)); + indep_vars = xnmalloc (n_variables, sizeof *indep_vars); for (k = 0; k < cmd->n_dependent; k++) @@ -969,6 +969,7 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, design_matrix_create (n_indep, (const struct variable **) indep_vars, n_data); + lopts.get_indep_mean_std = xnmalloc (X->m->size2, sizeof (int)); for (i = 0; i < X->m->size2; i++) { lopts.get_indep_mean_std[i] = 1; @@ -1010,8 +1011,7 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, /* Find the least-squares estimates and other statistics. */ - pspp_linreg ((const gsl_vector *) Y, X->m, &lopts, models[k]); - compute_moments (models[k], mom, X, n_variables); + pspp_linreg ((const gsl_vector *) Y, X, &lopts, models[k]); if (!taint_has_tainted_successor (casereader_get_taint (input))) { @@ -1020,6 +1020,7 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, gsl_vector_free (Y); design_matrix_destroy (X); + free (lopts.get_indep_mean_std); } else { @@ -1034,7 +1035,6 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, } free (mom); free (indep_vars); - free (lopts.get_indep_mean_std); casereader_destroy (input); return true;