FREQUENCIES: Fix percentiles and median calculation for multiple variables.
[pspp] / tests / language / stats / frequencies.at
index ca0467264e84a7f63abf8cec3cc40a846c0129e5..ad922bc11473d3f153f56c6e4b75a7332285ffd2 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
@@ -54,7 +54,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 +127,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 +212,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 +288,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 +325,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 +348,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 +390,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 +442,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -485,7 +485,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -527,7 +527,7 @@ END DATA.
 
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -571,7 +571,7 @@ END DATA.
 MISSING VALUE x (99.0) .
 WEIGHT BY f.
 
-FREQUENCIES 
+FREQUENCIES
        VAR=x
        /PERCENTILES = 0 25 50 75 100.
 ])
@@ -606,23 +606,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 +793,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 +845,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