Only taint casereader if case size is unknown.
[pspp] / 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      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
61 # Tests for exact calculations
62 activity="create file 1"
63 cat <<EOF > $TESTFILE
64 ECHO 'P < 0.5; N1/N2 < 1' .
65
66 NEW FILE.
67
68 DATA LIST LIST NOTABLE /x * w *.
69 BEGIN DATA.
70 1   6
71 2   15
72 END DATA.
73
74 WEIGHT BY w.
75
76 NPAR TESTS
77         /BINOMIAL(0.3) = x
78         .
79
80
81 ECHO 'P < 0.5; N1/N2 > 1' .
82
83 NEW FILE.
84
85 DATA LIST LIST NOTABLE /x * w *.
86 BEGIN DATA.
87 1   7
88 2   6
89 END DATA.
90
91 WEIGHT BY w.
92
93 NPAR TESTS
94         /BINOMIAL(0.4) = x
95         .
96
97
98
99 ECHO 'P < 0.5; N1/N2 = 1' .
100
101 NEW FILE.
102
103 DATA LIST LIST NOTABLE /x * w *.
104 BEGIN DATA.
105 1   8
106 2   8
107 END DATA.
108
109 WEIGHT BY w.
110
111 NPAR TESTS
112         /BINOMIAL(0.4) = x
113         .
114
115 ECHO 'P > 0.5; N1/N2 < 1' .
116
117 NEW FILE.
118
119 DATA LIST LIST NOTABLE /x * w *.
120 BEGIN DATA.
121 1   11
122 2   12
123 END DATA.
124
125 WEIGHT BY w.
126
127 NPAR TESTS
128         /BINOMIAL(0.6) = x
129         .
130
131
132 ECHO 'P > 0.5; N1/N2 > 1' .
133
134 NEW FILE.
135
136 DATA LIST LIST NOTABLE /x * w *.
137 BEGIN DATA.
138 1   11
139 2   9
140 END DATA.
141
142 WEIGHT BY w.
143
144 NPAR TESTS
145         /BINOMIAL(0.6) = x
146
147 ECHO 'P > 0.5; N1/N2 == 1' .
148
149 NEW FILE.
150
151 DATA LIST LIST NOTABLE /x * w *.
152 BEGIN DATA.
153 1   11
154 2   11
155 END DATA.
156
157 WEIGHT BY w.
158
159 NPAR TESTS
160         /BINOMIAL(0.6) = x
161         .
162
163 ECHO 'P == 0.5; N1/N2 < 1' .
164
165 NEW FILE.
166
167 DATA LIST LIST NOTABLE /x * w *.
168 BEGIN DATA.
169 1   8
170 2   15
171 END DATA.
172
173 WEIGHT BY w.
174
175 NPAR TESTS
176         /BINOMIAL(0.5) = x
177         .
178
179
180 ECHO 'P == 0.5; N1/N2 > 1' .
181
182 NEW FILE.
183
184 DATA LIST LIST NOTABLE /x * w *.
185 BEGIN DATA.
186 1   12
187 2   6
188 END DATA.
189
190 WEIGHT BY w.
191
192 NPAR TESTS
193         /BINOMIAL(0.5) = x
194
195 ECHO 'P == 0.5; N1/N2 == 1' .
196
197 NEW FILE.
198
199 DATA LIST LIST NOTABLE /x * w *.
200 BEGIN DATA.
201 1   10
202 2   10
203 END DATA.
204
205 WEIGHT BY w.
206
207 NPAR TESTS
208         /BINOMIAL(0.5) = x
209         .
210 EOF
211 if [ $? -ne 0 ] ; then no_result ; fi
212
213
214 activity="run program 1"
215 $SUPERVISOR $PSPP --testing-mode -o raw-ascii $TESTFILE
216 if [ $? -ne 0 ] ; then no_result ; fi
217
218 activity="compare output 1"
219 perl -pi -e 's/^\s*$//g' $TEMPDIR/pspp.list
220 diff -b $TEMPDIR/pspp.list - << EOF
221 P < 0.5; N1/N2 < 1
222 1.1 NPAR TESTS.  Binomial Test
223 +-+------#--------+--+--------------+----------+---------------------+
224 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
225 +-+------#--------+--+--------------+----------+---------------------+
226 |x|Group1#    1.00| 6|          .286|      .300|                 .551|
227 | |Group2#    2.00|15|          .714|          |                     |
228 | |Total #        |21|          1.00|          |                     |
229 +-+------#--------+--+--------------+----------+---------------------+
230 P < 0.5; N1/N2 > 1
231 2.1 NPAR TESTS.  Binomial Test
232 +-+------#--------+--+--------------+----------+---------------------+
233 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
234 +-+------#--------+--+--------------+----------+---------------------+
235 |x|Group1#    1.00| 7|          .538|      .400|                 .229|
236 | |Group2#    2.00| 6|          .462|          |                     |
237 | |Total #        |13|          1.00|          |                     |
238 +-+------#--------+--+--------------+----------+---------------------+
239 P < 0.5; N1/N2 = 1
240 3.1 NPAR TESTS.  Binomial Test
241 +-+------#--------+--+--------------+----------+---------------------+
242 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
243 +-+------#--------+--+--------------+----------+---------------------+
244 |x|Group1#    1.00| 8|          .500|      .400|                 .284|
245 | |Group2#    2.00| 8|          .500|          |                     |
246 | |Total #        |16|          1.00|          |                     |
247 +-+------#--------+--+--------------+----------+---------------------+
248 P > 0.5; N1/N2 < 1
249 4.1 NPAR TESTS.  Binomial Test
250 +-+------#--------+--+--------------+----------+---------------------+
251 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
252 +-+------#--------+--+--------------+----------+---------------------+
253 |x|Group1#    1.00|11|          .478|      .600|                 .164|
254 | |Group2#    2.00|12|          .522|          |                     |
255 | |Total #        |23|          1.00|          |                     |
256 +-+------#--------+--+--------------+----------+---------------------+
257 P > 0.5; N1/N2 > 1
258 5.1 NPAR TESTS.  Binomial Test
259 +-+------#--------+--+--------------+----------+---------------------+
260 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
261 +-+------#--------+--+--------------+----------+---------------------+
262 |x|Group1#    1.00|11|          .550|      .600|                 .404|
263 | |Group2#    2.00| 9|          .450|          |                     |
264 | |Total #        |20|          1.00|          |                     |
265 +-+------#--------+--+--------------+----------+---------------------+
266 P > 0.5; N1/N2 == 1
267 6.1 NPAR TESTS.  Binomial Test
268 +-+------#--------+--+--------------+----------+---------------------+
269 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (1-tailed)|
270 +-+------#--------+--+--------------+----------+---------------------+
271 |x|Group1#    1.00|11|          .500|      .600|                 .228|
272 | |Group2#    2.00|11|          .500|          |                     |
273 | |Total #        |22|          1.00|          |                     |
274 +-+------#--------+--+--------------+----------+---------------------+
275 P == 0.5; N1/N2 < 1
276 7.1 NPAR TESTS.  Binomial Test
277 +-+------#--------+--+--------------+----------+---------------------+
278 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
279 +-+------#--------+--+--------------+----------+---------------------+
280 |x|Group1#    1.00| 8|          .348|      .500|                 .210|
281 | |Group2#    2.00|15|          .652|          |                     |
282 | |Total #        |23|          1.00|          |                     |
283 +-+------#--------+--+--------------+----------+---------------------+
284 P == 0.5; N1/N2 > 1
285 8.1 NPAR TESTS.  Binomial Test
286 +-+------#--------+--+--------------+----------+---------------------+
287 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
288 +-+------#--------+--+--------------+----------+---------------------+
289 |x|Group1#    1.00|12|          .667|      .500|                 .238|
290 | |Group2#    2.00| 6|          .333|          |                     |
291 | |Total #        |18|          1.00|          |                     |
292 +-+------#--------+--+--------------+----------+---------------------+
293 P == 0.5; N1/N2 == 1
294 9.1 NPAR TESTS.  Binomial Test
295 +-+------#--------+--+--------------+----------+---------------------+
296 | |      #Category| N|Observed Prop.|Test Prop.|Exact Sig. (2-tailed)|
297 +-+------#--------+--+--------------+----------+---------------------+
298 |x|Group1#    1.00|10|          .500|      .500|                1.000|
299 | |Group2#    2.00|10|          .500|          |                     |
300 | |Total #        |20|          1.00|          |                     |
301 +-+------#--------+--+--------------+----------+---------------------+
302 EOF
303 if [ $? -ne 0 ] ; then fail ; fi
304
305
306 pass;