From 933f16e8847bacf67eec53e7ba77b6c069125700 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 19 Jan 2016 17:47:04 +0100 Subject: [PATCH] GLM: Do not print the intercept if the model is unbalanced I cannot find any reliable explanation of how to calculate this figure for unbalanced models not what it actually means. So let's not even bother with it until an expert comes along. --- src/language/stats/glm.c | 17 +++++++++++------ src/math/categoricals.c | 25 +++++++++++++++++++++++++ src/math/categoricals.h | 1 + tests/language/stats/glm.at | 6 +++--- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/language/stats/glm.c b/src/language/stats/glm.c index e4b3c17b21..a5e047e86d 100644 --- a/src/language/stats/glm.c +++ b/src/language/stats/glm.c @@ -775,12 +775,17 @@ output_glm (const struct glm_spec *cmd, const struct glm_workspace *ws) const double df = 1.0; const double F = intercept_ssq / df / mse; tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Intercept")); - tab_double (t, 1, r, 0, intercept_ssq, NULL, RC_OTHER); - tab_double (t, 2, r, 0, 1.00, NULL, RC_WEIGHT); - tab_double (t, 3, r, 0, intercept_ssq / df, NULL, RC_OTHER); - tab_double (t, 4, r, 0, F, NULL, RC_OTHER); - tab_double (t, 5, r, 0, gsl_cdf_fdist_Q (F, df, n_total - df_corr), - NULL, RC_PVALUE); + /* The intercept for unbalanced models is of limited use and + nobody knows how to calculate it properly */ + if (categoricals_isbalanced (ws->cats)) + { + tab_double (t, 1, r, 0, intercept_ssq, NULL, RC_OTHER); + tab_double (t, 2, r, 0, 1.00, NULL, RC_WEIGHT); + tab_double (t, 3, r, 0, intercept_ssq / df, NULL, RC_OTHER); + tab_double (t, 4, r, 0, F, NULL, RC_OTHER); + tab_double (t, 5, r, 0, gsl_cdf_fdist_Q (F, df, n_total - df_corr), + NULL, RC_PVALUE); + } r++; } diff --git a/src/math/categoricals.c b/src/math/categoricals.c index b621d98293..140542fe02 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -196,6 +196,31 @@ struct categoricals const struct payload *payload; }; + +bool +categoricals_isbalanced (const struct categoricals *cat) +{ + int i; + + for (i = 0 ; i < cat->n_iap; ++i) + { + int v; + const struct interact_params *iap = &cat->iap[i]; + + double oval = -1.0; + for (v = 0; v < hmap_count (&iap->ivmap); ++v) + { + const struct interaction_value *iv = iap->reverse_interaction_value_map[v]; + if (oval == -1.0) + oval = iv->cc; + if (oval != iv->cc) + return false; + } + } + return true; +} + + static void categoricals_dump (const struct categoricals *cat) { diff --git a/src/math/categoricals.h b/src/math/categoricals.h index c5919bc455..fbb45aadb7 100644 --- a/src/math/categoricals.h +++ b/src/math/categoricals.h @@ -124,5 +124,6 @@ struct payload void categoricals_set_payload (struct categoricals *cats, const struct payload *p, const void *aux1, void *aux2); +bool categoricals_isbalanced (const struct categoricals *cat); #endif diff --git a/tests/language/stats/glm.at b/tests/language/stats/glm.at index ec9a6799e3..e56c150820 100644 --- a/tests/language/stats/glm.at +++ b/tests/language/stats/glm.at @@ -214,7 +214,7 @@ warning: GLM is experimental. Do not rely on these results. Table: Tests of Between-Subjects Effects Source,Type I Sum of Squares,df,Mean Square,F,Sig. Corrected Model,216.017,7,30.860,5.046,.001 -Intercept,3410.526,1,3410.526,557.709,.000 +Intercept,,,,, Agrp,9.579,1,9.579,1.566,.220 Bgrp,186.225,3,62.075,10.151,.000 Agrp * Bgrp,20.212,3,6.737,1.102,.364 @@ -227,7 +227,7 @@ warning: GLM is experimental. Do not rely on these results. Table: Tests of Between-Subjects Effects Source,Type I Sum of Squares,df,Mean Square,F,Sig. Corrected Model,216.017,7,30.860,5.046,.001 -Intercept,3410.526,1,3410.526,557.709,.000 +Intercept,,,,, Bgrp,193.251,3,64.417,10.534,.000 Agrp,2.553,1,2.553,.418,.523 Bgrp * Agrp,20.212,3,6.737,1.102,.364 @@ -253,7 +253,7 @@ warning: GLM is experimental. Do not rely on these results. Table: Tests of Between-Subjects Effects Source,Type II Sum of Squares,df,Mean Square,F,Sig. Corrected Model,216.017,7,30.860,5.046,.001 -Intercept,3410.526,1,3410.526,557.709,.000 +Intercept,,,,, Agrp,2.553,1,2.553,.418,.523 Bgrp,186.225,3,62.075,10.151,.000 Agrp * Bgrp,20.212,3,6.737,1.102,.364 -- 2.30.2