Updated the example with an easier to visualise one
[pspp-builds.git] / tests / command / npar-binomial.sh
1 #!/bin/sh
2
3 # This program tests the BINOMIAL subcommand of the NPAR TESTS 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      cd /
30      rm -rf $TEMPDIR
31 }
32
33
34 fail()
35 {
36     echo $activity
37     echo FAILED
38     cleanup;
39     exit 1;
40 }
41
42
43 no_result()
44 {
45     echo $activity
46     echo NO RESULT;
47     cleanup;
48     exit 2;
49 }
50
51 pass()
52 {
53     cleanup;
54     exit 0;
55 }
56
57 mkdir -p $TEMPDIR
58
59 cd $TEMPDIR
60
61
62 # Tests for exact calculations
63 activity="create file 1"
64 cat <<EOF > $TESTFILE
65 ECHO 'P < 0.5; N1/N2 < 1' .
66
67 NEW FILE.
68
69 DATA LIST LIST NOTABLE /x * w *.
70 BEGIN DATA.
71 1   6
72 2   15
73 END DATA.
74
75 WEIGHT BY w.
76
77 SET FORMAT F8.3.
78
79 NPAR TESTS
80         /BINOMIAL(0.3) = x
81         .
82
83
84 ECHO 'P < 0.5; N1/N2 > 1' .
85
86 NEW FILE.
87
88
89
90 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
91 BEGIN DATA.
92 1   7
93 2   6
94 END DATA.
95
96 WEIGHT BY w.
97
98 NPAR TESTS
99         /BINOMIAL(0.4) = x
100         .
101
102
103
104 ECHO 'P < 0.5; N1/N2 = 1' .
105
106 NEW FILE.
107
108 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
109 BEGIN DATA.
110 1   8
111 2   8
112 END DATA.
113
114 WEIGHT BY w.
115
116 NPAR TESTS
117         /BINOMIAL(0.4) = x
118         .
119
120 ECHO 'P > 0.5; N1/N2 < 1' .
121
122 NEW FILE.
123
124 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
125 BEGIN DATA.
126 1   11
127 2   12
128 END DATA.
129
130 WEIGHT BY w.
131
132 NPAR TESTS
133         /BINOMIAL(0.6) = x
134         .
135
136
137 ECHO 'P > 0.5; N1/N2 > 1' .
138
139 NEW FILE.
140
141 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
142 BEGIN DATA.
143 1   11
144 2   9
145 END DATA.
146
147 WEIGHT BY w.
148
149 NPAR TESTS
150         /BINOMIAL(0.6) = x
151
152 ECHO 'P > 0.5; N1/N2 == 1' .
153
154 NEW FILE.
155
156 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
157 BEGIN DATA.
158 1   11
159 2   11
160 END DATA.
161
162 WEIGHT BY w.
163
164 NPAR TESTS
165         /BINOMIAL(0.6) = x
166         .
167
168 ECHO 'P == 0.5; N1/N2 < 1' .
169
170 NEW FILE.
171
172 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
173 BEGIN DATA.
174 1   8
175 2   15
176 END DATA.
177
178 WEIGHT BY w.
179
180 NPAR TESTS
181         /BINOMIAL(0.5) = x
182         .
183
184
185 ECHO 'P == 0.5; N1/N2 > 1' .
186
187 NEW FILE.
188
189 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
190 BEGIN DATA.
191 1   12
192 2   6
193 END DATA.
194
195 WEIGHT BY w.
196
197 NPAR TESTS
198         /BINOMIAL(0.5) = x
199
200 ECHO 'P == 0.5; N1/N2 == 1' .
201
202 NEW FILE.
203
204 DATA LIST LIST NOTABLE /x (F8.0) w (F8.0).
205 BEGIN DATA.
206 1   10
207 2   10
208 END DATA.
209
210 WEIGHT BY w.
211
212 NPAR TESTS
213         /BINOMIAL(0.5) = x
214         .
215
216 ECHO 'P == 0.5; N1/N2 == 1 Cutpoint' .
217
218 DATA LIST LIST NOTABLE /x * w *.
219 BEGIN DATA.
220 9    3
221 10   7
222 11   16
223 END DATA.
224
225 WEIGHT BY w.
226
227 NPAR TESTS
228         /BINOMIAL(0.5) = x (10)
229         .
230
231 ECHO 'P == 0.5; N1/N2 == 1 Named values' .
232
233 DATA LIST LIST NOTABLE /x * w *.
234 BEGIN DATA.
235 10   10
236 15   45
237 20   13
238 END DATA.
239
240 WEIGHT BY w.
241
242 NPAR TESTS
243         /BINOMIAL(0.5) = x (10, 20)
244         .
245 EOF
246 if [ $? -ne 0 ] ; then no_result ; fi
247
248
249 activity="run program 1"
250 $SUPERVISOR $PSPP --testing-mode $TESTFILE
251 if [ $? -ne 0 ] ; then no_result ; fi
252
253 activity="compare output 1"
254 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
255 diff -b $TEMPDIR/pspp.list - << EOF
256 P < 0.5; N1/N2 < 1
257 1.1 NPAR TESTS.  Binomial Test
258 +-+------#--------+-----+--------------+----------+---------------------+
259 | |      #Category|  N  |Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
260 +-+------#--------+-----+--------------+----------+---------------------+
261 |x|Group1#    1.00| 6.00|          .286|      .300|                 .551|
262 | |Group2#    2.00|15.00|          .714|          |                     |
263 | |Total #        |21.00|         1.000|          |                     |
264 +-+------#--------+-----+--------------+----------+---------------------+
265 P < 0.5; N1/N2 > 1
266 2.1 NPAR TESTS.  Binomial Test
267 +-+------#--------+--+--------------+----------+---------------------+
268 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
269 +-+------#--------+--+--------------+----------+---------------------+
270 |x|Group1#       1| 7|          .538|      .400|                 .229|
271 | |Group2#       2| 6|          .462|          |                     |
272 | |Total #        |13|         1.000|          |                     |
273 +-+------#--------+--+--------------+----------+---------------------+
274 P < 0.5; N1/N2 = 1
275 3.1 NPAR TESTS.  Binomial Test
276 +-+------#--------+--+--------------+----------+---------------------+
277 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
278 +-+------#--------+--+--------------+----------+---------------------+
279 |x|Group1#       1| 8|          .500|      .400|                 .284|
280 | |Group2#       2| 8|          .500|          |                     |
281 | |Total #        |16|         1.000|          |                     |
282 +-+------#--------+--+--------------+----------+---------------------+
283 P > 0.5; N1/N2 < 1
284 4.1 NPAR TESTS.  Binomial Test
285 +-+------#--------+--+--------------+----------+---------------------+
286 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
287 +-+------#--------+--+--------------+----------+---------------------+
288 |x|Group1#       1|11|          .478|      .600|                 .164|
289 | |Group2#       2|12|          .522|          |                     |
290 | |Total #        |23|         1.000|          |                     |
291 +-+------#--------+--+--------------+----------+---------------------+
292 P > 0.5; N1/N2 > 1
293 5.1 NPAR TESTS.  Binomial Test
294 +-+------#--------+--+--------------+----------+---------------------+
295 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
296 +-+------#--------+--+--------------+----------+---------------------+
297 |x|Group1#       1|11|          .550|      .600|                 .404|
298 | |Group2#       2| 9|          .450|          |                     |
299 | |Total #        |20|         1.000|          |                     |
300 +-+------#--------+--+--------------+----------+---------------------+
301 P > 0.5; N1/N2 == 1
302 6.1 NPAR TESTS.  Binomial Test
303 +-+------#--------+--+--------------+----------+---------------------+
304 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
305 +-+------#--------+--+--------------+----------+---------------------+
306 |x|Group1#       1|11|          .500|      .600|                 .228|
307 | |Group2#       2|11|          .500|          |                     |
308 | |Total #        |22|         1.000|          |                     |
309 +-+------#--------+--+--------------+----------+---------------------+
310 P == 0.5; N1/N2 < 1
311 7.1 NPAR TESTS.  Binomial Test
312 +-+------#--------+--+--------------+----------+---------------------+
313 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
314 +-+------#--------+--+--------------+----------+---------------------+
315 |x|Group1#       1| 8|          .348|      .500|                 .210|
316 | |Group2#       2|15|          .652|          |                     |
317 | |Total #        |23|         1.000|          |                     |
318 +-+------#--------+--+--------------+----------+---------------------+
319 P == 0.5; N1/N2 > 1
320 8.1 NPAR TESTS.  Binomial Test
321 +-+------#--------+--+--------------+----------+---------------------+
322 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
323 +-+------#--------+--+--------------+----------+---------------------+
324 |x|Group1#       1|12|          .667|      .500|                 .238|
325 | |Group2#       2| 6|          .333|          |                     |
326 | |Total #        |18|         1.000|          |                     |
327 +-+------#--------+--+--------------+----------+---------------------+
328 P == 0.5; N1/N2 == 1
329 9.1 NPAR TESTS.  Binomial Test
330 +-+------#--------+--+--------------+----------+---------------------+
331 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
332 +-+------#--------+--+--------------+----------+---------------------+
333 |x|Group1#       1|10|          .500|      .500|                1.000|
334 | |Group2#       2|10|          .500|          |                     |
335 | |Total #        |20|         1.000|          |                     |
336 +-+------#--------+--+--------------+----------+---------------------+
337 P == 0.5; N1/N2 == 1 Cutpoint
338 10.1 NPAR TESTS.  Binomial Test
339 +-+------#--------+------+--------------+----------+---------------------+
340 | |      #Category|   N  |Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
341 +-+------#--------+------+--------------+----------+---------------------+
342 |x|Group1#   <= 10|10.000|          .385|      .500|                 .327|
343 | |Group2#        |16.000|          .615|          |                     |
344 | |Total #        |26.000|         1.000|          |                     |
345 +-+------#--------+------+--------------+----------+---------------------+
346 P == 0.5; N1/N2 == 1 Named values
347 11.1 NPAR TESTS.  Binomial Test
348 +-+------#--------+------+--------------+----------+---------------------+
349 | |      #Category|   N  |Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
350 +-+------#--------+------+--------------+----------+---------------------+
351 |x|Group1#  10.000|10.000|          .435|      .500|                 .678|
352 | |Group2#  20.000|13.000|          .565|          |                     |
353 | |Total #        |23.000|         1.000|          |                     |
354 +-+------#--------+------+--------------+----------+---------------------+
355 EOF
356 if [ $? -ne 0 ] ; then fail ; fi
357
358
359 pass;