Implemented the NPAR TESTS command.
[pspp-builds.git] / tests / command / npar-chisquare.sh
1 #!/bin/sh
2
3 # This program tests the chisquare subcommand of the NPAR command.
4
5 TEMPDIR=/tmp/pspp-tst-$$
6 TESTFILE=$TEMPDIR/`basename $0`.sps
7
8 # ensure that top_srcdir and top_builddir  are absolute
9 if [ -z "$top_srcdir" ] ; then top_srcdir=. ; fi
10 if [ -z "$top_builddir" ] ; then top_builddir=. ; fi
11 top_srcdir=`cd $top_srcdir; pwd`
12 top_builddir=`cd $top_builddir; pwd`
13
14 PSPP=$top_builddir/src/ui/terminal/pspp
15
16 STAT_CONFIG_PATH=$top_srcdir/config
17 export STAT_CONFIG_PATH
18
19 LANG=C
20 export LANG
21
22
23 cleanup()
24 {
25      if [ x"$PSPP_TEST_NO_CLEANUP" != x ] ; then 
26         echo "NOT cleaning $TEMPDIR"
27         return ; 
28      fi
29      rm -rf $TEMPDIR
30 }
31
32
33 fail()
34 {
35     echo $activity
36     echo FAILED
37     cleanup;
38     exit 1;
39 }
40
41
42 no_result()
43 {
44     echo $activity
45     echo NO RESULT;
46     cleanup;
47     exit 2;
48 }
49
50 pass()
51 {
52     cleanup;
53     exit 0;
54 }
55
56 mkdir -p $TEMPDIR
57
58 cd $TEMPDIR
59
60 activity="create file 1"
61 cat <<EOF > $TESTFILE
62 DATA LIST NOTABLE LIST /x * y * w *.
63 BEGIN DATA.
64 1   2  1
65 2   1  3
66 3.1 1  4
67 3.2 2  1
68 4   2  2
69 5   3  1
70 1   4  2
71 END DATA.
72
73 WEIGHT BY w.
74
75 NPAR TESTS
76   CHISQUARE=x y
77   .
78
79 NPAR TESTS
80   CHISQUARE=y
81   /EXPECTED=3 4 5 4
82   .
83
84 NPAR TESTS
85   CHISQUARE=x y(2, 4)
86   /EXPECTED = 6 10 3
87   .
88
89 EOF
90 if [ $? -ne 0 ] ; then no_result ; fi
91
92
93 activity="run program 1"
94 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
95 if [ $? -ne 0 ] ; then no_result ; fi
96
97 activity="compare output 1"
98 diff $TEMPDIR/pspp.list - << EOF
99 1.1 NPAR TESTS.  x
100 +--------#----------+----------+--------+
101 |        #Observed N|Expected N|Residual|
102 +--------#----------+----------+--------+
103 |    1.00#         3|      2.33|     .67|
104 |    2.00#         3|      2.33|     .67|
105 |    3.10#         4|      2.33|    1.67|
106 |    3.20#         1|      2.33|   -1.33|
107 |    4.00#         2|      2.33|    -.33|
108 |    5.00#         1|      2.33|   -1.33|
109 |Total   #        14|          |        |
110 +--------#----------+----------+--------+
111
112 1.2 NPAR TESTS.  y
113 +--------#----------+----------+--------+
114 |        #Observed N|Expected N|Residual|
115 +--------#----------+----------+--------+
116 |    1.00#         7|      3.50|    3.50|
117 |    2.00#         4|      3.50|     .50|
118 |    3.00#         1|      3.50|   -2.50|
119 |    4.00#         2|      3.50|   -1.50|
120 |Total   #        14|          |        |
121 +--------#----------+----------+--------+
122
123 1.3 NPAR TESTS.  Test Statistics
124 +-----------#-----+-----+
125 |           #  x  |  y  |
126 +-----------#-----+-----+
127 |Chi-Square #3.143|6.000|
128 |df         #    5|    3|
129 |Asymp. Sig.# .678| .112|
130 +-----------#-----+-----+
131
132 2.1 NPAR TESTS.  y
133 +--------#----------+----------+--------+
134 |        #Observed N|Expected N|Residual|
135 +--------#----------+----------+--------+
136 |    1.00#         7|      2.63|    4.38|
137 |    2.00#         4|      3.50|     .50|
138 |    3.00#         1|      4.38|   -3.38|
139 |    4.00#         2|      3.50|   -1.50|
140 |Total   #        14|          |        |
141 +--------#----------+----------+--------+
142
143 2.2 NPAR TESTS.  Test Statistics
144 +-----------#------+
145 |           #   y  |
146 +-----------#------+
147 |Chi-Square #10.610|
148 |df         #     3|
149 |Asymp. Sig.#  .014|
150 +-----------#------+
151
152 3.1 NPAR TESTS.  Frequencies
153 +-----#---------------------------------------#---------------------------------------+
154 |     #                   x                   #                   y                   |
155 |     #--------+----------+----------+--------#--------+----------+----------+--------+
156 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
157 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
158 |1    #    2.00|         3|      3.16|    -.16#    2.00|         4|      2.21|    1.79|
159 |2    #    3.00|         5|      5.26|    -.26#    3.00|         1|      3.68|   -2.68|
160 |3    #    4.00|         2|      1.58|     .42#    4.00|         2|      1.11|     .89|
161 |Total#        |        10|          |        #        |         7|          |        |
162 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
163
164 3.2 NPAR TESTS.  Test Statistics
165 +-----------#----+-----+
166 |           #  x |  y  |
167 +-----------#----+-----+
168 |Chi-Square #.133|4.129|
169 |df         #   2|    2|
170 |Asymp. Sig.#.936| .127|
171 +-----------#----+-----+
172
173 EOF
174 if [ $? -ne 0 ] ; then fail ; fi
175
176
177 activity="create file 2"
178 cat <<EOF > $TESTFILE
179 DATA LIST NOTABLE LIST /x * y * w *.
180 BEGIN DATA.
181 1   2  1
182 2   1  3
183 3.1 1  4
184 3.2 2  1
185 4   2  2
186 5   3  1
187 1   4  2
188 END DATA.
189
190 WEIGHT BY w.
191
192 NPAR TESTS
193   CHISQUARE=y
194   /EXPECTED = 3 4 5 4 3 1
195   .
196 EOF
197 if [ $? -ne 0 ] ; then no_result ; fi
198
199
200 activity="run program 2"
201 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE  > $TEMPDIR/output
202 if [ $? -eq 0 ] ; then no_result ; fi
203
204 activity="compare errors 2"
205 diff  $TEMPDIR/output - << EOF
206 error: CHISQUARE test specified 6 expected values, but 4 distinct values were encountered in variable y.
207 EOF
208 if [ $? -ne 0 ] ; then fail ; fi
209
210
211 activity="create file 3"
212 cat <<EOF > $TESTFILE
213 DATA LIST NOTABLE LIST /x * y * w * .
214 BEGIN DATA.
215 1   2  1 
216 2   1  3
217 3.1 1  4
218 3.2 2  1
219 4   2  2
220 5   3  1
221 1   4  2
222 .   5  1
223 END DATA.
224
225 WEIGHT BY w.
226
227 MISSING VALUES x (4).
228
229 NPAR TESTS
230   CHISQUARE=x y(-2,5)
231   /MISSING=ANALYSIS
232   /STATISTICS=DESCRIPTIVES
233   .
234 EOF
235 if [ $? -ne 0 ] ; then no_result ; fi
236
237
238 activity="run program 3"
239 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE 
240 if [ $? -ne 0 ] ; then no_result ; fi
241
242
243 activity="compare output 3"
244 diff $TEMPDIR/pspp.list - <<EOF
245 1.1 NPAR TESTS.  Frequencies
246 +-----#---------------------------------------#---------------------------------------+
247 |     #                   x                   #                   y                   |
248 |     #--------+----------+----------+--------#--------+----------+----------+--------+
249 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
250 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
251 |1    #   -2.00|         0|      1.50|   -1.50#   -2.00|         0|      1.88|   -1.88|
252 |2    #   -1.00|         0|      1.50|   -1.50#   -1.00|         0|      1.88|   -1.88|
253 |3    #     .00|         0|      1.50|   -1.50#     .00|         0|      1.88|   -1.88|
254 |4    #    1.00|         3|      1.50|    1.50#    1.00|         7|      1.88|    5.13|
255 |5    #    2.00|         3|      1.50|    1.50#    2.00|         4|      1.88|    2.13|
256 |6    #    3.00|         5|      1.50|    3.50#    3.00|         1|      1.88|    -.88|
257 |7    #    4.00|         0|      1.50|   -1.50#    4.00|         2|      1.88|     .13|
258 |8    #    5.00|         1|      1.50|    -.50#    5.00|         1|      1.88|    -.88|
259 |Total#        |        12|          |        #        |        15|          |        |
260 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
261
262 1.2 NPAR TESTS.  Test Statistics
263 +-----------#------+------+
264 |           #   x  |   y  |
265 +-----------#------+------+
266 |Chi-Square #17.333|22.867|
267 |df         #     7|     7|
268 |Asymp. Sig.#  .015|  .002|
269 +-----------#------+------+
270
271 1.3 NPAR TESTS.  Descriptive Statistics
272 +-#--+-----+-----+-----+-----+
273 | # N| Mean| Std.|Minim|Maxim|
274 | #  |     |Devia|  um |  um |
275 #=#==#=====#=====#=====#=====#
276 |x#12|2.467|1.193|1.000|5.000|
277 |y#15|2.067|1.335|1.000|5.000|
278 +-#--+-----+-----+-----+-----+
279
280 EOF
281 if [ $? -ne 0 ] ; then fail ; fi
282
283
284 activity="create file 4"
285 cat <<EOF > $TESTFILE
286 DATA LIST NOTABLE LIST /x * y * w * .
287 BEGIN DATA.
288 1   2  1 
289 2   1  3
290 3.1 1  4
291 3.2 2  1
292 4   2  2
293 5   3  1
294 1   4  2
295 .   5  1
296 END DATA.
297
298 WEIGHT BY w.
299
300 * MISSING VALUES x (4).
301
302 NPAR TESTS
303   CHISQUARE=x y(-2,5)
304   /MISSING=LISTWISE
305   /STATISTICS=DESCRIPTIVES
306   .
307 EOF
308 if [ $? -ne 0 ] ; then no_result ; fi
309
310
311 activity="run program 4"
312 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE 
313 if [ $? -ne 0 ] ; then no_result ; fi
314
315
316 activity="compare output 4"
317 diff $TEMPDIR/pspp.list - <<EOF
318 1.1 NPAR TESTS.  Frequencies
319 +-----#---------------------------------------#---------------------------------------+
320 |     #                   x                   #                   y                   |
321 |     #--------+----------+----------+--------#--------+----------+----------+--------+
322 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
323 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
324 |1    #   -2.00|         0|      1.75|   -1.75#   -2.00|         0|      1.75|   -1.75|
325 |2    #   -1.00|         0|      1.75|   -1.75#   -1.00|         0|      1.75|   -1.75|
326 |3    #     .00|         0|      1.75|   -1.75#     .00|         0|      1.75|   -1.75|
327 |4    #    1.00|         3|      1.75|    1.25#    1.00|         7|      1.75|    5.25|
328 |5    #    2.00|         3|      1.75|    1.25#    2.00|         4|      1.75|    2.25|
329 |6    #    3.00|         5|      1.75|    3.25#    3.00|         1|      1.75|    -.75|
330 |7    #    4.00|         2|      1.75|     .25#    4.00|         2|      1.75|     .25|
331 |8    #    5.00|         1|      1.75|    -.75#    5.00|         0|      1.75|   -1.75|
332 |Total#        |        14|          |        #        |        14|          |        |
333 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
334
335 1.2 NPAR TESTS.  Test Statistics
336 +-----------#------+------+
337 |           #   x  |   y  |
338 +-----------#------+------+
339 |Chi-Square #13.429|26.000|
340 |df         #     7|     7|
341 |Asymp. Sig.#  .062|  .001|
342 +-----------#------+------+
343
344 1.3 NPAR TESTS.  Descriptive Statistics
345 +-#--+-----+-----+-----+-----+
346 | # N| Mean| Std.|Minim|Maxim|
347 | #  |     |Devia|  um |  um |
348 #=#==#=====#=====#=====#=====#
349 |x#14|2.686|1.231|1.000|5.000|
350 |y#14|1.857|1.099|1.000|4.000|
351 +-#--+-----+-----+-----+-----+
352
353 EOF
354 if [ $? -ne 0 ] ; then fail ; fi
355
356
357 pass;