FREQUENCIES: Implement LAYERED option on SPLIT FILE.
[pspp] / tests / language / stats / frequencies.at
index ca0467264e84a7f63abf8cec3cc40a846c0129e5..5ab31a5d9f4b1fee361448e52ddb64e38f71eb41 100644 (file)
@@ -1,16 +1,16 @@
 dnl PSPP - a program for statistical analysis.
 dnl Copyright (C) 2017 Free Software Foundation, Inc.
-dnl 
+dnl
 dnl This program is free software: you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
 dnl the Free Software Foundation, either version 3 of the License, or
 dnl (at your option) any later version.
-dnl 
+dnl
 dnl This program is distributed in the hope that it will be useful,
 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 dnl GNU General Public License for more details.
-dnl 
+dnl
 dnl You should have received a copy of the GNU General Public License
 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
 dnl
@@ -47,6 +47,163 @@ Total,,10,100.0%,,
 ])
 AT_CLEANUP
 
+AT_SETUP([FREQUENCIES with SPLIT FILE - LAYERED])
+AT_DATA([frequencies.sps], [dnl
+DATA LIST LIST NOTABLE/name (A8) value quantity.
+BEGIN DATA.
+foo 1 5
+bar 2 6
+baz 1 9
+quux 3 1
+bar 1 2
+baz 4 3
+baz 1 4
+baz 1 1
+foo 6 0
+quux 5 8
+END DATA.
+EXECUTE.
+
+SORT CASES BY name.
+SPLIT FILE BY name.
+FREQUENCIES /VARIABLES=value quantity /FORMAT NOTABLE.
+])
+AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
+Table: Statistics
+,,name,,,,,,,
+,,bar,,baz,,foo,,quux,
+,,value,quantity,value,quantity,value,quantity,value,quantity
+N,Valid,2,2,4,4,2,2,2,2
+,Missing,0,0,0,0,0,0,0,0
+Mean,,1.50,4.00,1.75,4.25,3.50,2.50,4.00,4.50
+Std Dev,,.71,2.83,1.50,3.40,3.54,3.54,1.41,4.95
+Minimum,,1.00,2.00,1.00,1.00,1.00,.00,3.00,1.00
+Maximum,,2.00,6.00,4.00,9.00,6.00,5.00,5.00,8.00
+])
+AT_CLEANUP
+
+AT_SETUP([FREQUENCIES with SPLIT FILE - SEPARATE])
+AT_DATA([frequencies.sps], [dnl
+DATA LIST LIST NOTABLE/name (A8) value quantity.
+BEGIN DATA.
+foo 1 5
+bar 2 6
+baz 1 9
+quux 3 1
+bar 1 2
+baz 4 3
+baz 1 4
+baz 1 1
+foo 6 0
+quux 5 8
+END DATA.
+EXECUTE.
+
+SORT CASES BY name.
+SPLIT FILE SEPARATE BY name.
+FREQUENCIES /VARIABLES=value quantity /FORMAT NOTABLE.
+])
+AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
+Table: Split Values
+Variable,Value
+name,bar
+
+Table: Statistics
+,,value,quantity
+N,Valid,2,2
+,Missing,0,0
+Mean,,1.50,4.00
+Std Dev,,.71,2.83
+Minimum,,1.00,2.00
+Maximum,,2.00,6.00
+
+Table: Split Values
+Variable,Value
+name,baz
+
+Table: Statistics
+,,value,quantity
+N,Valid,4,4
+,Missing,0,0
+Mean,,1.75,4.25
+Std Dev,,1.50,3.40
+Minimum,,1.00,1.00
+Maximum,,4.00,9.00
+
+Table: Split Values
+Variable,Value
+name,foo
+
+Table: Statistics
+,,value,quantity
+N,Valid,2,2
+,Missing,0,0
+Mean,,3.50,2.50
+Std Dev,,3.54,3.54
+Minimum,,1.00,.00
+Maximum,,6.00,5.00
+
+Table: Split Values
+Variable,Value
+name,quux
+
+Table: Statistics
+,,value,quantity
+N,Valid,2,2
+,Missing,0,0
+Mean,,4.00,4.50
+Std Dev,,1.41,4.95
+Minimum,,3.00,1.00
+Maximum,,5.00,8.00
+])
+AT_CLEANUP
+
+AT_SETUP([FREQUENCIES with SPLIT FILE - LAYERED - unsorted data])
+AT_DATA([frequencies.sps], [dnl
+DATA LIST LIST NOTABLE/name (A8) value quantity.
+BEGIN DATA.
+foo 1 5
+bar 2 6
+baz 1 9
+quux 3 1
+baz 4 3
+bar 1 2
+baz 1 1
+foo 6 0
+baz 1 4
+quux 5 8
+END DATA.
+EXECUTE.
+
+SPLIT FILE BY name.
+FREQUENCIES /VARIABLES=value quantity /FORMAT NOTABLE.
+])
+AT_CHECK([pspp -O format=csv frequencies.sps], [0], [dnl
+"frequencies.sps:17: warning: FREQUENCIES: When SPLIT FILE is in effect, the input data must be sorted by the split variables (for example, using SORT CASES), but multiple runs of cases with the same split values were found separated by cases with different values.  Each run will be analyzed separately.  The duplicate split values are: name = baz     "
+
+"frequencies.sps:17: warning: FREQUENCIES: When SPLIT FILE is in effect, the input data must be sorted by the split variables (for example, using SORT CASES), but multiple runs of cases with the same split values were found separated by cases with different values.  Each run will be analyzed separately.  The duplicate split values are: name = bar     "
+
+"frequencies.sps:17: warning: FREQUENCIES: When SPLIT FILE is in effect, the input data must be sorted by the split variables (for example, using SORT CASES), but multiple runs of cases with the same split values were found separated by cases with different values.  Each run will be analyzed separately.  The duplicate split values are: name = baz     "
+
+"frequencies.sps:17: warning: FREQUENCIES: When SPLIT FILE is in effect, the input data must be sorted by the split variables (for example, using SORT CASES), but multiple runs of cases with the same split values were found separated by cases with different values.  Each run will be analyzed separately.  The duplicate split values are: name = foo     "
+
+"frequencies.sps:17: warning: FREQUENCIES: When SPLIT FILE is in effect, the input data must be sorted by the split variables (for example, using SORT CASES), but multiple runs of cases with the same split values were found separated by cases with different values.  Each run will be analyzed separately.  The duplicate split values are: name = baz     "
+
+Table: Statistics
+,,name,,,,,,,,,,,,,,,,,,,
+,,foo,,bar,,baz,,quux,,baz,,bar,,baz,,foo,,baz,,quux,
+,,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity,value,quantity
+N,Valid,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
+,Missing,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
+Mean,,1.00,5.00,2.00,6.00,1.00,9.00,3.00,1.00,4.00,3.00,1.00,2.00,1.00,1.00,6.00,.00,1.00,4.00,5.00,8.00
+Std Dev,,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN,NaN
+Minimum,,1.00,5.00,2.00,6.00,1.00,9.00,3.00,1.00,4.00,3.00,1.00,2.00,1.00,1.00,6.00,.00,1.00,4.00,5.00,8.00
+Maximum,,1.00,5.00,2.00,6.00,1.00,9.00,3.00,1.00,4.00,3.00,1.00,2.00,1.00,1.00,6.00,.00,1.00,4.00,5.00,8.00
+
+frequencies.sps:17: warning: FREQUENCIES: Suppressed 1 additional warning about duplicate split values.
+])
+AT_CLEANUP
+
 # Tests for a bug where pspp would crash if two FREQUENCIES commands
 # existed in a input file.
 AT_SETUP([FREQUENCIES two runs crash])
@@ -54,7 +211,7 @@ AT_DATA([frequencies.sps],
   [data list free /v1 v2.
 begin data.
 0 1
-2 3 
+2 3
 4 5
 3 4
 end data.
@@ -127,7 +284,7 @@ AT_DATA([frequencies.sps],
   [data list free /v1 v2.
 begin data.
 0 1
-2 3 
+2 3
 4 5
 3 4
 end data.
@@ -212,14 +369,14 @@ end data.
 
 weight by w.
 
-frequencies /x 
-           /format=notable 
+frequencies /x
+           /format=notable
            /statistics=none
            /histogram=minimum(0) maximum(50) percent(5) normal.
 ])
 # Cannot use the CSV driver for this because it does not output charts
 # at all.
-AT_CHECK([pspp -O format=pdf frequencies.sps], [0], [ignore])
+AT_CHECK([pspp -O format=pdf frequencies.sps], [0], [ignore], [ignore])
 AT_CLEANUP
 
 # Tests for a bug which crashed PSPP when the median and a histogram
@@ -288,34 +445,34 @@ AT_CLEANUP
 
 m4_define([FREQUENCIES_NTILES_OUTPUT], [dnl
 Table: Statistics
-,,x
-N,Valid,5
-,Missing,0
-Mean,,3.00
-Std Dev,,1.58
-Minimum,,1.00
-Maximum,,5.00
-Percentiles,0,1.00
-,25,2.00
-,33,2.33
-,50,3.00
-,67,3.67
-,75,4.00
-,100,5.00
+,,x,y
+N,Valid,5,5
+,Missing,0,0
+Mean,,3.00,30.00
+Std Dev,,1.58,15.81
+Minimum,,1.00,10.00
+Maximum,,5.00,50.00
+Percentiles,0,1.00,10.00
+,25,2.00,20.00
+,33,2.33,23.33
+,50,3.00,30.00
+,67,3.67,36.67
+,75,4.00,40.00
+,100,5.00,50.00
 ])
 AT_SETUP([FREQUENCIES basic percentiles])
 AT_DATA([frequencies.sps],
-  [DATA LIST LIST notable /x .
+  [DATA LIST LIST notable /x y.
 BEGIN DATA.
-1 
-2 
-3 
-4 
-5
+1 10
+2 20
+3 30
+4 40
+5 50
 END DATA.
 
-FREQUENCIES 
-       VAR=x
+FREQUENCIES
+       VAR=x y
        /FORMAT=NOTABLE
        /PERCENTILES = 0 25 33.333 50 66.666 75 100.
 ])
@@ -325,17 +482,17 @@ AT_CLEANUP
 
 AT_SETUP([FREQUENCIES basic n-tiles])
 AT_DATA([frequencies.sps],
-  [DATA LIST LIST notable /x .
+  [DATA LIST LIST notable /x y.
 BEGIN DATA.
-1 
-2 
-3 
-4 
-5
+1 10
+2 20
+3 30
+4 40
+5 50
 END DATA.
 
-FREQUENCIES 
-       VAR=x
+FREQUENCIES
+       VAR=x y
        /FORMAT=NOTABLE
        /NTILES = 3
        /NTILES = 4.
@@ -348,14 +505,14 @@ AT_SETUP([FREQUENCIES compatibility percentiles])
 AT_DATA([frequencies.sps],
   [DATA LIST LIST notable /X * .
 BEGIN DATA.
-1 
-2 
-3 
-4 
+1
+2
+3
+4
 5
 END DATA.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /ALGORITHM=COMPATIBLE
        /PERCENTILES = 0 25 50 75 100.
@@ -390,14 +547,14 @@ AT_SETUP([FREQUENCIES enhanced percentiles])
 AT_DATA([frequencies.sps],
   [DATA LIST LIST notable /X * .
 BEGIN DATA.
-1 
-2 
-3 
-4 
+1
+2
+3
+4
 5
 END DATA.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -442,7 +599,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -485,7 +642,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -527,7 +684,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -571,7 +728,7 @@ END DATA.
 MISSING VALUE x (99.0) .
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -606,23 +763,23 @@ AT_SETUP([FREQUENCIES dichotomous histogram])
 AT_DATA([frequencies.sps], [dnl
 data list notable list /d4 *.
 begin data.
-0 
-0 
-0 
-1 
-0 
-0 
-0 
-0 
-1 
-0 
-0 
-0 
-0 
-0 
-1 
-2 
-0 
+0
+0
+0
+1
+0
+0
+0
+0
+1
+0
+0
+0
+0
+0
+1
+2
+0
 end data.
 
 FREQUENCIES
@@ -793,9 +950,9 @@ Maximum,,.  @&t@
 Sum,,.  @&t@
 
 Table: x
-,,Frequency,Percent,Valid Percent,Cumulative Percent
-Missing,.  ,3,100.0%,,
-Total,,3,.0%,,
+,,Frequency,Percent
+Missing,.  ,3,100.0%
+Total,,3,.0%
 ])
 
 AT_CLEANUP
@@ -845,3 +1002,44 @@ FREQUENCIES VARIABLES=SCORE
 AT_CHECK([pspp bug.sps], [0],  [ignore])
 
 AT_CLEANUP
+
+
+AT_SETUP([FREQUENCIES vs. missing weights])
+AT_DATA([warn.sps], [dnl
+data list notable list /x w .
+begin data.
+1 1
+2 1
+1 1
+3 1
+3 .
+4 .
+end data.
+
+weight by w.
+
+frequencies /variables=x.
+])
+
+AT_CHECK([pspp warn.sps -O format=csv], [0],  [dnl
+"warn.sps:13: warning: FREQUENCIES: At least one case in the data file had a weight value that was user-missing, system-missing, zero, or negative.  These case(s) were ignored."
+
+Table: Statistics
+,,x
+N,Valid,4.00
+,Missing,.00
+Mean,,1.75
+Std Dev,,.96
+Minimum,,1.00
+Maximum,,4.00
+
+Table: x
+,,Frequency,Percent,Valid Percent,Cumulative Percent
+Valid,1.00,2.00,50.0%,50.0%,50.0%
+,2.00,1.00,25.0%,25.0%,75.0%
+,3.00,1.00,25.0%,25.0%,100.0%
+,4.00,.00,.0%,.0%,100.0%
+Total,,4.00,100.0%,,
+])
+
+AT_CLEANUP