REGRESSION: Allow independent variables to be specified on the ENTER subcommand.
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 9 May 2017 07:46:29 +0000 (09:46 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 9 May 2017 07:46:29 +0000 (09:46 +0200)
This is more typical of the syntax that third party software generates.

src/language/stats/regression.c
tests/language/stats/regression.at

index f7ec679a1c5c4180aa244e5e0f2e8b344654e582..d7608927da97e2d5e400e83e22257fcbc6d80b8b 100644 (file)
@@ -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,
-                              &regression.vars, &regression.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,
+                                     &regression.vars, &regression.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,
+                                         &regression.vars, &regression.n_vars,
+                                         PV_NO_DUPLICATE | PV_NUMERIC))
+               goto error;
+           }
         }
       else if (lex_match_id (lexer, "STATISTICS"))
         {
index d487ca8a8becbd7bac7af8e5de3c65798f64f72f..e520bb1138fe534dfeeb84c365bab3a492b27107 100644 (file)
@@ -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