Enabled the autoscroll feature on the datasheet.
[pspp] / 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 $TESTFILE
95 if [ $? -ne 0 ] ; then no_result ; fi
96
97 activity="compare output 1"
98 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
99 diff -b $TEMPDIR/pspp.list - << EOF
100 1.1 NPAR TESTS.  x
101 +--------#----------+----------+--------+
102 |        #Observed N|Expected N|Residual|
103 +--------#----------+----------+--------+
104 |    1.00#         3|      2.33|     .67|
105 |    2.00#         3|      2.33|     .67|
106 |    3.10#         4|      2.33|    1.67|
107 |    3.20#         1|      2.33|   -1.33|
108 |    4.00#         2|      2.33|    -.33|
109 |    5.00#         1|      2.33|   -1.33|
110 |Total   #        14|          |        |
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 1.3 NPAR TESTS.  Test Statistics
123 +-----------#-----+-----+
124 |           #  x  |  y  |
125 +-----------#-----+-----+
126 |Chi-Square #3.143|6.000|
127 |df         #    5|    3|
128 |Asymp. Sig.# .678| .112|
129 +-----------#-----+-----+
130 2.1 NPAR TESTS.  y
131 +--------#----------+----------+--------+
132 |        #Observed N|Expected N|Residual|
133 +--------#----------+----------+--------+
134 |    1.00#         7|      2.63|    4.38|
135 |    2.00#         4|      3.50|     .50|
136 |    3.00#         1|      4.38|   -3.38|
137 |    4.00#         2|      3.50|   -1.50|
138 |Total   #        14|          |        |
139 +--------#----------+----------+--------+
140 2.2 NPAR TESTS.  Test Statistics
141 +-----------#------+
142 |           #   y  |
143 +-----------#------+
144 |Chi-Square #10.610|
145 |df         #     3|
146 |Asymp. Sig.#  .014|
147 +-----------#------+
148 3.1 NPAR TESTS.  Frequencies
149 +-----#---------------------------------------#---------------------------------------+
150 |     #                   x                   #                   y                   |
151 |     #--------+----------+----------+--------#--------+----------+----------+--------+
152 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
153 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
154 |1    #    2.00|         3|      3.16|    -.16#    2.00|         4|      2.21|    1.79|
155 |2    #    3.00|         5|      5.26|    -.26#    3.00|         1|      3.68|   -2.68|
156 |3    #    4.00|         2|      1.58|     .42#    4.00|         2|      1.11|     .89|
157 |Total#        |        10|          |        #        |         7|          |        |
158 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
159 3.2 NPAR TESTS.  Test Statistics
160 +-----------#----+-----+
161 |           #  x |  y  |
162 +-----------#----+-----+
163 |Chi-Square #.133|4.129|
164 |df         #   2|    2|
165 |Asymp. Sig.#.936| .127|
166 +-----------#----+-----+
167 EOF
168 if [ $? -ne 0 ] ; then fail ; fi
169
170
171 activity="create file 2"
172 cat <<EOF > $TESTFILE
173 DATA LIST NOTABLE LIST /x * y * w *.
174 BEGIN DATA.
175 1   2  1
176 2   1  3
177 3.1 1  4
178 3.2 2  1
179 4   2  2
180 5   3  1
181 1   4  2
182 END DATA.
183
184 WEIGHT BY w.
185
186 NPAR TESTS
187   CHISQUARE=y
188   /EXPECTED = 3 4 5 4 3 1
189   .
190 EOF
191 if [ $? -ne 0 ] ; then no_result ; fi
192
193
194 activity="run program 2"
195 $SUPERVISOR $PSPP --testing-mode $TESTFILE  > $TEMPDIR/output
196 if [ $? -eq 0 ] ; then no_result ; fi
197
198 activity="compare errors 2"
199 perl -pi -e 's/^\s*$//g' $TEMPDIR/output
200 diff -b  $TEMPDIR/output - << EOF
201 error: CHISQUARE test specified 6 expected values, but 4 distinct values were encountered in variable y.
202 EOF
203 if [ $? -ne 0 ] ; then fail ; fi
204
205
206 activity="create file 3"
207 cat <<EOF > $TESTFILE
208 DATA LIST NOTABLE LIST /x * y * w * .
209 BEGIN DATA.
210 1   2  1 
211 2   1  3
212 3.1 1  4
213 3.2 2  1
214 4   2  2
215 5   3  1
216 1   4  2
217 .   5  1
218 END DATA.
219
220 WEIGHT BY w.
221
222 MISSING VALUES x (4).
223
224 NPAR TESTS
225   CHISQUARE=x y(-2,5)
226   /MISSING=ANALYSIS
227   /STATISTICS=DESCRIPTIVES
228   .
229 EOF
230 if [ $? -ne 0 ] ; then no_result ; fi
231
232
233 activity="run program 3"
234 $SUPERVISOR $PSPP --testing-mode $TESTFILE 
235 if [ $? -ne 0 ] ; then no_result ; fi
236
237
238 activity="compare output 3"
239 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
240 diff -b $TEMPDIR/pspp.list - <<EOF
241 1.1 NPAR TESTS.  Frequencies
242 +-----#---------------------------------------#---------------------------------------+
243 |     #                   x                   #                   y                   |
244 |     #--------+----------+----------+--------#--------+----------+----------+--------+
245 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
246 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
247 |1    #   -2.00|         0|      1.50|   -1.50#   -2.00|         0|      1.88|   -1.88|
248 |2    #   -1.00|         0|      1.50|   -1.50#   -1.00|         0|      1.88|   -1.88|
249 |3    #     .00|         0|      1.50|   -1.50#     .00|         0|      1.88|   -1.88|
250 |4    #    1.00|         3|      1.50|    1.50#    1.00|         7|      1.88|    5.13|
251 |5    #    2.00|         3|      1.50|    1.50#    2.00|         4|      1.88|    2.13|
252 |6    #    3.00|         5|      1.50|    3.50#    3.00|         1|      1.88|    -.88|
253 |7    #    4.00|         0|      1.50|   -1.50#    4.00|         2|      1.88|     .13|
254 |8    #    5.00|         1|      1.50|    -.50#    5.00|         1|      1.88|    -.88|
255 |Total#        |        12|          |        #        |        15|          |        |
256 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
257 1.2 NPAR TESTS.  Test Statistics
258 +-----------#------+------+
259 |           #   x  |   y  |
260 +-----------#------+------+
261 |Chi-Square #17.333|22.867|
262 |df         #     7|     7|
263 |Asymp. Sig.#  .015|  .002|
264 +-----------#------+------+
265 1.3 NPAR TESTS.  Descriptive Statistics
266 +-#--+-----+-----+-----+-----+
267 | # N| Mean| Std.|Minim|Maxim|
268 | #  |     |Devia|  um |  um |
269 #=#==#=====#=====#=====#=====#
270 |x#12|2.467|1.193|1.000|5.000|
271 |y#15|2.067|1.335|1.000|5.000|
272 +-#--+-----+-----+-----+-----+
273 EOF
274 if [ $? -ne 0 ] ; then fail ; fi
275
276
277 activity="create file 4"
278 cat <<EOF > $TESTFILE
279 DATA LIST NOTABLE LIST /x * y * w * .
280 BEGIN DATA.
281 1   2  1 
282 2   1  3
283 3.1 1  4
284 3.2 2  1
285 4   2  2
286 5   3  1
287 1   4  2
288 .   5  1
289 END DATA.
290
291 WEIGHT BY w.
292
293 * MISSING VALUES x (4).
294
295 NPAR TESTS
296   CHISQUARE=x y(-2,5)
297   /MISSING=LISTWISE
298   /STATISTICS=DESCRIPTIVES
299   .
300 EOF
301 if [ $? -ne 0 ] ; then no_result ; fi
302
303
304 activity="run program 4"
305 $SUPERVISOR $PSPP --testing-mode $TESTFILE 
306 if [ $? -ne 0 ] ; then no_result ; fi
307
308
309 activity="compare output 4"
310 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
311 diff -b $TEMPDIR/pspp.list - <<EOF
312 1.1 NPAR TESTS.  Frequencies
313 +-----#---------------------------------------#---------------------------------------+
314 |     #                   x                   #                   y                   |
315 |     #--------+----------+----------+--------#--------+----------+----------+--------+
316 |     #Category|Observed N|Expected N|Residual#Category|Observed N|Expected N|Residual|
317 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
318 |1    #   -2.00|         0|      1.75|   -1.75#   -2.00|         0|      1.75|   -1.75|
319 |2    #   -1.00|         0|      1.75|   -1.75#   -1.00|         0|      1.75|   -1.75|
320 |3    #     .00|         0|      1.75|   -1.75#     .00|         0|      1.75|   -1.75|
321 |4    #    1.00|         3|      1.75|    1.25#    1.00|         7|      1.75|    5.25|
322 |5    #    2.00|         3|      1.75|    1.25#    2.00|         4|      1.75|    2.25|
323 |6    #    3.00|         5|      1.75|    3.25#    3.00|         1|      1.75|    -.75|
324 |7    #    4.00|         2|      1.75|     .25#    4.00|         2|      1.75|     .25|
325 |8    #    5.00|         1|      1.75|    -.75#    5.00|         0|      1.75|   -1.75|
326 |Total#        |        14|          |        #        |        14|          |        |
327 +-----#--------+----------+----------+--------#--------+----------+----------+--------+
328 1.2 NPAR TESTS.  Test Statistics
329 +-----------#------+------+
330 |           #   x  |   y  |
331 +-----------#------+------+
332 |Chi-Square #13.429|26.000|
333 |df         #     7|     7|
334 |Asymp. Sig.#  .062|  .001|
335 +-----------#------+------+
336 1.3 NPAR TESTS.  Descriptive Statistics
337 +-#--+-----+-----+-----+-----+
338 | # N| Mean| Std.|Minim|Maxim|
339 | #  |     |Devia|  um |  um |
340 #=#==#=====#=====#=====#=====#
341 |x#14|2.686|1.231|1.000|5.000|
342 |y#14|1.857|1.099|1.000|4.000|
343 +-#--+-----+-----+-----+-----+
344 EOF
345 if [ $? -ne 0 ] ; then fail ; fi
346
347
348 pass;