X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fregression.q;h=4f6f0b862196b6a7365466147145714f3969bfa9;hb=e93857e0338c2a71794db2b57e3659bbe6946240;hp=92afb378cea85c45d308d7a38845d2640cb80d68;hpb=f1861ea4c715dfaddd84ff14be2ab92b13379014;p=pspp-builds.git diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 92afb378..4f6f0b86 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -41,7 +41,7 @@ #include #include #include -#include +#include #include #include @@ -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; @@ -209,8 +208,7 @@ reg_stats_coeff (pspp_linreg_cache * c) tab_float (t, 2, 1, 0, c->intercept, 10, 2); 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_float (t, 4, 1, 0, 0.0, 10, 2); t_stat = c->intercept / std_err; tab_float (t, 5, 1, 0, t_stat, 10, 2); pval = 2 * gsl_cdf_tdist_Q (fabs (t_stat), 1.0); @@ -242,25 +240,24 @@ 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_float (t, 2, this_row, 0, c->coeff[j]->estimate, 10, 2); /* 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); /* - '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; + beta = pspp_coeff_get_sd (c->coeff[j]); + beta *= c->coeff[j]->estimate / c->depvar_std; tab_float (t, 4, this_row, 0, beta, 10, 2); /* Test statistic for H0: coefficient is 0. */ - t_stat = coeff / std_err; + t_stat = c->coeff[j]->estimate / std_err; tab_float (t, 5, this_row, 0, t_stat, 10, 2); /* P values for the test statistic above. @@ -318,12 +315,11 @@ reg_stats_anova (pspp_linreg_cache * c) /* 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_float (t, 4, 1, TAB_RIGHT, msm, 8, 3); tab_float (t, 4, 2, TAB_RIGHT, mse, 8, 3); @@ -334,21 +330,25 @@ reg_stats_anova (pspp_linreg_cache * c) 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) { @@ -861,39 +861,6 @@ coeff_init (pspp_linreg_cache * c, struct design_matrix *dm) pspp_coeff_init (c->coeff, dm); } -/* - Put the moments in the linreg cache. - */ -static void -compute_moments (pspp_linreg_cache * c, struct moments_var *mom, - struct design_matrix *dm, size_t n) -{ - size_t i; - size_t j; - double weight; - double mean; - double variance; - double skewness; - double kurtosis; - /* - Scan the variable names in the columns of the design matrix. - When we find the variable we need, insert its mean in the cache. - */ - for (i = 0; i < dm->m->size2; i++) - { - for (j = 0; j < n; j++) - { - if (design_matrix_col_to_var (dm, i) == (mom + j)->v) - { - 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)); - } - } - } -} - static bool run_regression (struct casereader *input, struct cmd_regression *cmd, struct dataset *ds, pspp_linreg_cache **models) @@ -956,9 +923,9 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, n_indep = identify_indep_vars (indep_vars, dep_var); reader = casereader_clone (input); reader = casereader_create_filter_missing (reader, indep_vars, n_indep, - MV_ANY, NULL); + MV_ANY, NULL, NULL); reader = casereader_create_filter_missing (reader, &dep_var, 1, - MV_ANY, NULL); + MV_ANY, NULL, NULL); n_data = prepare_categories (casereader_clone (reader), indep_vars, n_indep, mom); @@ -973,7 +940,8 @@ run_regression (struct casereader *input, struct cmd_regression *cmd, { lopts.get_indep_mean_std[i] = 1; } - models[k] = pspp_linreg_cache_alloc (X->m->size1, X->m->size2); + models[k] = pspp_linreg_cache_alloc (dep_var, (const struct variable **) indep_vars, + X->m->size1, X->m->size2); models[k]->depvar = dep_var; /* For large data sets, use QR decomposition. @@ -1010,8 +978,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))) {