From ccc28b2989e313e79407ed174ec0ebb2302f0b32 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 9 May 2017 09:46:29 +0200 Subject: [PATCH] REGRESSION: Allow independent variables to be specified on the ENTER subcommand. This is more typical of the syntax that third party software generates. --- src/language/stats/regression.c | 49 +++++++++++++++++-------- tests/language/stats/regression.at | 57 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 15 deletions(-) diff --git a/src/language/stats/regression.c b/src/language/stats/regression.c index f7ec679a1c..d7608927da 100644 --- a/src/language/stats/regression.c +++ b/src/language/stats/regression.c @@ -205,26 +205,36 @@ cmd_regression (struct lexer *lexer, struct dataset *ds) regression.ds = ds; - /* Accept an optional, completely pointless "/VARIABLES=" */ - lex_match (lexer, T_SLASH); - if (lex_match_id (lexer, "VARIABLES")) - { - if (!lex_force_match (lexer, T_EQUALS)) - goto error; - } - - if (!parse_variables_const (lexer, dict, - ®ression.vars, ®ression.n_vars, - PV_NO_DUPLICATE | PV_NUMERIC)) - goto error; - - + bool variables_seen = false; + bool method_seen = false; + bool dependent_seen = false; while (lex_token (lexer) != T_ENDCMD) { lex_match (lexer, T_SLASH); - if (lex_match_id (lexer, "DEPENDENT")) + if (lex_match_id (lexer, "VARIABLES")) + { + if (method_seen) + { + msg (SE, _("VARIABLES may not appear after %s"), "METHOD"); + goto error; + } + if (dependent_seen) + { + msg (SE, _("VARIABLES may not appear after %s"), "DEPENDENT"); + goto error; + } + variables_seen = true; + lex_match (lexer, T_EQUALS); + + if (!parse_variables_const (lexer, dict, + ®ression.vars, ®ression.n_vars, + PV_NO_DUPLICATE | PV_NUMERIC)) + goto error; + } + else if (lex_match_id (lexer, "DEPENDENT")) { + dependent_seen = true; lex_match (lexer, T_EQUALS); free (regression.dep_vars); @@ -238,12 +248,21 @@ cmd_regression (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "METHOD")) { + method_seen = true; lex_match (lexer, T_EQUALS); if (!lex_force_match_id (lexer, "ENTER")) { goto error; } + + if (! variables_seen) + { + if (!parse_variables_const (lexer, dict, + ®ression.vars, ®ression.n_vars, + PV_NO_DUPLICATE | PV_NUMERIC)) + goto error; + } } else if (lex_match_id (lexer, "STATISTICS")) { diff --git a/tests/language/stats/regression.at b/tests/language/stats/regression.at index d487ca8a8b..e520bb1138 100644 --- a/tests/language/stats/regression.at +++ b/tests/language/stats/regression.at @@ -2204,3 +2204,60 @@ regression AT_CHECK([pspp -o pspp.csv empty-parens.sps], [1], [ignore]) AT_CLEANUP + + + + +AT_SETUP([LINEAR REGRESSION varibles on ENTER subcommand]) +AT_DATA([regression.sps], [dnl +SET FORMAT=F10.3. + +DATA LIST notable LIST /number * value *. +BEGIN DATA + 16 7.25 + 0 .00 + 1 .10 + 9 27.9 + 0 .00 + 7 3.65 + 14 16.8 + 24 9.15 + 0 .00 + 24 19.0 + 7 4.05 + 12 7.90 + 6 .75 + 11 1.40 + 0 .00 + 3 2.30 + 12 7.60 + 11 6.80 + 16 8.65 +END DATA. + +REGRESSION + /STATISTICS COEFF R ANOVA + /DEPENDENT value + /METHOD=ENTER number. +]) + + +AT_CHECK([pspp -O format=csv regression.sps], [0], [dnl +Table: Model Summary (value) +,R,R Square,Adjusted R Square,Std. Error of the Estimate +,.612,.374,.338,6.176 + +Table: ANOVA (value) +,,Sum of Squares,df,Mean Square,F,Sig. +,Regression,388.065,1,388.065,10.173,.005 +,Residual,648.498,17,38.147,, +,Total,1036.563,18,,, + +Table: Coefficients (value) +,,Unstandardized Coefficients,,Standardized Coefficients,, +,,B,Std. Error,Beta,t,Sig. +,(Constant),.927,2.247,.000,.413,.685 +,number,.611,.192,.612,3.189,.005 +]) + +AT_CLEANUP -- 2.30.2